I'm writing my first powershell script:
foreach ($UserDir in Get-ChildItem -Path $NetworkLocation)
{
# if the item is a directory, then process it.
if ($UserDir.Attributes -eq "Directory")
{
$Dir = $UserDir.Name
Remove-Item $Dir +"*" -recurse
}
}
Will $Dir end with a trailing "\" so I can just add a * to delete all files in that directory?
Best Answer
No it won't supply a trailing slash.
Nor will it supply full path:
That is provided through "fullname", which also doesn't provide a trailing slash. However, Remove-Item doesn't need slashes!
In summary, to remove all files in a directory and all files in it's sub-directories, use:
where