Simple one (i hope) I’m working on a script to automate the process of logging off then removing local user profiles from Remote Desktop Servers. I’ve fallen at the first hurdle and cannot get the script to delete a folder based on a variable - let me show you what i have
Note that the variables in param has to be in the same order as the ArgumentList, though the names doesn’t have to be the same, but it makes it easier.
There is a few group policy settings that delete profiles off the server automatically when the user logs off. If you enable these profiles should get deleted automatically.
So, i’ve got it working thanks to you lovely people - I’m developing it a bit further and need to add a bit of code that i haven’t had to use before, allow me to explain.
currently im deleting profiles from session hosts. As you may know, people can create multiple sessions and with that the profiles have “extensions” put onto the end of their original profile name, e.g
testuser can then next time be called testuser.001, testuser.SDC etc etc. Is there a way to include a wildcard so that i capture all of the variances?
My current line of code to remove is
Remove-Item -Path \\$sessionhosts\C$\Users\$user
What i was thinking is adding * after $user? Would that work?
The $user is defined by a read-host, which in 99% of cases will be their default username without any of the extras, this is why i want to be able to capture all variances