メモ
- ExecutionPolicy を RemoteSigned として PowerShell_ISE.exe を起動するだけのショートカットを作成するVBAとPowerShellスクリプト
- PowerShell_ISE.exe のパラメーターは気にしない
参考資料リンク
使い捨てスクリプト
使い捨てExcelマクロ
' Excel 2019, Windows 10 ' 参照設定 ' IWshRuntimeLibrary ' Windows Script Host Object Model ' "C:\Windows\System32\wshom.ocx" Option Explicit Public Sub Main() Dim wsh As IWshRuntimeLibrary.WshShell Dim lnk As IWshRuntimeLibrary.WshShortcut Dim path As String Set wsh = New IWshRuntimeLibrary.WshShell path = VBA.Interaction.Environ("USERPROFILE") & "\Desktop\PowerShell ISE (RemoteSigned).lnk" Set lnk = wsh.CreateShortcut(path) lnk.TargetPath = "PowerShell.exe" lnk.Arguments = "-ExecutionPolicy RemoteSigned -Command ""&{PowerShell_ISE.exe}#""" lnk.WorkingDirectory = "" lnk.Description = "PowerShell ISE (RemoteSigned)" lnk.Save Set lnk = Nothing Set wsh = Nothing End Sub
使い捨てPowerShellスクリプト
- エラー処理やCOMオブジェクトの解放を気にしてないので練習以外での実行は危険
# PowerShell 5.1, Windows 10 Set-StrictMode -Version Latest $wsh = New-Object -ComObject 'WScript.Shell' $path = "${env:USERPROFILE}\Desktop\PowerShell ISE (RemoteSigned).lnk" $lnk = $wsh.CreateShortcut($path) $lnk.TargetPath = 'PowerShell.exe' $lnk.Arguments = '-ExecutionPolicy RemoteSigned -Command "&{PowerShell_ISE.exe}#"' $lnk.WorkingDirectory = '' $lnk.Description = 'PowerShell ISE (RemoteSigned)' $lnk.Save() $lnk = $null $wsh = $null