• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

create meaningful csv file from a script

Hi I am having difficulty exporting this script to csv i would like it to have a column header for computers and OU then all results beneath them accordingly.
 
Get-QADObject -SearchScope "onelevel" -Type 'organizationalUnit' -SearchRoot  "OU=time,DC=domain,DC=com" |foreach  ($_.DN) {((write-output $_.DN),(write-output "Computer Count"), ((get-qadcomputer -searchroot $_.dn).count))} >> C:\Users\admin\Documents\computer.csv

Open in new window

0
davidm27
Asked:
davidm27
  • 5
  • 3
1 Solution
 
morpheiosCommented:
Tr to use  Export-Csv Cmdlet
http://technet.microsoft.com/en-us/library/ee176825.aspx

For selecting fields Select-Object Cmdlet
http://technet.microsoft.com/en-us/library/ee176955.aspx

Something like that

$FilePath = "c:\YourDir\people3.csv" 
$OuDomain = "OU=YourPlace,DC=cp5,DC=mosel" 
Get-QADUser -searchRoot $OuDomain | select-Object name, SamAccountName, UserPrincipalName | Export-Csv $FilePath

Open in new window


0
 
davidm27Author Commented:
Hi this is getting at what I'm looking for, but my starting script shows totals for the number of users not the individual users (as in the last script) it adds up the number of users in each OU. I've tried to modify the script to show this but i cant get it to show the column totals and there respective OU's

thanks

$FilePath = "C:\Users\admin\Documents\users.csv" 
$OuDomain = "OU=time,DC=domain,DC=com" 
Get-QADObject -SearchScope "onelevel" -Type 'organizationalUnit' -SearchRoot $OuDomain |foreach  ($_.DN) {((write-output $_.DN),(write-output "User Count,"),(Get-QADUser -SearchRoot $_.DN).count) } | select-Object "user count", $_.DN | Export-Csv $FilePath

Open in new window

0
 
morpheiosCommented:
May be you need more easy way:

Get-QADUser | Group-Object ParentContainerDN | Select Name, Count
or
Get-QADUser | Group-Object ParentContainerDN | Select Name, Count | Export-Csv 123.csv
0
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
morpheiosCommented:
Also you may sort output:

Get-QADUser | Group-Object ParentContainerDN | Sort Count -descending | Select Name, Count
or
Get-QADUser | Group-Object ParentContainerDN | Sort Name | Select Name, Count
0
 
davidm27Author Commented:
hi this is much simpler/better Get-QADUser | Group-Object ParentContainerDN | Sort Count -descending | Select Name, Count

I only want it OU's below a certain parent folder though how would i specify this then export to csv

thanks

0
 
morpheiosCommented:
Get-QADUser | Group-Object ParentContainerDN | Where {$_.Name -like "*OU=time,DC=domain,DC=com"} | Sort Count -descending | Select Name, Count

Open in new window

0
 
morpheiosCommented:
This will be faster
Get-QADUser -SearchRoot "OU=time,DC=domain,DC=com" | Group-Object ParentContainerDN | Sort Count -descending | Select Name, Count

Open in new window

0
 
davidm27Author Commented:
thanks great solution twice as fast as the way i was trying to do it
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now