windows 使用powershell从任务栏和开始菜单取消固定应用程序

vuktfyat  于 2023-02-16  发布在  Windows
关注(0)|答案(1)|浏览(263)

在Windows 11中,使用PowerShell,我正试图从任务栏中解钉微软商店,从开始菜单中解钉ESPN & Spotify。

function unpin_taskbar([string]$appname) {
    ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() |
        Where-Object{$_.Name -eq $appname}).Verbs() | Where-Object{$_.Name.replace('&','') -match 'Unpin from taskbar'} | ForEach-Object{$_.DoIt()}
}

function unpin_startmenu([string]$appname) {
    ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() |
        Where-Object{$_.Name -eq $appname}).Verbs() | Where-Object{$_.Name.replace('&','') -match 'Unpin from Start'} | ForEach-Object{$_.DoIt()}
}

foreach ($taskbarapp in 'Microsoft Store') {
    Write-Host unpinning $taskbarapp
    unpin_taskbar("$taskbarapp")
}

foreach ($startmenuapp in 'ESPN', 'Spotify') {
    Write-Host unpinning $startmenuapp
    unpin_startmenu("$startmenuapp")
}

Microsoft应用商店已成功取消固定,但接下来的两个失败。这是输出。

unpinning Microsoft Store
unpinning ESPN
You cannot call a method on a null-valued expression.
At C:\Users\Administrator\Desktop\repo\general\rundeck\windows\unpin_windows_apps.ps1:7 char:5
+     ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
unpinning Spotify
You cannot call a method on a null-valued expression.
At C:\Users\Administrator\Desktop\repo\general\rundeck\windows\unpin_windows_apps.ps1:7 char:5
+     ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

我做错了什么?

6jjcrrmo

6jjcrrmo1#

你在看这样的东西有什么变化吗?

Install-Module -Name Microsoft.PowerShell.StartMenu
Import-Module Microsoft.PowerShell.StartMenu

Remove-StartAppsTaskbarPinned -AppName "Microsoft Store"
Remove-StartAppsStartMenuPinned -AppName "ESPN"
Remove-StartAppsStartMenuPinned -AppName "Spotify"

您将需要安装模块“Microsoft.PowerShell.StartMenu”,这是强制运行这些命令的。您可以查看powershell库以了解更多关于这是什么以及它是如何工作的。

相关问题