I have found and modified this snippet to output exactly what I need inside of a Powershell window:
Get-ADOrganizationalUnit -Properties canonicalname -Filter *|
ForEach-Object{
[pscustomobject]@{
OUName = Split-Path $.CanonicalName -Leaf
CanonicalName = $.CanonicalName
UserCount = (Get-AdUser -Filter * -SearchBase $.DistinguishedName -SearchScope OneLevel).Count
ComputerCount = (Get-AdComputer -Filter * -SearchBase $.DistinguishedName -SearchScope OneLevel).Count
}
}
It displays a simple table with the 4 columns I need, but I’m struggling with where I can input the command to export this output into a CSV. When I do get it to create a file, the .csv is empty.
If you want to export some structured data to a CSV file you can use
Please read the help completely including the examples to learn how to use it.
You may read as well the help for
This could help you to find some cmdlets you don’t know about yet.
Regardless of that when you post code please format it as code using the preformatted text button ( </> ), simply place your cursor on an empty line, click the button and paste your code.