我终于得到了我的脚本的功能,现在我想保存到 CSV,我使用| Export-CSV -path .\output.csv -Delimiter ";"
. 但无法获得我需要的数据。
我正在创建一个全局空数组并尝试在foreach-object
循环中附加项目但得到一个空的 CSV
我也在做我foraech-object
的工作并管道 | Export-CSV -path .\output.csv -Delimiter ";"
并获得一组随机数字
如何将我的数据输入 CSV?
我的脚本
Function Get-FileName{
[System.Reflection.Assembly]::LoadWithPartialName(“System.windows.forms”) | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = Get-Location
$OpenFileDialog.filter = “All files (*.*)| *.*”
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$Importfile = Get-FileName
$Clients = Get-Content $Importfile
$Do = $Clients | ForEach-Object -Parallel {
# CHECK IF PC IS IN AD AND STATUS OF PC IN AD ENABLED/DISABLED
$O = get-ADComputer -Identity $_ -Properties Enabled
if ($O."Enabled" -eq 'TRUE') {
#CHECK IF PC IS NETWORK ACCESSIBLE
if (Test-Connection -ComputerName $_ -Count 2 -Quiet){
try{
#GET LATEST KB PATCH INSTALLED
Get-HotFix -ComputerName $_ -Description 'Security Update' | Select-Object -Last 1 # tried to get csv from here and only capture what passes through here and not the catch or elses also tryed appending this to empty array
}
catch{
"$_;An error occurred."
}
}
else{
"$_;not on line "
}
}
else{
"$_;Disabled PC"
}
} -AsJob
$Do | Receive-Job -Wait # i tried " | Export-CSV -path .\output.csv -Delimiter ";" " and got random data