0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PowerShellを実行してみる

Posted at

はじめに

こちらの続きで書いていきます。

実行ファイルを作る

/usr/local/src/pwsh/ディレクトリに、test.ps1というファイルを作ってみます。
PowerShellの実行ファイルは、.ps1という拡張子になります。

とりあえず、HelloWorldを出力するだけの内容にしています。

/usr/local/src/pwsh/test.ps1
echo "Hello World"

実行ファイルを実行する

PowerShellのコンソールから実行する方法と、PowerShellコンソールを開かずに実行する方法があります。

PowerShellのコンソールから実行

ファイル名を指定するだけで実行されます。

PS /usr/local/src/pwsh> cd /usr/local/src/pwsh/
PS /usr/local/src/pwsh> ./test.ps1
Hello World

実行すると、コンソールにHello Worldが表示されました。

PowerShellコンソールを開かずに実行

pwshをつけてファイル名を実行することで実行できます。

# cd /usr/local/src/pwsh
# pwsh test.ps1
Hello World

PowerCLIを実行する

こちらの記事で使ったコードを参考に、PowerCLIを実行してみます。

/usr/local/src/pwsh/test.ps1
Connect-VIServer -Server {IPアドレス} -User root -Password {パスワード} -force
Get-VM
Disconnect-VIServer -Server {IPアドレス} -Confirm:$False

結果は割愛しますが、ちゃんと表示されました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?