Windows11のPowerShellスクリプトでVPNサーバーに接続する

・VPNサーバーに接続できるよう事前に設定
・接続名は「会社」とする

下記のように設定ファイルを編集して確認を表示せずに接続するよう変更。

…
PreviewUserPw=0
…

PowerShellスクリプトを適当な名前で作成する。

$connectionName = "会社"
$result = ipconfig | Select-String $connectionName
if ($result -like "*" + $connectionName + "*") {
    echo "ok"
} else {
    rasphone -d $connectionName
}

下記のような感じで実行する。

powershell -ExecutionPolicy RemoteSigned -File connect-vpn.ps1