title: Powershell exporting variables to excel
body: <p>Ok, so I've been given the task of learning powershell at work to write a few scripts. I have some experience with other languages (just a little) like Java, Python, HTML, and CSS. Powershell is turning out to be a totally different beast, and so I'm not exactly sure how to go about doing things sometimes. Right now I'm trying to figure out how to get my computer name, domain, username and datetime into an excel doc. Here's what I'm trying:</p>
  
  <pre><code>$compname = $env:COMPUTERNAME | Select-Object @{Name='Computer Name'; Expression={$_.Computer_Name}}
  $domain = $env:USERDNSDOMAIN | Select-Object @{Name='Domain'; Expression={$_.Domain}}
  $user = $env:USERNAME | Select-Object @{Name='Username'; Expression={$_.Username}}
  $date = Get-Date -format F | Select-Object @{Name='Date'; Expression={$_}}
  $file = "$env:USERPROFILE\Desktop\test4.csv" 
  $row = @($Date, $compname, $domain, $user)
  $row | Export-Csv $file -NoType
  </code></pre>
  
  <p>I put my variables into an array hoping it would help, but no luck. Right now only the date is printing. The other variables are all empty and I have no idea why. I can get them to work using Write-Out, but not exactly the way I want, and I'm assuming that Export-CSV is my best option. Am I wrong in that assumption?</p>