I want all the server name and the process information in CSV file but please see
below the result is coming wrongIt brings only server info but not the process information. I am using PS V2Function GetStatusCode
Function Get-ProcessData { Param([string] $ComputerName) $ProcessData=Get process | Select Name return $ProcessData } $ServerList = Get-Content "C:\temp\Report\ServerList.txt" $Result1 = @() $oArray01=@() $ProcessData=$null Foreach($ServerName in $ServerList) { $OperatingSystem = Get-WmiObject Win32_OperatingSystem -ComputerName $ServerName -ErrorAction SilentlyContinue $ProcessData=Get-ProcessData $ServerName $NewObject01 = new-object PSObject $NewObject01 | add-member -membertype NoteProperty -name "Server Name" -Value $ServerName $NewObject01 | add-member -membertype NoteProperty -name "Process Data" -Value $ProcessData | % {$_.Name} $oArray01 += $NewObject01 $oArray01 | Export-Csv -Path "c:\temp\report\shortexport01.csv" $Result1 += New-Object PSObject -Property @{ ServerName = $ServerName Process=$ProcessData | % {$_.Name} } }
Result from CSV file the process comes empty. What am I doing wrong?
"Server Name","Process Data"
"00113E",
"00114E",
"00115E",
"00136E",
"00170E",
"00005E",
"18001Q",
"18101Q",
"28001Q",
"28002Q",
"28101Q",
"28102Q",
"28201Q",
"28202Q",
↧
PS Object to CSV file
↧