# ショートカットのターゲットパス
$TargetPath = "%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
# ショートカットに渡す引数
$Arguments = '-WindowStyle Hidden -ExecutionPolicy Bypass -File ".\\App.ps1"'
# 作業フォルダ
$WorkingDir = "%FILEPATH%"
# ショートカットのアイコンパス
$IconPath = "%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
# ショートカットの説明
$Description = "Shortcut to run App.ps1 with PowerShell"
# ショートカットを作成するループ
foreach ($WindowStyle in 2) {
# ショートカットファイルのパス
$ShortcutPath = Join-Path -Path $PSScriptRoot -ChildPath "MyPowershellShortcut_$WindowStyle.lnk"
# WScript.Shellを使用してショートカットを作成
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($ShortcutPath)
# # ショートカットのプロパティを設定
$Shortcut.TargetPath = $TargetPath
$Shortcut.Arguments = $Arguments
$Shortcut.WorkingDirectory = $WorkingDir
$Shortcut.IconLocation = $IconPath
$Shortcut.Description = $Description
$Shortcut.WindowStyle = $WindowStyle #1:通常サイズ、2:最小化、3:最大化 ※2の場合だけ反映されないWindowsの仕様?
# ショートカットを保存
$Shortcut.Save()
# ショートカット作成メッセージを表示
Write-Host "ショートカットが作成されました: $ShortcutPath"
}
# 5行改行
Write-Host "$(1..5|%{"`n"})"
# 最小化の設定に関するメッセージを表示
Write-Host "【!】本スクリプト上で「実行時の大きさ」を「最小化」にしても正常に反映されないため、手動で設定をしてください。"
# スクリプトが終了しないように待機
Read-Host "Press Enter to exit..."