Ich versuche, einige Systeminformationen von Domänencomputern zu erhalten. Ich führe dieses Skript, aber es endet nie.Was ist mit diesem PowerShell-Skript falsch?
Das Skript generiert die Computernamen in eine Textdatei, aber dann scheitert es die benötigten Informationen von jedem Computer zu erhalten.
Ich bin sicher, dass etwas im Skript fehlt, aber ich bin nicht ganz mit PS-Scripting vertraut.
Jede Hilfe würde sehr geschätzt werden.
# Get a list of all computer names and export to text file
Get-ADComputer -Filter * -Property * | Select -Expand Name | Out-File Z:\test.txt
#Get the computer name and find the below infromation for each individual computer
get-content -path z:\test.txt | % {
$computerSystem = get-wmiobject Win32_ComputerSystem
$computerOS = get-wmiobject Win32_OperatingSystem
$computerCPU = get-wmiobject Win32_Processor
$computerHDD = Get-WmiObject Win32_LogicalDisk -Filter drivetype=3 }
#Prepare the below information for a CSV file
$csvObject = New-Object PSObject -property @{
'PCName' = $computerSystem.Name
'Manufacturer' = $computerSystem.Manufacturer
'Model' = $computerSystem.Model
'RAM' = "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB)
'HDDSize' = "{0:N2}" -f ($computerHDD.Size/1GB)
'HDDFree' = "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size)
'CPU' = $computerCPU.Name
'OS' = $computerOS.caption
'User' = $computerSystem.UserName
'BootTime' = $computerOS.ConvertToDateTime($computerOS.LastBootUpTime)
}
#Export the fields you want from above in the specified order
$csvObject | Select User, Model, PCName, OS, CPU, Ram | Export-Csv 'system-info.csv' -NoTypeInformation -Append
}
Vielen Dank. Das Skript lief perfekt, als ich es heute getestet habe. Ich habe versucht, den Computern eine Ping-Option hinzuzufügen und nur Details von den Computern zu erhalten, die online sind. Wie erreiche ich das? –
Wenn ich Folgendes hinzufüge: get-content Z: \ test.txt Wenn {Test-connection $ _} Else {"$ _ ist down"} –
Mehr wie 'Get-Content z: \ test.txt | ForEach {if (Test-Verbindung $ _) {"$ _ ist up"} else {"$ _ ist down"}} ' – TessellatingHeckler