$OUpath = @(
"OU=example,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=exam.ple,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=example1,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=example2,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=example3,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=example4,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=example5,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=example6,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=example7,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=example8,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=example9,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=CA,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=CAB,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=Ara,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=Gil,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=Kbi,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=Cieux,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=liz,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=mes,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=IO,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=SE,OU=Parent OU,DC=domain name,DC=domain prefix",
"OU=SC,OU=Parent OU,DC=domain name,DC=domain prefix")
foreach ($i in $OUpath){
$fname= $i.Substring(3,9) + ".csv"
Get-ADComputer -Filter * -Property * -SearchBase $i.toString() |
Select-Object Name,OperatingSystem,OperatingSystemVersion |
Export-CSV $fname -NoTypeInformation -Encoding UTF8
}
Remark: OU=exam.ple with $fname= $i.Substring(3,9) + ".csv" gives not an excel csv file because of the dot in the ou name.
Question: Is it possible to generate 1 excel file with different workSheets ? And transform the data directly into excel tables ?