Jump to content

Recommended Posts

Posted

Does anyone know a way of using a wildcard with RMDir command in cmd we are trying to do "C:\Users\*\OneDrive - eLearning & Information Management\tempsimsrpt" /S /Q but it's not playing ball.

 

I'm aware we could remove item in powershell but it's not a fan of the - naming of the path. We have tested RMDIR and it works just need it for every user

Posted

Something like this, run from an elevated powershell prompt ? it should capture a list of all the folders that match your criteria in the $ListOfFolders variable, and then they can be piped individually to a delete command

 

$BaseDir = "C:\Users"
$NameToFind = "OneDrive - eLearning & Information Management\tempsimsrpt"

$ListOfFolders = Get-ChildItem $BaseDir -Recurse | Where-Object { $_.PSIsContainer -and $_.FullName -like "*$NameToFind"}

foreach($FolderToDelete in $ListOfFolders)
{
$FolderToDelete.FullName
#Remove-Item -Path $FolderToDelete.FullName -Recurse -Force
#RMDIR /S /Q $FolderToDelete.FullName
}

 

Run it once as is to list all the folders it wants to delete, then all you need to do is remove the hash in front of the command you want to use to actually carry out the delete. I would advise testing it on one machine with not many users first (maybe after making a backup) just in case it goes wrong.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...