Hi @A.Elrayes ,
Move-AdObject
expect a GUID or DN as the -Identity
parameter.
Also you should provide the full DN of the -TargetPath
.
https://learn.microsoft.com/en-us/powershell/module/activedirectory/move-adobject?view=windowsserver2022-ps
In your script the variable $OriginalOU
contains the DN of the user, not the OU of the user. So could try this:
Move-ADobject -Identity $OriginalOU -Targetpath "OU=old users,OU=xxx,DC=xyz,DC=abc"
For Set-AdUser
you could try this:
Set-ADuser $ChangeDiscription -Description ("Disabled dueto inactivity - Moved from $OriginalOU")
If you are posting scripts please use the Code Sample
option (the Icon with 101010
). The Q&A editor will remove some characters of scripts if you paste the script as normal text.
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten
I got that and working
$InactiveUsers | Export-Csv -Path C:\InactiveUsers" "$((Get-Date).ToString('dd-MM-yyyy')).csv -NoTypeInformation
Thanks
Hi @A.Elrayes ,
looks great.
I would recommend to use Year-Month-Date. Might be better for sorting the files in Explorer.
Otherwise the sort order in File Explorer by name is all the files from date 01- , than date 02-
I prefer the Y-M-D sorting for files. But it's totally up to you.
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten