navcontainerhelper/Common/Remove-DesktopShortcut.ps1

46 строки
1.6 KiB
PowerShell
Исходник Постоянная ссылка Обычный вид История

2019-09-03 12:42:17 +03:00
<#
.Synopsis
Remove a shortcut
.Description
Remove a shortcut
.Parameter Name
2019-09-03 12:46:10 +03:00
Name of shortcut to remove from all locations
2019-09-03 12:42:17 +03:00
#>
function Remove-DesktopShortcut {
Param (
2019-05-23 07:18:48 +03:00
[Parameter(Mandatory=$true)]
2019-09-03 12:42:17 +03:00
[string] $Name
2019-05-23 07:18:48 +03:00
)
2019-11-08 17:55:50 +03:00
"Desktop","CommonDesktop" | % {
$environmentPath = [Environment]::GetFolderPath($_)
If ($environmentPath -ne "") {
$filename = Join-Path $environmentPath "$Name.lnk"
2019-12-05 17:24:32 +03:00
if (Test-Path -Path $filename -PathType Leaf) {
2019-11-08 17:55:50 +03:00
Remove-Item $filename -force
}
2019-12-05 17:24:32 +03:00
else {
$folderName = $Name.Split(' ')[0]
$shortcutName = $name.Substring($folderName.Length).TrimStart(' ')
2019-12-05 17:24:32 +03:00
$folderName = Join-Path $environmentPath $folderName
2021-12-02 09:32:18 +03:00
$filename = Join-Path $foldername "$shortcutName.lnk"
if (Test-Path -Path $filename -PathType leaf) {
Remove-Item $filename -Force
try {
Remove-Item $folderName -Recurse -force
} catch {}
2019-12-05 17:24:32 +03:00
}
}
2019-05-23 07:18:48 +03:00
}
}
2019-11-08 17:55:50 +03:00
"StartMenu","CommonStartMenu" | % {
$environmentPath = [Environment]::GetFolderPath($_)
if ($environmentPath -ne "") {
2020-07-27 22:14:28 +03:00
$filename = Join-Path $environmentPath "BcContainerHelper\$Name.lnk"
2019-11-08 17:55:50 +03:00
if (Test-Path -Path $filename) {
Remove-Item $filename -force
}
2019-05-23 07:18:48 +03:00
}
}
}
Export-ModuleMember -Function Remove-DesktopShortcut