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?

PowerShell(Posh-SSH)でFortigateをシャットダウンする

Last updated at Posted at 2025-02-16

はじめに

xxDの頃に、急に落ちちゃってDisk故障して泣いて。
xxE,Fになれば、そんなこともまぁなくなって。でも不安で。
だから、UPS連動の際に安全にFortigateも停止させようって言う話。でもWindowsしかないんだ!

前準備

PowerShellのModuleで以下を追加しておく。

PowerShell
Install-Module -Name Posh-SSH -Verbose

本題のスクリプト

私はせっかちなんだ。

PowerShell
#run 1st : Install-Module -Name Posh-SSH -Verbose
Import-Module -Name Posh-SSH -Verbose
$connect  = "192.168.11.21"
$username = "admin"
$password = ConvertTo-SecureString -String "sugoipassword" -AsPlainText -Force -Verbose

$credential = New-Object System.Management.Automation.PSCredential($username, $password) -Verbose

$sshSession = New-SSHSession -ComputerName $connect -Credential $credential -AcceptKey -Verbose
$stream = New-SSHShellStream -Session $sshSession -Verbose

# This Command Shutdown !!
#Invoke-SSHStreamExpectAction -ShellStream $stream -Command "execute shutdown comment volt_stop_autoshut" -ExpectString 'Do you want to continue? (y/n)' -Action "y" -Timeout 3 -Verbose
# 動作させるときは上の行のコメントアウトを削除すること。

# #not running!!!…対話型の場合、上手く動かない。y/nがある奴。
#$session = Get-SSHSession -SessionId 0
#Invoke-SSHCommand -Command "execute shutdown comment volt_stop_autoshut" -SessionId 0
#timeout 3
#Invoke-SSHCommand -Command "y" -SessionId 0
# #not running!!!
  • -AcceptKeyは、フィンガープリントがいちいち出てこない。

あとがき

こういうのもあるらしい。

PowerShell
Install-Module -Name PowerFGT
Import-Module -Name PowerFGT
$fgtIP    = "192.168.11.21"
$username = "admin"
$password = ConvertTo-SecureString "totemosugoipassword" -AsPlainText -Force
Connect-FGT -Server $fgtIP -Username $username -Password $password -SkipCertificateCheck
#Get-FGTFirewallAddress
#Get-Command -Module PowerFGT
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?