how to write to csv instead of write host powershell

Viewed 30
$var = @();
Get-AzureAdUser -All $true -filter 'accountEnabled eq false' | ForEach { $licensed=$False ; For ($i=0; $i -le ($_.AssignedLicenses  |
 Measure).Count ; $i++) { If( [string]::IsNullOrEmpty(  $_.AssignedLicenses[$i].SkuId ) -ne $True)
  { $licensed=$true } } ;  If( $licensed -eq $true)  {  if( {($_.licenses).AccountSkuId -match "STANDARDPACK"}) {  $var += Write-Host  $_.UserPrincipalName, $_.AssignedLicenses[$i].SkuId}   } }
  $var | Export-Csv c:\temp\users.csv

I am trying to write the write host output to a csv i have tried replacing write host with export csv but i cant seem to see what variable s to save to an array tried the same as write host and mail the output is emails for write host but it is not working

0 Answers
Related