export-csv issues

This topic contains 2 replies, has 2 voices, and was last updated by  ca 10 months, 1 week ago.

  • Author
  • #59787


    hello, if anyone could comment on these issues i'm having it would be much appreciated! I feel like I'm wasting too much time on something pretty simple.. the code below is somewhat of an excerpt to a larger script but it will suffice to address to issues I'm having. The first: why do I continue to get a CSV with the following information:

    IsReadOnly IsFixedSize IsSynchronized Keys Values SyncRoot Count
    FALSE FALSE FALSE System.Collections.Hashtable+KeyCollection System.Collections.Hashtable+ValueCollection System.Object 6

    instead of a table with values?

    Second, I cannot make $report = "C:\report_$dt.csv" because the Export-Csv command complains that it does not like the filename. Anyone know why that is? Thanks in advanced. -ca

    $dt = Get-Date -UFormat %m%d%y:%H:%M%S
    $report = "C:\report.csv"
    $OU = "OU=AN,OU=OU,DC=A,DC=domain"
    $gADC_OU = Get-ADComputer -Filter * -Properties * -SearchBase $OU -ResultSetSize 20
    $gADC_OU_g = $gADC_OU | Select-Object -Property OperatingSystem,Count | `
    	Group-Object -Property OperatingSystem -AsHashTable 
    $gADC_OU_g | Export-Csv $report -Append -NoClobber -NoTypeInformation
  • #59790


    Count is not one of the properties returned by Get-ADComputer.

    I assume your goal is to count operating system names in use. Try this.

    $gADC_OU_g = $gADC_OU | Select-Object -Property OperatingSystem | Group-Object OperatingSystem|Select-Object Name, Count
  • #59799


    Ron, thank you for spotting that. I did update the code with

    $gADC_OU_g = $gADC_OU | Group-Object -Property OperatingSystem | Select-Object -Property Name,Count

    and when I do the export to csv it is working as expected!

You must be logged in to reply to this topic.