cyncate
November 25, 2020, 12:18pm
1
I am getting proper output in ISE but the CSV is only displaying System.Object , usually I am able to use -join to address this but do not know what I am getting wrong this time.
$Workstations = Get-Content C:\PSscripts\results2.txt
$InfoColl = @()
Foreach ($s in $Workstations)
{
$CPUInfo = Get-WmiObject Win32_Processor -ComputerName $s -ErrorAction SilentlyContinue
$MODEL = gwmi Win32_ComputerSystem -ComputerName $s -ErrorAction SilentlyContinue|select -ExpandProperty Model
$SerialNumber = Get-WmiObject win32_computersystemproduct -ComputerName $s -ErrorAction SilentlyContinue|select -ExpandProperty IdentifyingNumber
$DISPLAY = gwmi Win32_PnPSignedDriver -ComputerName $s -ErrorAction SilentlyContinue | select deviceclass,devicename | where {$_.deviceclass -like “*display*”}
$OSInfo = Get-WmiObject Win32_OperatingSystem -ComputerName $s -ErrorAction SilentlyContinue
$USERS = get-WmiObject -ComputerName $s -ClassName Win32_UserProfile -ErrorAction SilentlyContinue| select LocalPath
$Date = Get-Date -format “yyyy-MM-d”
foreach ($CPU in $CPUInfo)
{
$InfoObject = New-Object PSObject
Add-Member -InputObject $infoObject -MemberType NoteProperty -Name “WorkStationName” -Value $CPU.SystemName
Add-Member -InputObject $infoObject -MemberType NoteProperty -Name “Model” -Value $Model
Add-Member -InputObject $infoObject -MemberType NoteProperty -Name “USERS” -Value ($USERS -join ‘, ‘)
$infoObject
$InfoColl += $InfoObject
}
}
$InfoColl|Export-Csv -Path C:\PSscripts\IOC_Users$((Get-Date).ToString(‘MMddyyyy’)).csv -NoTypeInformation
You need to use select -ExpandProperty LocalPath or reference that property in ($USERS.localpath -join ‘, ‘)
Also, you are doing some older techniques that can be slow an unnecessary. You might be aware but you are collecting several things you aren’t outputting.
$Workstations = Get-Content C:\PSscripts\results2.txt
$workstations | ForEach-Object {
$CPUInfo = Get-WmiObject Win32_Processor -ComputerName $_ -ErrorAction SilentlyContinue
$MODEL = gwmi Win32_ComputerSystem -ComputerName $_ -ErrorAction SilentlyContinue|select -ExpandProperty Model
$SerialNumber = Get-WmiObject win32_computersystemproduct -ComputerName $_ -ErrorAction SilentlyContinue|select -ExpandProperty IdentifyingNumber
$DISPLAY = gwmi Win32_PnPSignedDriver -ComputerName $_ -ErrorAction SilentlyContinue | select deviceclass,devicename | where {$_.deviceclass -like “*display*”}
$OSInfo = Get-WmiObject Win32_OperatingSystem -ComputerName $_ -ErrorAction SilentlyContinue
$USERS = get-WmiObject -ComputerName $_ -ClassName Win32_UserProfile -ErrorAction SilentlyContinue| select -ExpandProperty LocalPath
$Date = Get-Date -format “yyyy-MM-d”
foreach ($CPU in $CPUInfo)
{
[PSCustomObject]@{
WorkStationName = $CPU.SystemName
Model = $Model
USERS = $USERS -join ‘, ‘
}
}
} -OutVariable InfoColl
$InfoColl|Export-Csv -Path C:\PSscripts\IOC_Users$((Get-Date).ToString(‘MMddyyyy’)).csv -NoTypeInformation
Does the entire CSV shows System.Object or only value of a specific column ?
cyncate
December 1, 2020, 12:05pm
4
I am using a modified script that I have been using for years to inventory systems. I got your changes to work, thanks for the assist.