Hallo liebe Freunde,
ich bin neu in Powershell.
Ich habe ein Skript geschrieben, daß alle Win7 Rechner aus dem AD ausliest, die Erreichbarkeit per Ping testet und die Ergebnisse in eine CSV exportiert.
Diese Liste soll ein Grundlage dienen um ein zweites Skript zu füttern.
Leider habe ich ein Problem die CSV zu verwenden und weiß nciht woran es liegt.
$Computers = Import-Csv -Path .\Hosts.csv $Path1 = "C:\Windows\Softwaredistribution\Download" $Path2 = "C:\Windows\SoftwareDistribution\DataStore" $Path3 = "C:\Windows\winsxs" Param( [Array] $Computers ) Function Class-Size($size){ IF($size -ge 1GB) { "{0:n2}" -f ($size / 1GB) + " GB" } ELSEIF($size -ge 1MB) {"{0:n2}" -f ($size / 1MB) + " MB" } ELSE {"{0:n2}" -f ($size / 1KB) + " KB" } } function Get-FolderSize { Param( [Array]$Computers ) $Array = @() Foreach($ComputerName in $Computers) { $ErrorActionPreference = "SilentlyContinue" $Length1 = Invoke-Command -ComputerName $Computer -ScriptBlock { (Get-ChildItem C:\Windows\Softwaredistribution\Download -Recurse | Measure-Object -Property Length -Sum).Sum #(Get-ChildItem C:\Windows\SoftwareDistribution\DataStore -Recurse | Measure-Object -Property Length -Sum).Sum #(Get-ChildItem C:\Windows\winsxs -Recurse | Measure-Object -Property Length -Sum).Sum } $Result = "" | Select Computer,Folder,Length $Result.Computer = $Computer $Result.Folder = $Path1 $Result.Length = Class-Size $length1 $array += $Result $Length2 = Invoke-Command -ComputerName $Computer -ScriptBlock { (Get-ChildItem C:\Windows\SoftwareDistribution\DataStore -Recurse | Measure-Object -Property Length -Sum).Sum } $Result = "" | Select Computer,Folder,Length $Result.Computer = $Computer $Result.Folder = $Path2 $Result.Length = Class-Size $length2 $array += $Result<# $Length3 = Invoke-Command -ComputerName $Computer -ScriptBlock { (Get-ChildItem C:\Windows\winsxs -Recurse | Measure-Object -Property Length -Sum).Sum } $Result = "" | Select Computer,Folder,Length $Result.Computer = $Computer $Result.Folder = $Path3 $Result.Length = Class-Size $length3 $array += $Result #> } return $array | Export-Csv -NoTypeInformation C:\Work\Result.csv } Get-FolderSize -Computers $Computers.ComputerName
Die Syntax is:
Get-FolderSize -Computers Client001, Client002 usw.
Die CSV sieht wie folgt aus:
ComputerName,"Status" Client001,"True" Client002,"True"