从用户配置文件中删除特定文件夹
我试图淘汰一个足够简单的脚本(我认为)脚本,以清理通过浏览器部署但仅留下完全安装的版本的较旧版本的缩放版本。
组合以下内容:
$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
}
}
“有点”工作,我会收到以下错误:
remove-item : Cannot find path 'C:\Users\Admin\AppData\Roaming\Zoom\bin FullName\AppData\Roaming\Zoom\bin\'
because it does not exist.
很明显,我不理解join-path命令是完全正确的,并且正在重复其搜索路径。
这里的想法是从所有配置文件中删除目标目录(\ appdata \ roaming \ Zoom \ bin) - 具有讽刺意味至于原因。
添加了一个行以将$ JOANIND_PATH变量指定为null,以便添加一些变量输出以尝试了解我的错误位置:
$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 = ""
}
现在我在输出中看到以下内容:
resulting joined path1 is
resulting joined path2 is
C:\Users\Admin\AppData\Roaming\Zoom\bin
FullName\AppData\Roaming\Zoom\bin
这向我表明这是之间的界限这两个输出只是在努力理解原因。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢Zett42。
修复错别字使其正常工作,并且看起来确实可以围绕所有配置文件夹,除了我排除在外的文件夹外 - 已经在现在和没有任何问题或错过的配置文件上测试了该文件夹。
Thanks to Zett42.
Fixing the typo got it all working fine, and it does appear to work it's way around all the profile folders except for what I'm excluding - have tested that on multiple devices now and without any problems or missed profiles.