PowerShell provides ‘easy’ access to Windows via a command line, and can be used for many things. I wanted to find the total disk space and amount free which we can do like this:
get-wmiobject -class win32_logicaldiskOutputs:
PowerShell uses STDIN and STDOUT, which is how we can pipe it into SAS. Note adding the filter to restrict to local, non-removable, drives:
DeviceID : A:
DriveType : 2
ProviderName :
FreeSpace :
Size :
VolumeName :
DeviceID : C:
DeviceID : C:
DriveType : 3
ProviderName :
FreeSpace : 221132865536
Size : 293552017408
VolumeName :
filename diskinfo pipe "powershell get-wmiobject -class win32_logicaldisk -filter 'DriveType=3'";Which yields (note the 2 leading blank lines):
data _null_;
infile diskinfo;
input;
put _infile_;
run;
PowerShell can reformat output, but I coded SAS to read it as-is:
DeviceID : C:
DriveType : 3
ProviderName :
FreeSpace : 221132881920
Size : 293552017408
VolumeName :
data _null_;Which gives us variables holding the total size of the C drive (in bytes) and free space:
infile diskinfo firstobs=3 truncover;
input
@':' +1 DeviceID $1.
/
/
/ @':' +1 FreeSpace 32.
/ @':' +1 Size 32.
/ @':' +1 VolumeName $32.
/;
put _all_;
run;
DeviceID=C FreeSpace=221132861440 Size=293552017408 VolumeName= _ERROR_=0 _N_=1
No comments:
Post a Comment