Remove folders from \\server\home$ if no match in AD

I want to find a script (playing with Get-ADUser with no success) to search through a server share and compare the folder name to the current samaccountnames in AD. If there’s no match, I want to move the folder to a “termed” folder.

Any ideas?


What does “playing with Get-ADUser with no success” mean? Please show your code and explain what did not work out as expected. (If you post code format it as code using the code tag button ‘pre’ on the edit bar of the post editor. That counts as well for sample data and console output. )

To summarize what could be used for this task - you can use Get-ADUser, Get-ChildItem, a foreach loop, comparison operators and Move-Item.
If you’re not already familiar with Powershell you should read the complete help including the examples of all cmdlets you’re about to use. :wink: