Running vbs on SCE 2010: Object required: 'ScriptContext'
I am trying to run a vbs script on my SCE 2010 to monitor folder sizes. Script is from
http://contoso.se/blog/?p=127 . For that purpose, I have set up a rule. However, I got the following error logged on to event viewer by SCE. Any idea appreciated?
The Event Policy for the process started at 11:21:29 AM has detected errors in the output. The 'StdErr' policy expression:
\a+
matched the following output:
C:\Program Files\System Center Essentials\Health Service State\Monitoring Host Temporary Files 23\277315\GDriveUsage.vbs(8, 1) Microsoft VBScript runtime error: Object required: 'ScriptContext'
Command executed: "C:\WINDOWS\system32\cscript.exe" /nologo "GDriveUsage.vbs"
Working Directory: C:\Program Files\System Center Essentials\Health Service State\Monitoring Host Temporary Files 23\277315\
One or more workflows were affected by this.
Workflow name: MomUIGeneratedRule99e6fa8dcd4c4cfd9ed3d485c9f4ee7e
Instance name: myserver
Instance ID: {5334066A-1769-25ED-61BB-F4EE28494E9A}
Management group: mydomain
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
September 8th, 2010 9:40pm
Hi,
I noticed this script is for Microsoft Operations Manager 2005 and it might not work properly in System Center Operations Manager 2007.
For System Center Operations Manager 2007, I just got the following example about monitoring file count and I would like to share it with you for your
reference. Hope this can give you some hints:
SCOM 2007 Script to Monitor File Count inside a Directory
http://www.scom2k7.com/scom-2007-script-to-monitor-file-count-inside-a-directory/
Please Note: Since the website is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
Thanks.
Nicholas Li
TechNet Subscriber Support in forum
If you have any feedback on our support, please contact
tngfb@microsoft.com.
Nicholas Li - MSFT
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
September 9th, 2010 12:54pm
I am just writing to say Hi, and to see how thing are going there and if the information is helpful. If there is anything I can do to help on this issue, please feel free to let me know. I am happy
to be of assistance. :)
Thanks!
Nicholas Li
TechNet Subscriber Support in forum
If you have any feedback on our support, please contact
tngfb@microsoft.com.Nicholas Li - MSFT
Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
September 13th, 2010 8:58am
Below scipt is to monitor folder sizes:
'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strFolder
strFolder = "\\?\G:\"
Set objFolder = objFSO.GetFolder(strFolder)
Set colSubfolders = objFolder.Subfolders
Dim oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
For Each objSubfolder in colSubfolders
if StrComp(Right(objSubfolder.Path, 9), "~snapshot") then
' wscript.echo objSubfolder.Path
Call oBag.AddValue(objSubfolder.Path, objSubfolder.Size/1024/1024)
' wscript.echo FormatNumber(objSubfolder.Size/1024/1024, 2)
end if
Next
Call oAPI.Return(oBag)
Please note that G drive is a mapped network drive, and also note that because of the long folder names on that network drive, I need to use UNC style addressing like
\\?\G:\ instead of just "G:\" to bypass the limitation coming from MAX_PATH in Windows API.
If I run this in cmd with "cscript" it just works fine. However, when I set it up as a script running rule in my SCE 2010, it still gives me the following error:
Description:
The Event Policy for the process started at 1:49:20 PM has detected errors in the output. The 'StdErr' policy expression:
\a+
matched the following output:
C:\Program Files\System Center Essentials\Health Service State\Monitoring Host Temporary Files 27\32743\GDriveUsage.vbs(5, 1) Microsoft VBScript runtime error: Path not found
Command executed: "C:\WINDOWS\system32\cscript.exe" /nologo "GDriveUsage.vbs"
Working Directory: C:\Program Files\System Center Essentials\Health Service State\Monitoring Host Temporary Files 27\32743\
One or more workflows were affected by this.
Workflow name: MomUIGeneratedRule99e6fa8dcd4c4cfd9ed3d485c9f4ee7e
Instance name: myserver
Instance ID: {5334066A-1769-25ED-61BB-F4EE28494E9A}
Management group: mydomain
So, any idea how to run that script as a scripting rule in SCE 2010?
Free Windows Admin Tool Kit Click here and download it now
September 14th, 2010 2:08am
Hi,
Thank you for your update.
After researching, I would like to suggest the following:
1.
Ensure there is no security software (anti-virus, anti-spyware, etc.) blocking the script on the target computer.
2.
Check how it works if you monitor the UNC “\\computername\sharefolder” or the local drive.
3.
Ensure the run as account has proper permission to access the mapped network drive. You can also try another account which has enough privileges:
How Can I Use the RunAs Command to Run a Script Under Alternate User Credentials?
http://blogs.technet.com/b/heyscriptingguy/archive/2006/04/28/how-can-i-use-the-runas-command-to-run-a-script-under-alternate-user-credentials.aspx
Using a specific account for specific scripts in SCOM 2007
http://www.cupfighter.net/index.php/2010/03/using-a-specific-account-for-specific-scripts-in-scom-2007/
Please Note: Since the website is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy
of this information.
In addition, I would like to share the following with you for your reference:
Getting lots of Script Failed To Run alerts? WMI Probe Failed Execution? Backward Compatibility Script Error?
http://blogs.technet.com/b/kevinholman/archive/2009/06/29/getting-lots-of-script-failed-to-run-alerts-wmi-probe-failed-execution-backward-compatibility-script-error.aspx
Hope this helps.
Thanks.
Nicholas Li
TechNet Subscriber Support in forum
If you have any feedback on our support, please contact
tngfb@microsoft.com.Nicholas Li - MSFT
Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
September 14th, 2010 6:52am
How are you doing? I'm just writing to see how things are going on there. If you have any questions or concerns with the information I provided, please
feel free to let me know. It is my pleasure to be of assistance.
Thanks! Have a nice day!
Nicholas Li
TechNet Subscriber Support in forum
If you have any feedback on our support, please contact
tngfb@microsoft.com.
Nicholas Li - MSFT
Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
September 16th, 2010 11:26am
Hi Nicholas,
I can run my vbs with strFolder = "\\?\G:\" (you can see the full script above) in CMD by calling cscript manually, and it completes just fine. However, it does not run in SCE 2010 as a script rule, and gives me path not found
error. I checked the RunAs account, and it is nothing to do with it: all logs on the device is clear (no auth failure), and the default action acount in SCE has full permission on the drive by through its security group membership.
Any other sugegstions?
September 23rd, 2010 2:39am
As Nicholas says, you have to configure a run as account with permission to the shared folder and because G: doesn't exist in the environment where the script is executed by SCE (probably under user account SYSTEM by default) you also have to use a UNC path
in the script to access the folder.
/ Svante
Free Windows Admin Tool Kit Click here and download it now
November 30th, 2010 3:13am
As Nicholas says, you have to configure a run as account with permission to the shared folder and because G: doesn't exist in the environment where the script is executed by SCE (probably under user account SYSTEM by default) you also have to use a UNC path
in the script to access the folder.
/ Svante
November 30th, 2010 11:07am