はじめに
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