title: Powershell add field and format to single line field=value
body: <p>My Powershell report needs to take:
      [TimeZoneInfo]::Local</p>
  
  <p>and add two fields: Hostname (or $env:computername) and date fields to the object/format-list,</p>
  
  <p>and then replace all "\t:\t" (colon between tabs) with "=" and all "\n" (new lines) with ","</p>
  
  <p>For the final result:
  Id=Central Standard Time,DisplayName=(UTC-06:00) Central Time (US &amp; Canada),StandardName=Central Standard Time,DaylightName=Central Daylight Time
  BaseUtcOffset=-06:00:00,SupportsDaylightSavingTime=True,hostname=ANDREW-PC</p>
  
  <p>The respective powershell commands to pull the data of interest are (simply):</p>
  
  <pre><code>[TimeZoneInfo]::Local
  Hostname
  $env:computername
  date
  </code></pre>
  
  <p>What is the best way to do this?</p>
  
  <p>Added, so far I have added the two fields with the following code:</p>
  
  <pre><code>$tz=[TimeZoneInfo]::Local
  $time=date
  Add-Member -inputobject $tz -membertype noteproperty -name time -value $time
  $hostname=$env:computername
  Add-Member -inputobject $tz -membertype noteproperty -name hostname -value $hostname
  </code></pre>
  
  <p>Here is my final solution:</p>
  
  <pre><code>$os=Get-CimInstance Win32_OperatingSystem | Select-Object  @{Expression={$_.caption};Label="os"},@{Expression={$_.InstallDate};Label="time_os_install"},@{Expression={$_.OSArchitecture};Label="os_arch"},@{Expression={$_.BootDevice};Label="os_boot"},@{Expression={$_.CSName};Label="hostname_os"},@{Expression={$_.SystemDirectory};Label="os_dir"},@{Expression={$_.RegisteredUser};Label="user_os"},@{Expression={$_.SerialNumber};Label="os_serial"},@{Expression={$_.Version};Label="os_ver"}
  $bios=Get-wmiObject -class win32_bios | Select-Object @{Expression={$_.SMBIOSBIOSVersion};Label="bios_ver"},@{Expression={$_.Manufacturer};Label="bios_company"},@{Expression={$_.Name};Label="bios_name"},@{Expression={$_.Version};Label="version"}
  $ipconf=Get-NetIPConfiguration -InterfaceAlias *Connection | Select-Object @{Expression={$_.ComputerName};Label="hostname"},@{Expression={$_.InterfaceAlias};Label="name"},@{Expression={$_.InterfaceIndex};Label="index"},@{Expression={$_.InterfaceDescription};Label="description"},@{Expression={$_.IPv4Address};Label="src"},@{Expression={$_.IPv4DefaultGateway.NextHop};Label="gateway"},@{Expression={$_.DNSServer.ServerAddresses[0]};Label="dns1"},@{Expression={$_.DNSServer.ServerAddresses[1]};Label="dns2"},@{Expression={$_.NetAdapter.MacAddress};Label="mac"},@{Expression={$_.NetAdapter.Status};Label="status"}
  $tz=[TimeZoneInfo]::Local | Select-Object @{Expression={$_.Id};Label="tz_id"},@{Expression={$_.BaseUtcOffset};Label="tz_utc"},@{Expression={$_.SupportsDaylightSavingTime};Label="tz_dst"}
  $time=Get-Date -UFormat %s
  $hostname=[Environment]::MachineName
  $user=[Environment]::UserName
  
  $pattern_src = "[^\d\.].+"
  $src=$ipo."IPv4 Address" -Replace $pattern_src,""
  
  $pattern_ver2 = "[^a-zA-Z\d\-]+"
  $bios_ver2=$bios.version -Replace $pattern_ver2,""
  
  $computer = New-Object PsObject -property @{user=$user; hostname=$hostname; time=$time; os=$os.os; time_os_install=$os.time_os_install; os_arch=$os.os_arch; os_boot=$os.os_boot; hostname_os=$os.hostname_os; os_dir=$os.os_dir; user_os=$os.user_os; os_serial=$os.os_serial; os_ver=$os.os_ver; bios_ver=$bios.bios_ver; bios_company=$bios.bios_company; bios_name=$bios.bios_name; bios_ver2=$bios_ver2; tz_id=$tz.tz_id; tz_utc=$tz.tz_utc; tz_dst=$tz.tz_dst;adapter_hostname=$ipconf.hostname; adapter_name=$ipconf.name; adapter_index=$ipconf.index; adapter_description=$ipconf.description; src=$ipconf.src; gateway=$ipconf.gateway; dns1=$ipconf.dns1; dns2=$ipconf.dns2; mac=$ipconf.mac; adapter_status=$ipconf.status}
  
  (($computer | out-string).split("`r`n") | ? {$_} | % {$_ -replace '\s+:\s+', '='}) -join ','`
  </code></pre>