I currently have this script setup and running on our primary domain. The script is running via a scheduled task. We have a separate domain that we have a trust with, and I would also like to get this running against those users. Is there a simple way to point it to that domain as well? Or, will I need to set this up with another app registration and run it locally on that domain?
If I modify line 63 as such- $users = get-aduser -server "DC.newdomain.local" -filter * -SearchBase "OU=Departments,DC=newdomain,DC=local"-properties Name, PasswordNeverExpires, PasswordExpired, PasswordLastSet, EmailAddress |where {$_.Enabled -eq "True"} | where { $_.PasswordNeverExpires -eq $false } | where { $_.passwordexpired -eq $false }
I can get that to pull the users by using the -server option just running that line, but when I try to run the entire script I get the "Failed to aquire token" error.
Figured I would try to comment here and hope for a response before I go through the trouble of setting up another instance.
Edit: I was able to get this working without having to setup a new app registration. For anyone else who might be trying to do the same, I basically just copied the entire script and pasted it below in the existing powershell file. I made my modifications to the bottom portion to point to the separate domain, OU, log file, etc. and it was successful running.