I have to be missing something obvious, this task shouldn't be this hard! Thanks in advance if you can point it out to me without laughing too much. I'm writing a system survey script, to run on each computer in my domain on boot via GPO. Each time it runs it should add a row with all the info it gathers to a csv file on a shared drive. I can only get it to output in columns.
Code:
$loglocation = "C:\Temp"
$timestamp = Get-Date -UFormat "%Y-%m-%d %H:%M"
$ipaddress = Get-NetIPAddress | fl -Property ipaddress | Out-String -stream |
Select-String 10.15
# Add info to hashtable
$computerinfohastable = [ordered]@{
Timestamp = $timestamp
Hostname = hostname
OSName = (Get-WmiObject Win32_OperatingSystem).Caption
OSVer = (Get-WmiObject Win32_OperatingSystem).Version
IPAddress = ($ipaddress -replace "ipaddress : ").Trim()
}
# Convert to object
$computerinforows = $computerinfohastable.Keys | ForEach-Object {
[PSCustomObject]@{
Property = $_
Value = $computerinfohastable[$_]
}
}
# Output to csv
$computerinforows | Export-Csv -Path "$loglocation\testfile.csv" -
NoTypeInformation -Append
What I get:
Property Value
Timestamp 11/25/2024 14:23
Hostname #####
OSName Microsoft Windows 11 Enterprise
OSVer 10.0.26100
IPAddress nnn.nnn.nnn.nnn
What I want:
Timestamp Hostname OSName OSVer IPAddress
11/25/2024 14:23 ##### Microsoft Windows 11 Enterprise 10.0.26100 nnn.nnn.nnn.nnn
I have been hitting up the internet and tried several methods for transposing, no success. Appreciate any advice.
Omit intermediary
$computerinfohastable = [ordered]@{ … }
, useIf you insist on intermediary
$computerinfohastable = [ordered]@{ … }
, use a simple casting as follows:In both variants, you should get