PowerShell Desktop Variable

前端 未结 3 1950
无人及你
无人及你 2021-02-06 22:27

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 t

相关标签:
3条回答
  • 2021-02-06 23:25

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

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

    This can be shortened to:

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

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

    [Environment]::GetFolderPath("CommonDesktopDirectory")
    

    Check out the full list of values for the SpecialFolder Enum.

    0 讨论(0)
  • 2021-02-06 23:28

    If you need $Desktop\a.txt, use this

    echo ([Environment]::GetFolderPath("Desktop")+"\a.txt")
    
    0 讨论(0)
  • 2021-02-06 23:29

    What you are looking for is known as the $home variable. It's one of PowerShell's built-in automatic variables.

    It defaults to the user-profile path, so drill down to the desktop like this:

    If (Test-Path "$home\Desktop\Google Chrome.lnk") {
        Remove-Item "$home\Desktop\Google Chrome.lnk"
    }
    
    0 讨论(0)
提交回复
热议问题