Hi,
I have the following code that I have put together
This loops through the computer in the OU and checks for a few details about that PC. The issues I have is that I can't get it to recursively check sub / child OUs. Any ideas?
Thanks
I have the following code that I have put together
Code:
$ou = [ADSI]"LDAP://OU=test,OU=domain,DC=local,DC=co,DC=uk"
$files = ("C:\Scripts\$(get-date -f yyyy-MM-dd-hh-mm-ss)-loggedin.csv")
<# edit the above variables to suit your environment #>
$vers = (get-host | select-object Version | Format-Wide | Out-String).trim()
cls
echo " "
echo "This script must be run as a domain admin in Powershell 3.0 or above"
echo " "
write-host "You are currently running Powershell version " -nonewline
write-host "$vers" -NoNewline
write-host " as user " -NoNewLine
Write-Host "$env:UserName"
echo " "
echo "It will output details of who is logged into all systems in the following OU" $ou
echo " "
echo "And write the results to $files"
echo " "
Write-Host "Press any key to run the script ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
cls
foreach ($child in $ou.psbase.Children) {
if ($child.ObjectCategory -like '*computer*') { $strComputers += $child.Name } }
foreach ($strComputer in $strComputers) {
gwmi win32_computersystem -comp $strComputer | select Username,Caption,Manufacturer,Model | Export-Csv -append -path ($files)}
Echo "Export Completed"
This loops through the computer in the OU and checks for a few details about that PC. The issues I have is that I can't get it to recursively check sub / child OUs. Any ideas?
Thanks