PowerShell桌面变量 [英] PowerShell Desktop Variable

查看:133
本文介绍了PowerShell桌面变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过sccm安装后,我试图编写PowerShell脚本来删除Chrome的桌面图标。但是,网络中的某些用户会将其桌面定向到网络上的不同文件夹。 PowerShell中是否存在用于存储桌面位置的变量?

I am trying to write a PowerShell script to remove the desktop icon for Chrome after installing through sccm. However, certain users in the network have their desktop directed to different folders on the network. Is there a variable in PowerShell that stores the location of the desktop?

我已经在线查看并使用搜索-可变| Out-String ,但我什么也没找到。完成的代码应如下所示:

I have looked online and searched using Get-Variable | Out-String, but I didn't find anything. The finished code should look like:

If (Test-Path "$DesktopLocation\Google Chrome.lnk"){
    Remove-Item "$DesltopLocation\Google Chrome.lnk"
}


推荐答案

您可以使用 Environment.GetFolderPath()方法以获取特殊文件夹的完整路径:

You can use the Environment.GetFolderPath() method to get the full path to special folders:

$DesktopPath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop)

此可以缩短为:

$DesktopPath = [Environment]::GetFolderPath("Desktop")




您还可以获取 AllUsers共享的桌面文件夹(如果快捷方式文件在所有用户之间共享):


You can also get the "AllUsers" shared desktop folder (if the shortcut file is shared among all users):

[Environment]::GetFolderPath("CommonDesktopDirectory")

签出 SpecialFolder 枚举

这篇关于PowerShell桌面变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆