azdzn (1/6/2012)
Change$Output = Get-WmiObject Win32_logicaldisk Format-Table DeviceId, MediaType, Size, FreeSpace -auto
to
$Output = Get-WmiObject Win32_logicaldisk | Format-Table DeviceId, MediaType, Size, FreeSpace -auto
It seems like this fixed the previous error, but when I try to put it into a job step, the job fails with this error message:
Unable to start execution of step 1 (reason: line(18): Syntax error). The step failed.
Line 18 would be this one:
$Command.CommandText ="INSERT into DiskSpace ([Drive], [MediaType], [Size], [FreeSpace]) VALUES ('$($Output.DeviceId)', '$($Output.MediaType)', '$($Output.Size)', '$($Output.FreeSpace)')"
Strange enough, when I run this script from the powershell command line, it runs without errors, but it inserts twice as many records into the table as there are rows in $output. There are 4 rows in $output and it inserts 8. It would not be so bad, but the data is all zeros:
Drive,MediaType,Size,FreeSpace
,0,0,0
,0,0,0
,0,0,0
,0,0,0
,0,0,0
,0,0,0
,0,0,0
,0,0,0
When I run $output from the command line in powershell, I get the correct information:
DeviceId MediaType Size FreeSpace
-------- --------- ---- ---------
A: 5
C: 12 146154967040 105137184768
D: 12 536862916608 18457624576
E: 11