Import-Module SshShell
$elevatedPrompt = "#.$"
$configPrompt = "(config)#.$"
$objectPrompt = "object)#.$"
$s = New-SshSession -SshHost $asaIP -User $user -Password $password
Send-SshCommand $s "enable" -Expect "Password:"
Send-SshCommand $s "$elevatedPassword" -Expect $elevatedPrompt
Send-SshCommand $s "show run object id $objectId" -Expect $elevatedPrompt
if ($s.LastResult -match "does not exist") {
Send-SshCommand $s "conf t" -Expect $configPrompt
Send-SshCommand $s "object network $objectId" -Expect $objectPrompt
Send-SshCommand $s "description $description" -Expect $objectPrompt
Send-SshCommand $s "host $hostIP" -Expect $objectPrompt
Send-SshCommand $s "end" -Expect $elevatedPrompt
Send-SshCommand $s "write mem" -Expect "[OK]" -WaitUnlimitedOn "configuration...|Cryptochecksum|copied"
}
Close-SshSession $s
Comments