Kaseya Community

Some Trouble with one Vbscript

  • Procedure Shadow Copy.xml

    Hi everybody,

    I've made a script to grab the information about the Shadow Copy on Windows Server who works everytimes I launch it manually:

    Here is my VBScript 

    'Resume the script if there is an error 
    On Error Resume Next
    'StrComputer is the string where the dot is the localhost.
    set oArgs = WScript.Arguments
    filepath = oArgs(0)
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objResultFile = objFSO.CreateTextFile(filepath,true)
    strComputer = "."
    strVolume = "Volume = "
    strSpaceAllo = "Allo = "
    strMaxSpace = "Space = "
    strUsedSpace = "strUsedSpace = "

    'This step is made to get the object in the WinMgmt path to query the cimv2 namespace
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    'We put the information of the query in a variable here i've selected the Win32_Volume Classe for getting the name of the device
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Volume")
    'We used the For Each Statement for query the columns who contains all the properties of the object
    For Each objItem In colItems
    'This step remove the slash for the next step
    deviceID = Replace(objItem.DeviceID, "\", "\\\\")
    'declaration of the Query Variable
    Dim query
    'the Wmi Query to get all the shadow copy with the Volume Name instead of the device ID non human readable
    query = "Select * from Win32_ShadowStorage WHERE Volume='Win32_Volume.DeviceID=""" & deviceID & """'"
    'excution of the query and put in the variable
    Set ssItems = objWMIService.ExecQuery(query)
    For Each ssI In ssItems
    'We Check if there''s an error to write a message
    If Err.Number <> 0 Then
    strMessage = strMessage & "NO Shadow Copy Entries Found for " & objitem.name & VbCrLf
    'Else we put the grabbed data on the screen
    Else
    strVolume = strVolume & vbTab & objitem.name
    strSpaceAllo = strSpaceAllo & Int((ssI.AllocatedSpace)/1073741824) & " Go" & vbTab
    strMaxSpace = strMaxSpace & Int((ssI.MaxSpace)/1073741824) & " Go" & vbTab
    strUsedSpace = strUsedSpace & Int((ssI.UsedSpace)/1073741824) & " Go" & vbTab
    End If
    Next
    Next

    objResultFile.Write(strMessage & vbCrLf & strVolume & vbCrLf & strSpaceAllo & vbCrLf & strMaxSpace & vbCrLf & strUsedSpace)
    Wscript.Echo strMessage & vbCrLf & strVolume & vbCrLf & strSpaceAllo & vbCrLf & strMaxSpace & vbCrLf & strUsedSpace
    objResultFile.close

    If set my Kaseya Script like that : 

    (View the attached procedure)

    I've tried, Impersonate User, Use Credentials but every time if this output :

    NO Shadow Copy Entries Found for D:\
    NO Shadow Copy Entries Found for \\?\Volume{cefc9dd6-b8b9-11de-8b9a-806e6f6e6963}\
    NO Shadow Copy Entries Found for E:\
    NO Shadow Copy Entries Found for C:\
    NO Shadow Copy Entries Found for H:\
    NO Shadow Copy Entries Found for F:\
    NO Shadow Copy Entries Found for G:\

    Volume =
    Allo =
    Space =
    strUsedSpace =
    and if I connect myself on the remote computer the output is :
    c:\kworking\Files>cscript.exe shadow.vbs test.txt
    Microsoft (R) Windows Script Host Version 5.8
    Copyright (C) Microsoft Corporation 1996-2001. Tous droits réservés.


    Volume = D:\ E:\ C:\
    Allo = 52 Go 19 Go 0 Go
    Space = 52 Go 19 Go 6 Go
    strUsedSpace = 50 Go 18 Go 0 Go
    
    
    Does anyone have this strange stuff ?
  • Yes all the time and the issue can be that when a script is run there is no "Start in" defined (to use a windows short term) So there is no default drive or location to start the logic from

  • Etienne,  did you ever figure out how to get this working?  Im trying to build something similar with custom fields and was able to get a CF populated with the drive letters with ShadowCopy enabled but now I cant figure out how to pull the ShadowCopy space metrics for each volume.   I would also love to have a custom field with the last few available Shadow Copies by Date/Time.

    I also tried downloading your Agent Procedure and it just links me back to this thread :(.

  • Procedure ShadowCopyValues.xml

    Try this Agent Procedure

    I saved the vbs as a file named shadowcopy.vbs

    It assumes you've already put the vbs file in your Agent Working Directory

    And also you need to run it as cscript , or edit the VB and remove the line wscript.echo in line 44 

    Cheers

  • Thanks Paul, I got all that in place along with adding the piece to write the vbs file to the #agentdir# but I'm seeing the same results that Etienne reported on where the data comes back as:

    NO Shadow Copy Entries Found for \\?\Volume{75b69943-416c-11e1-b948-806e6f6e6963}\

    NO Shadow Copy Entries Found for C:\

    NO Shadow Copy Entries Found for D:\

    Volume =

    Allo =

    Space =

    strUsedSpace =

    when I have confirmed locally that Shadow Copy is indeed enabled and has entries.  I just copy/pasted the Vbscript he included in his post and ran it as cscript.

  • Anyone have any thoughts?  I need to do a large shadow copy audit across our clients as shadow copies mysteriously stopped working on may 8th on a large number of client servers and it would be great if I didn't need to do it by hand.  Odd thing is on these servers, shadow copy is enabled and the schedule is set but unless we manually take a shadow copy the last shadow copy date is on 5/8, like it just stopped making new Shadow Copies.

  • I couldn't get a vbscript to work remotely but you might try this Poweshell script (I haven't had a chance to try it):

    gallery.technet.microsoft.com/.../Get-Remote-Shadow-Volume-e5a72619



    Added parens
    [edited by: zippo at 11:35 AM (GMT -7) on Jun 3, 2014]
  • Interesting Zippo thanks.  I actually haven't had much experience with Powershell execution through Agent Procedures, anyone know by chance if there are any known issues or quirks using PS from a Procedure?  I could be wrong but I think I recall seeing a few things on the forums about PS either not working or not working on certain machines.

    When I get some time to spare I'll try it out, I just need to finally sit down and learn how to utilize procedure variables properly and subsequently populate Custom Fields from VB/PS/Shell scripts, text docs :p

  • You need to make sure to lower the restriction setting on the endpoint via RegEdit, run the PS1 and then re-enable the restriction.

  • On another note with this VBS... Have you been able to test executing the Query from the Script without all of these nested FOR loops?

    I retrieved a description of the error since you have the ON ERROR RESUME NEXT and I see that there is something wrong w. the VBS

  • Ok so I was able to finally get the VBS script to work as well as the AP

  • 2014-07-08_14-15-43.png

    The AP does not require anything fancy. My AP did not copy the VBS script to the endpoint as I just placed it down and referred it to the one I was working on in my endpoint.

    That being said, you need to make sure you simply reference the following under ExecuteShellCommand()

    wscript.exe c:\vss.vbs c:\vsstest.txt

    Run as SYSTEM in 64-bit shell

    You can hardcode the argument Etienne placed in, or have the procedure ask for a variable, or make your own variable.

    As well you can setup many different pre steps before the execution of the VBS such as copying it from the KServer, etc...

    Now for the VBS issue.

    This is how you had the query setup:

    query = "Select * from Win32_ShadowStorage WHERE Volume='Win32_Volume.DeviceID=""" & deviceID & """'"

    You neglected to escape the single quotes!

    query = "Select * from Win32_ShadowStorage WHERE Volume='Win32_Volume.DeviceID=" & "\'" & deviceID & "\''"

    Change this piece and the script will surely work even locally.

    Attached is the screenshot of the results

  • VSS.mp4

    Attached is my version of the VBS script...

    Rename .mp4 to .vbs

  • I also removed the Wscript.Echo piece at the end as this prompt will cause the script to pause as it executes in a hidden desktop.

    No one available to click on Ok, means script just sits there and waits.. just like KSDU...

  • If you execute it with cscript (available in the native vbscript execution step) it will pipe the output to the command-line and not wait for any user interaction.