I finally got the functionality of my script working now I want to save to CSV, Im using the | Export-CSV -path .\output.csv -Delimiter ";"
. but not able to get the data i need.
I'm creating a global empty array and trying to append items within in a foreach-object
loop
but get an empty CSV
im also runing my foraech-object
as a job and piping the | Export-CSV -path .\output.csv -Delimiter ";"
and get a random set of numbers
how can i get my data in to CSV?
My Script
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