inactive users
1 TopicAdd to the search of inactive users multiple OUs
Hi all I came with a script that works fine what it does is to find users that haven't logged on in more than 90 days in an specific OU and then it disables them, however I need the script to search for 2 more OUs instead of only one but I couldn't make it work, this is the script: #Script to disable users that not login for more than 90 days #Create the report file $FileName = "DisabledUsers" + (Get-Date).ToString("dd-MM-yyyy") + ".csv" New-Item -Path "C:\temp" -Name $FileName -ItemType File Add-Content -Path C:\temp\$fileName -Value "Account,Disabled date,Last Logon Date" $DisabledDate = Get-Date -Format dd/MM/yyyy $UsersToDisable = Get-ADUser -Filter 'Enabled -eq $True' -SearchBase “OU” -Properties LastLogonDate,WhenCreated | where {$_.LastLogonDate -lt (get-date).AddDays(-90) -and $_.WhenCreated -lt (get-date).AddDays(-90)} foreach($User in $UsersToDisable){ foreach($User in $UsersToDisable){ if($User.DistinguishedName -notlike "OU"){ Disable-ADAccount -Identity $User.SamAccountName -Confirm:$false if((Get-ADUser -Identity $User.SamAccountName)){ $Account = $User.SamAccountName $LastLogon = $User.LastLogonDate $Value = "$Account,$DisabledDate,$LastLogon" Add-Content -Path C:\temp\$FileName -Value $Value } } } In this partGet-ADUser -Filter 'Enabled -eq $True' -SearchBase “OU” i tried to create above something like this: $OU = 'OU1','OU2' and then tried to pipe it but it did not work. Any thoughts how could I make it work? Many thanks!Solved805Views0likes3Comments