PowerShell Enter-PSSession ファイル実行

毎回パスワードを入力するのが面倒なので、ファイル実行にする。

前提条件

  • Windows 7 Professional
  • $PSVersionTable PSVersion=5.0.10586.117
  • 対象サーバの Windows リモート管理 (WinRM) 機能が有効
  • PowerShellを立ち上げて以下のファイルを実行する

remote.ps1

$user   = "{ユーザ名}"
$pass   = ConvertTo-SecureString "{パスワード}" -AsPlainText -Force
$remote = "{IPアドレス}"

$credential = New-Object System.Management.Automation.PSCredential $user, $pass
Enter-PSSession $remote -Credential $credential