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

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

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

  1. function unpin_taskbar([string]$appname) {
  2. ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() |
  3. Where-Object{$_.Name -eq $appname}).Verbs() | Where-Object{$_.Name.replace('&','') -match 'Unpin from taskbar'} | ForEach-Object{$_.DoIt()}
  4. }
  5. function unpin_startmenu([string]$appname) {
  6. ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() |
  7. Where-Object{$_.Name -eq $appname}).Verbs() | Where-Object{$_.Name.replace('&','') -match 'Unpin from Start'} | ForEach-Object{$_.DoIt()}
  8. }
  9. foreach ($taskbarapp in 'Microsoft Store') {
  10. Write-Host unpinning $taskbarapp
  11. unpin_taskbar("$taskbarapp")
  12. }
  13. foreach ($startmenuapp in 'ESPN', 'Spotify') {
  14. Write-Host unpinning $startmenuapp
  15. unpin_startmenu("$startmenuapp")
  16. }

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

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

我做错了什么?

6jjcrrmo

6jjcrrmo1#

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

  1. Install-Module -Name Microsoft.PowerShell.StartMenu
  2. Import-Module Microsoft.PowerShell.StartMenu
  3. Remove-StartAppsTaskbarPinned -AppName "Microsoft Store"
  4. Remove-StartAppsStartMenuPinned -AppName "ESPN"
  5. Remove-StartAppsStartMenuPinned -AppName "Spotify"

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

相关问题