Hi All
definitely new to powershell and this is breaking me. i have a script that works fine until i run it through an invoke-command to do it remotely. ive pulled this out of a larger script but then this is in it messes up the output to csv and i end up with this
<colgroup> <col style="width: 48pt;" width="64" /> </colgroup>Length |
7 |
7 |
7 |
6 |
#this works until i put it through the invoke-command.#some pointless notes on straight forward code
#create a file and put a couple of servers in it, change this to that file
$complist = “C:\temp\ewan\computers.txt”#change this where you want the output spitting out too
$outreport = “C:\temp\ewan\superballs_” + $((Get-Date).ToString(‘MM-dd-yyyy’)) + “.csv”#Invoke command breaks this
Invoke-Command -ComputerName (Get-Content $complist) -Credential $credentials -scriptblock {#gets physical disks on device
$colDisks = get-wmiobject Win32_LogicalDisk -Filter “DriveType = 3”
$Space = “No Space Issues”
#works out %free on any disks
foreach ($disk in $colDisks) {
if ($disk.size -gt 0) {$PercentFree = [Math]::round((($disk.freespace/$disk.size) * 100))}
else {$PercentFree = 0}$Drive = $disk.DeviceID
“$Drive - $PercentFree”
#if less that 10% free it should complain
if ($PercentFree -le 10) {
$Space = “Low on space”;
}
}#writes some stuff that can by output to a csv
$infoObject = New-Object PSObjectAdd-Member -inputObject $infoObject -memberType NoteProperty -name “Disk Space” -value $Space -Force
$infoObject} | Select-Object * -ExcludeProperty PSComputerName, RunspaceId, PSShowComputerName | Export-Csv -path $outreport -NoTypeInformation
#HALP