Bookmark and Share

In this post:

 

Dealing with Quarantined File Types and Exchange Server

Hey, Scripting Guy! Question

Hey, Scripting Guy! I have spent most of this week Googling, experimenting, and fighting with Exchange 2007. The problem I have been working on was caused by one of my colleagues who came to me and asked if I can make it possible for him to receive an .exe attachment that one of our customers wants to send to him. Being pretty sure that I could, I logged on to the Exchange server just to allow the attachment to be sent, and to my surprise, I discovered that Exchange has deleted it. I can’t get Exchange 2007 to quarantine .exe files. The only thing it can do is delete all of the.exe attachments, or let them all into my network (a change that obviously sets my security level below 0). Is there a way of setting Exchange 2007 attachment filtering rules, so I can decide which .exe files can be received?

-- MK

Hey, Scripting Guy! AnswerHello MK,

Microsoft Scripting Guy Ed Wilson here. This is an Exchange Server question, and I am no longer an Exchange Server guru. The last version I was an expert on was Exchange 5.5. At that time, there was no such thing as file quarantine. These days, what I do when I need to receive an executable file from someone is have them rename the .exe file to with a .ex_ extension and email it to me. Most of the time this simple change will get the file through. At times, however, it will not (it seems to depend on certain antivirus products that use advanced file-matching algorithms). For those occasions when I am unable to receive a renamed executable via e-mail, I use SkyDrive from Windows Live. It is free and allows up to 25 GB of storage. It works most excellently for sharing files. My SkyDrive is seen here:

Image of Ed's SkyDrive



 

Scanning Multiple Remote Computers and Creating a Resultant CSV File

Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I scan a list of multiple remote PCs (running Windows XP) on the same domain for particular installation files on their hard drives and submit the positive results to a .csv file? I came across one of your scripts (listed below) but this is only for one PC at a time and all of the results are shown in the shell.

ScanPCForSpecificFile.vbs

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
    ExecQuery("Select * From CIM_DataFile Where FileName = 'VisioMUI' and Extension = 'msi'")
If colFiles.Count = 0 Then
    Wscript.Echo "The file does not exist on the remote computer."
Else
    Wscript.Echo "The file exists on the remote computer."
End If

-- JD

 

Hey, Scripting Guy! AnswerHello JD,

Believe it or not, the script is pretty well set up to run on multiple computers. What you will need to do is populate the value of the strComputer variable. The ScanPcForSpecificFile.vbs uses a period, which is WMI shorthand for “run on the local computer.”

There are several ways that you can get values for the strComputer variable. You can read a text file (really easy to do), you can ping a range of IP addresses (really cool to do), you can read a database (a bit of work but groovy none the less), or you can even query Active Directory (similar to querying a database) to get your computer names.

After you have the computer names, modify the wscript.echo commands to write to a text file, Word document, Excel spreadsheet, Access or SQL database, or whatever other output you like. Because of the work involved in opening and reading your data source, it often makes sense to stay with the same type of output for logging your results. For example, if you open a text file and read it for your computer names, use a text file to log your results.

You can find numerous examples of working with text files in the Hey, Scripting Guy! archive and in the TechNet Script Center Gallery. The same is true for working with Office Word, Excel, databases, and Active Directory.

Here is an example I wrote to illustrate what needs to be done.

ReadFromTextFileWriteToTextFile.vbs

'==========================================================================
'
'
' NAME: ReadFromTextFileWriteToTextFile.vbs
'
' AUTHOR: ed wilson , Microsoft
' DATE  : 10/20/2009
'
' COMMENT: Demo read from a text file, and writing information to a different
' text file. If the other text file does not exist, it will be created.
'==========================================================================
strServers = "c:\fso\servers.txt"
strOutFile = "c:\fso\output.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strServers)
Set objOutFile = objFSO.OpenTextFile(strOutFile,8,True)
Do until  objTextFile.AtEndOfStream
    strComputer = objTextFile.Readline
    'WScript.Echo strComputer

   objOutFile.WriteLine strComputer
Loop
objTextFile.Close
objOutFile.Close

Here is your script pasted into the above script:
strServers = "c:\fso\servers.txt"
strOutFile = "c:\fso\output.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strServers)
Set objOutFile = objFSO.OpenTextFile(strOutFile,8,True)
Do until  objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
    ExecQuery("Select * From CIM_DataFile Where FileName = 'VisioMUI' and Extension = 'msi'")
If colFiles.Count = 0 Then
    Wscript.Echo "The file does not exist on the remote computer."
Else
   objOutFile.WriteLine  "The file exists on the: " & strComputer
End If
Loop
objTextFile.Close
objOutFile.Close

I have not tested the script, but I believe it should work.   


How Can I Check for the Latest Daylight Saving Time Update?

Hey, Scripting Guy! Question

Hey, Scripting Guy! I’m hoping that you could help me here. Please see Bug ID 422388 on the Microsoft Connect Feedback Web page. This is a bug I ran into while scanning my domain during the 2009 DST spring forward. 

The problem is with recently patched Windows XP and Windows Server 2003 machines; WMI appears to follow the pre-2007 DST rules. The case on the Connect forum says that it has been fixed and closed, but it makes no mention of what has been fixed and how the end user might be able to remedy this on their own machines.

I was hoping that you might know internal Microsoft people who can shed some light about whether any operating system hotfixes are being issued to fix this problem.

You obviously see the seriousness of this issue when the instrumentation interface that you are using is giving incorrect replies.

Thank you for your attention.

-- WD


Hey, Scripting Guy! AnswerHello WD,

This is a Windows PowerShell script I wrote to check for the latest daylight saving time update. Daylight saving time updates are now cumulative. As far as I know, the latest one is 955839.

CheckDSTPatch.ps1

# CheckDSTPatch.ps1
# ed wilson, msft
# checks for patch 955839 Dec. 2008 TZ patch update
http://bit.ly/yukqp $computer = $env:computerName Get-WmiObject -Class Win32_QuickFixEngineering -computer $computer | Where-Object { $_.hotFixID -match '955839' }


 

Troubleshooting the Use of WSMan with Windows PowerShell

Hey, Scripting Guy! Question

Hey, Scripting Guy! I am having an issue with Windows PowerShell. I hope someone can help. I could not find any relevant documentation or thread referring to same. While running a script using WSMan in Windows PowerShell, we created the script to get the data for CIM_Sensor class. The script ran successfully in a C# project, but when we ran the code in a Windows PowerShell script, it threw an exception. The exception that was thrown is seen here:

"Get-WSManInstance: The response that the WS-Management service computed exceeds the internal limit for envelope size."

Is this a Windows PowerShell issue because we were able to retrieve data successfully using C# and Perl? Any pointers would be highly appreciated.

-- SK
 

Hey, Scripting Guy! AnswerHello SK,

You can configure the envelope size limit (and a bunch of other things) in the WSMan provider. To do this, you will need to start Windows PowerShell as an administrator. Use the Set-Location cmdlet to change to the WSMan drive. You can then Set-Location to the localhost container. Use the Get-Item cmdlet to retrieve your maxenvelopesizekb property. Use the Set-Item cmdlet to configure a new size. This is seen here:

PS C:\Windows\system32> Set-Location wsman:
PS WSMan:\> Set-Location localhost

Start WinRM Service
WinRM service is not started currently. Running this command will start the WinRM service.

Do you want to continue?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
WARNING: Waiting for service 'Windows Remote Management (WS-Management) (WinRM)' to finish starting...
PS WSMan:\localhost> Get-Item .\MaxEnvelopeSizekb


   WSManConfig: Microsoft.WSMan.Management\WSMan::localhost

Name                      Value                                                             Type
----                      -----                                                             ----
MaxEnvelopeSizekb         150                                                               System.String

 

For more information on this, refer to the WSMan provider help by using the following command: Get-Help wsman.

 

Well, this concludes another edition of Quick-Hits Friday. It also concludes another exciting week on the Script Center. Join us next week as we delve into the mysteries of…well, we will let that remain a mystery for now.

If you want to know exactly what we will be looking at on Monday, follow us on Twitter or Facebook. If you have any questions, send e-mail to us at scripter@microsoft.com or post them on the Official Scripting Guys Forum. See you on Monday. Until then, have an awesome weekend.

 

Ed Wilson and Craig Liebendorfer, Scripting Guys