PowerShell shortcut not working.


  1. Posts : 841
    Windows 10 Pro 21H2
       #1

    PowerShell shortcut not working.


    Shortcut:
    Code:
    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden "& ""D:\Backup\Common\App_Launcher\System_2\EmptyRecycleBin.ps1"""
    If this code is run inside Powershell.ise, it works, but not with the shortcut:
    Code:
    $title    = 'Empty Recycle Bin'
    $question = 'About to empty recycle bin and delete recent files, do you want to proceed?'
    
    $choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription]
    $choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes'))
    $choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&No'))
    
    $decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
    if ($decision -eq 0) {
       # Empty Recycle Bin
        Clear-RecycleBin -Force
    
        Stop-Process -ProcessName explorer    # explorer restarts without any help.
    
        Start-Sleep -Seconds 1
    
        # Remove ghost itmes from Desktop.
        Remove-Item C:\Users\rdwray\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations\*.* -Recurse -Force -Confirm:$false
        Remove-Item C:\Users\rdwray\AppData\Roaming\Microsoft\Windows\Recent\CustomDestinations\*.* -Recurse -Force -Confirm:$false
    } else {
        Write-Host 'cancelled'
    }
    If only this code is used, the shortcut works:
    Code:
       # Empty Recycle Bin
        Clear-RecycleBin -Force
    
        Stop-Process -ProcessName explorer    # explorer restarts without any help.
    
        Start-Sleep -Seconds 1
    
        # Remove ghost itmes from Desktop.
        Remove-Item C:\Users\rdwray\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations\*.* -Recurse -Force -Confirm:$false
        Remove-Item C:\Users\rdwray\AppData\Roaming\Microsoft\Windows\Recent\CustomDestinations\*.* -Recurse -Force -Confirm:$false
      My Computer


  2. Posts : 7,607
    Windows 10 Home 20H2
       #2

    The following shortcut works at my end:

    PowerShell -ExecutionPolicy Bypass -file "E:\Folder\EmptyRecycleBin.ps1"

    Code:
    Microsoft Windows [Version 10.0.19042.746]
    (c) 2020 Microsoft Corporation. All rights reserved.
    
    C:\Users\Matthew_Wai>PowerShell -ExecutionPolicy Bypass -file "E:\Folder\EmptyRecycleBin.ps1"
    
    Empty Recycle Bin
    About to empty recycle bin and delete recent files, do you want to proceed?
    [Y] Yes  [N] No  [?] Help (default is "N"):
      My Computer


  3. Posts : 841
    Windows 10 Pro 21H2
    Thread Starter
       #3

    Matthew Wai said:
    The following shortcut works at my end:

    PowerShell -ExecutionPolicy Bypass -file "E:\Folder\EmptyRecycleBin.ps1"

    Code:
    Microsoft Windows [Version 10.0.19042.746]
    (c) 2020 Microsoft Corporation. All rights reserved.
    
    C:\Users\Matthew_Wai>PowerShell -ExecutionPolicy Bypass -file "E:\Folder\EmptyRecycleBin.ps1"
    
    Empty Recycle Bin
    About to empty recycle bin and delete recent files, do you want to proceed?
    [Y] Yes  [N] No  [?] Help (default is "N"):
    Thanks Matthew Wai, that works
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 11:48.
Find Us




Windows 10 Forums