このドキュメントでは、PowerShell を使用して Windows 仮想マシン(VM)インスタンスに接続する方法について説明します。
始める前に
-
まだ設定していない場合は、認証を設定します。認証とは、 Trusted Cloud by S3NS サービスと API にアクセスするために ID を確認するプロセスです。ローカル開発環境からコードまたはサンプルを実行するには、次のいずれかのオプションを選択して Compute Engine に対する認証を行います。
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, configure the gcloud CLI to use your federated identity and then initialize it by running the following command:
gcloud init
- Set a default region and zone.
リモート Windows インスタンスのユーザー名とパスワードを作成していない場合には、Windows パスワードを作成またはリセットします。
ファイアウォール ルールを追加し、Windows Server インスタンスが存在する Trusted Cloud VPC ネットワーク上のポート
5986
を開くようにこのルールを設定します。ローカル ワークステーションで、PowerShell ターミナルを開きます。
省略可: ユーザー認証情報を格納する変数を初期化できます。初期化すると、インスタンスに接続するたびに、認証情報を入力する必要がなくなります。この手順をスキップすると、ユーザー名とパスワードを要求するプロンプトが後で表示されます。
$credentials = Get-Credential
双方向の PowerShell セッションを確立するか、Windows Server VM 上でリモートでコマンドを呼び出すかを選択します。
IP_ADDRESS
: 接続するインスタンスの IP アドレス、DNS 名、または Windows コンピュータ名。SCRIPT
: リモート インスタンスで実行する 1 つ以上のコマンド。たとえば、ログイベントのリストを表示するには、Get-EventLog -log "Windows PowerShell"
を指定します。- プロジェクトまたは組織の複数ユーザーのインスタンスへのアクセスを管理する方法を学習する。
- VM インスタンスに安全に接続する。
- Linux インスタンスにファイルを転送する。
PowerShell を使用した接続
Windows ワークステーションに PowerShell がインストールされている場合には、リモート PowerShell セッションから Windows Server インスタンスに接続できます。
双方向の PowerShell セッションの確立
PowerShell セッションを確立するには、次のコマンドを実行します。
Enter-PSSession -ComputerName IP_ADDRESS -UseSSL -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck) -Credential $credentials
IP_ADDRESS
は、接続するインスタンスの外部 IP アドレス、DNS 名、または Windows コンピュータ名に置き換えます。接続後、コマンド プロンプトが変更され、リモート Windows インスタンスの IP アドレスが含まれるようになります。これで、ターミナルからリモートの Windows Server インスタンスで PowerShell コマンドを実行できます。
Windows Server VM 上のコマンドをリモートで呼び出す
Enter-PSSession
コマンドの代わりに、-ScriptBlock
フラグを指定してInvoke-Command
を実行すると、インタラクティブ セッションを確立せずにリモート インスタンスで PowerShell コマンドを実行できます。Invoke-Command -ComputerName IP_ADDRESS -ScriptBlock { SCRIPT } -UseSSL -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck) -Credential $credentials
次のように置き換えます。
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-03 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-03 UTC。"],[[["This document guides you through connecting to a Windows virtual machine (VM) instance using PowerShell, enabling remote management and command execution."],["Before connecting, ensure you have set up authentication via the Google Cloud CLI or are using the Google Cloud console, and have created or reset your Windows password on the remote instance."],["Connecting to a Windows Server instance requires opening port 5986 in your Google Cloud VPC network's firewall rules, in order to accept remote PowerShell connections."],["You can establish either an interactive PowerShell session using `Enter-PSSession` or remotely invoke commands on the VM without an interactive session by using the `Invoke-Command` method."],["When a user connects to a VM, they can utilize all IAM permissions granted to the service account attached to that specific VM."]]],[]] -