I'm trying to knock out a simple enough (I thought) script to clean up older versions of Zoom that were deployed via browser but leaving fully installed versions alone.
Put together the following:
$UserDir = "C:\Users"
$TargetFolder = "AppData\Roaming\Zoom\bin"
Get-ChildItem $UserDir -Directory -Exclude Default*,Public | foreach {
$joined_path = Join-Path -Path $_,FullName -ChildPath $TargetFolder
if (Test-Path $joined_path) {
remove-item "$joined_path\" -Force
}
}
And it 'kind of' works, I'm getting the following error:
remove-item : Cannot find path 'C:\Users\Admin\AppData\Roaming\Zoom\bin FullName\AppData\Roaming\Zoom\bin\'
because it does not exist.
It's apparent that I'm not understanding the join-path command quite right, and it's duplicating the path it's searching for.
The idea here is to delete the target directory (\AppData\Roaming\Zoom\Bin) from all profiles - ironically perhaps the error messages show that it is searching through multiple profiles, but it's tagging on the target folder twice and I'm confused as to why.
Added a line to specify the $joined_path variable as null so as to then add some variable outputs to try and understand where I'm going wrong:
$UserDir = "C:\Users"
$TargetFolder = "\AppData\Roaming\Zoom\bin"
$joined_path = ""
Get-ChildItem $UserDir -Directory -Exclude Default*,Public | foreach {
write-output "resulting joined path1 is" $joined_path
$joined_path = Join-Path -Path $_,FullName -ChildPath $TargetFolder
write-output "resulting joined path2 is" $joined_path
if (Test-Path $joined_path) {
remove-item "$joined_path" -Force
}
$joined_path = ""
}
Now I'm seeing the following in the output:
resulting joined path1 is
resulting joined path2 is
C:\Users\Admin\AppData\Roaming\Zoom\bin
FullName\AppData\Roaming\Zoom\bin
This indicates to me that it's the line between the two outputs, just struggling to understand why.