Kaseya Community

Disk Space Free Variable

  • I need to grab the disk space free on the system drive as a variable in a script... any ideas? I can't seem to get the WMI property to work correctly. Thanks.

    Legacy Forum Name: Disk Space Free Variable,
    Legacy Posted By Username: cnwicsurrett
  • What format does that variable need? bytes, gigs, mb?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: ryan.odwyer
  • There is also this forum post that may help out with vbs:

    http://community.kaseya.com/xsp/f/132/t/3450.aspx

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: ryan.odwyer
  • #vCurrDiskInfo.FreeSpace# for space in MB. Provided you have run an audit recently.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: CCDave
  • HI CCDave,

    I tried that variable, but it kept returning A: drive, I couldn't find a way to check a specifc drive C.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: ryan.odwyer
  • ryan.odwyer
    HI CCDave,

    I tried that variable, but it kept returning A: drive, I couldn't find a way to check a specifc drive C.


    You can't - it's an array and there's no way to specify which member of the array you want. I've been down that rabbit hole before with Kaseya.

    Michael

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: RCS-Michael
  • cnwicsurrett
    I need to grab the disk space free on the system drive as a variable in a script... any ideas? I can't seem to get the WMI property to work correctly. Thanks.


    Try this script. It will return a variable of the SytemDrive in Bytes.


    Script Name: Get_Boot_FreeSpace
    Script Description: Outputs free bytes available on the Windows system drive (%SystemDrive%). Uses WMIC command to get the FreeSpace and the FOR command to just return the FreeSpace count in bytes.
    Works on XP and above.

    Greg Sloan
    PCM Networking

    IF True
    THEN
    Get Variable
    Parameter 1 : 2
    Parameter 2 : c:\temp
    Parameter 3 : AgentTemp
    OS Type : 0
    Execute Shell Command
    Parameter 1 : (for /f "usebackq delims== tokens=2" %a in (`wmic logicaldisk where "DeviceID='%SystemDrive%'" get FreeSpace /format:value`) do (echo %a) >>#AgentTemp#\FreeSpace.txt)
    Parameter 2 : 0
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #AgentTemp#\freespace.txt
    Parameter 3 : Freespace
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : Freespace is #Freespace#
    OS Type : 0
    Execute Shell Command
    Parameter 1 : del #AgentTemp#\Freespace.txt
    Parameter 2 : 0
    OS Type : 0
    ELSE




    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: pcmnetmanage
  • Nicely done, I especially like that you clean up when the script is done

    A slightly modified version of Gregs script.


    Script Name: Get_Boot_FreeSpace
    Script Description: Outputs free bytes available on the Windows system drive (%SystemDrive%). Uses WMIC command to get the FreeSpace and the FOR command to just return the FreeSpace count in bytes.
    Works on XP and above.

    Greg Sloan
    PCM Networking

    Modified by thirteentwenty
    Modification: Removed the set variable to agent temp dir and replaced with the nested variable so that the script will use everyones temp dir.

    IF True
    THEN
    Execute Shell Command
    Parameter 1 : (for /f "usebackq delims== tokens=2" %a in (`wmic logicaldisk where "DeviceID='%SystemDrive%'" get FreeSpace /format:value`) do (echo %a) >>#vAgentConfiguration.agentTempDir#\FreeSpace.txt)
    Parameter 2 : 0
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #vAgentConfiguration.agentTempDir#\freespace.txt
    Parameter 3 : Freespace
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : Freespace is #Freespace#
    OS Type : 0
    Execute Shell Command
    Parameter 1 : del #vAgentConfiguration.agentTempDir#\Freespace.txt
    Parameter 2 : 0
    OS Type : 0
    ELSE


    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: thirteentwenty
  • thirteentwenty
    Nicely done, I especially like that you clean up when the script is done

    A slightly modified version of Gregs script.


    Script Name: Get_Boot_FreeSpace
    Script Description: Outputs free bytes available on the Windows system drive (%SystemDrive%). Uses WMIC command to get the FreeSpace and the FOR command to just return the FreeSpace count in bytes.
    Works on XP and above.

    Greg Sloan
    PCM Networking

    Modified by thirteentwenty
    Modification: Removed the set variable to agent temp dir and replaced with the nested variable so that the script will use everyones temp dir.

    IF True
    THEN
    Execute Shell Command
    Parameter 1 : (for /f "usebackq delims== tokens=2" %a in (`wmic logicaldisk where "DeviceID='%SystemDrive%'" get FreeSpace /format:value`) do (echo %a) >>#vAgentConfiguration.agentTempDir#\FreeSpace.txt)
    Parameter 2 : 0
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #vAgentConfiguration.agentTempDir#\freespace.txt
    Parameter 3 : Freespace
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : Freespace is #Freespace#
    OS Type : 0
    Execute Shell Command
    Parameter 1 : del #vAgentConfiguration.agentTempDir#\Freespace.txt
    Parameter 2 : 0
    OS Type : 0
    ELSE


    Thanks, I used to use the vAgentConfiguration.agentTempDir variable in my scripts but I got tired of fighting the Kaseya script interpreter when there is a space in the agent temp path, sometime you would need to surround the command in double quotes and sometimes not, either way, it gets the job done.

    Thanks

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: pcmnetmanage
  • pcmnetmanage
    Thanks, I used to use the vAgentConfiguration.agentTempDir variable in my scripts but I got tired of fighting the Kaseya script interpreter when there is a space in the agent temp path, sometime you would need to surround the command in double quotes and sometimes not, either way, it gets the job done.

    Thanks


    I understand that... Also just made another little mod, I added a step that does the math so that it outputs to the script log in GB


    Script Name: Get_Boot_FreeSpace
    Script Description: Outputs free bytes available on the Windows system drive (%SystemDrive%). Uses WMIC command to get the FreeSpace and the FOR command to just return the FreeSpace count in bytes.
    Works on XP and above.

    Greg Sloan
    PCM Networking

    Modified by thirteentwenty:
    Modifications:
    1) Removed the Get Variable and replaced with nested variable to agent temp dir

    2) added step three to do the math so that the output to script log would be in GB

    IF True
    THEN
    Execute Shell Command
    Parameter 1 : (for /f "usebackq delims== tokens=2" %a in (`wmic logicaldisk where "DeviceID='%SystemDrive%'" get FreeSpace /format:value`) do (echo %a) >>#vAgentConfiguration.agentTempDir#\FreeSpace.txt)
    Parameter 2 : 0
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #vAgentConfiguration.agentTempDir#\freespace.txt
    Parameter 3 : b
    OS Type : 0
    Get Variable
    Parameter 1 : 13
    Parameter 2 : #b# / 1024 / 1024 / 1024
    Parameter 3 : freespace
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : Freespace is #freespace#
    OS Type : 0
    Execute Shell Command
    Parameter 1 : del #vAgentConfiguration.agentTempDir#\Freespace.txt
    Parameter 2 : 0
    OS Type : 0
    ELSE


    Note: Math is done for binary size of drive 1024 b = 1 k etc etc etc...

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: thirteentwenty