Have a question on some weird behavior running powershell on my AD server.
I created a powershell script to retrieve inactive users info from AD, not sure whether it will be related but I include it below:
$searchRoot = @("mydomain.com/TEst/test1","mydomain.com/TEst/test2")
$searchRoot += @("mydomain.com/TEst/test3")
Add-PSSnapin Quest.ActiveRoles.ADManagement<br>
$inactiveUsers = @()
Foreach ($ou in $searchRoot) {
$inactiveUsers += @(Get-QADUser -SearchRoot $ou -Enabled | Select-Object Name,SamAccountName,LastLogonTimeStamp,Description,passwordneverexpires,canonicalName)}
$body = $inactiveUsers
$body | out-file -filepath C:\DisableInactive\disabletest.txt -append
I scheduled this script to run with another ID (not the 1 I logged in), the script should take less than 5 seconds to run, but the schedule task took more than a minute to complete (as below):
"DisableInactiveUsers.job" (powershell.exe)
Started 7/7/2014 2:26:00 PM
"DisableInactiveUsers.job" (powershell.exe)
Finished 7/7/2014 2:27:39 PM
Result: The task completed with an exit code of (0).
However when I logoff and login again with that schedule ID, the schedule completed in 4 secs.
"DisableInactiveUsers.job" (powershell.exe)
Started 7/7/2014 7:02:41 PM
"DisableInactiveUsers.job" (powershell.exe)
Finished 7/7/2014 7:02:45 PM
Result: The task completed with an exit code of (0).
I then login with my own ID and right click to run the schedule again, it completed within 5 secs.
Suspecting something to do with the user profile, I then delete the profile from the System Properties and run the job again, guess what, the scheduled job used more than 1 minutes to complete again.
The script and scheduled task have not been changed during all these logoff and in
I am not sure whether it is related to my script but I really appreciate if someone can point out what's wrong with my script/why the scheduled task behave like this.
Thank you.