Windows 7やWindows Server 2008 R2から標準搭載されているPowerShell。
通常、WindowsでPowerShellを利用する場合は「Windows PowerShell」アプリを使用して実行しますが、最近コマンドプロンプトからでも実行できることを知りましたのでご紹介します!
コマンドプロンプトをPowerShellに切り替える
日々の業務であまりPowerShellを利用することがなかったので、偶然WindowsのコマンドプロンプトでPowerShellを実行する方法を発見したときは衝撃を受けました!

本当に現役SEなのか?w
既にご存知の方はこちらの記事をどうぞ!

それでは、Windowsのコマンドプロンプトを開いてください。
そこに[powershell]と入力するだけです!(ドヤッ)
1 2 3 4 5 6 7 |
C:\WINDOWS\System32>powershell Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. 新機能と改善のために最新の PowerShell をインストールしてください!https://aka.ms/PSWindows PS C:\WINDOWS\System32> |
コマンドプロンプトからPowerShellに切り替わったら、上記の最終行のように[PS~]が付きます。
PowerShellのコードでバージョン確認
試しに、そのままPowerShellのコードでバージョンを確認してみましょう!
PowerShellのバージョンを確認するには、[$PSVersionTable]を入力して実行するだけです。
1 2 3 4 5 6 7 8 9 10 11 12 |
PS C:\WINDOWS\System32> $PSVersionTable Name Value ---- ----- PSVersion 5.1.22000.xxxx PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.22000.xxx CLRVersion 4.0.30319.xxxxx WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 |
これで、Windowsのコマンドプロンプト上でPowerShellのバージョンが確認できました!
PowerShellからコマンドプロンプトに戻す
こちらも簡単!
[cmd]コードだけでPowerShellからコマンドプロンプトに戻ります!
1 2 3 4 5 |
PS C:\WINDOWS\System32> cmd Microsoft Windows [Version 10.0.22000.xxxx] (c) Microsoft Corporation. All rights reserved. C:\WINDOWS\System32> |
切り替わったら先程の[PS~]が消えて、通常のコマンドプロンプトに戻っていることがわかります。
【おまけ】切り替えずにPowerShellを実行する
WindowsのコマンドプロンプトからPowerShellを直接実行するには、[powershell]コマンドに[-Command]オプションを付けて実行します。
先程のバージョン確認を例に実行すると、このようになります。
1 2 3 4 5 6 7 8 9 10 11 12 |
C:\WINDOWS\System32>powershell -Command $PSVersionTable Name Value ---- ----- PSVersion 5.1.22000.xxx PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.22000.xxx CLRVersion 4.0.30319.xxxxx WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 |
実際にもっと複雑なコードを入力する場合は、途中にスペースがあったりするので、[-Command]オプションの後ろに入力するPowerShellのコードは[“”](ダブルクオーテーション)で囲んであげましょう!
1 |
> powershell -Command "ここにコードを入力" |
PowerShellについてもっと詳しく知りたい方はこちらもどうぞ!


コメント