[CmdletBinding()]਀瀀愀爀愀洀⠀ [switch]$Execute,਀嬀倀愀爀愀洀攀琀攀爀⠀䴀愀渀搀愀琀漀爀礀㴀␀吀爀甀攀Ⰰ倀漀猀椀琀椀漀渀㴀 ⤀崀 #[string]$HostToEnclosureBayMap,਀⌀嬀倀愀爀愀洀攀琀攀爀⠀䴀愀渀搀愀琀漀爀礀㴀␀吀爀甀攀Ⰰ倀漀猀椀琀椀漀渀㴀㄀⤀崀 #[string]$EnclosureCredentials,਀⌀嬀倀愀爀愀洀攀琀攀爀⠀䴀愀渀搀愀琀漀爀礀㴀␀吀爀甀攀Ⰰ倀漀猀椀琀椀漀渀㴀㈀⤀崀 [string]$HostList਀⤀ ਀ function Reset-OABlade਀笀 param([string]$ilo_address, [string]$slot_number, [string]$userid, [string]$passwd, [String]$ServerName)਀ऀ $ping=Test-Connection -ComputerName $ServerName -Quiet -Count 2਀椀昀 ⠀␀瀀椀渀最 ⴀ攀焀 ∀吀爀甀攀∀⤀ 笀 ਀ऀ圀爀椀琀攀ⴀ䠀漀猀琀 ∀␀匀攀爀瘀攀爀一愀洀攀 椀猀 爀攀愀挀栀愀戀氀攀Ⰰ 瀀漀眀攀爀 漀昀昀 䔀匀堀 愀渀搀 琀爀礀 愀最愀椀渀∀ }਀攀氀猀攀 笀 #WRITE-HOST "SHUTTING DOWN SERVER" #Added by Rahamath਀    ⌀匀琀漀瀀ⴀ䌀漀洀瀀甀琀攀爀 ⴀ䌀漀洀瀀甀琀攀爀一愀洀攀 ␀匀攀爀瘀攀爀一愀洀攀 ⌀䄀搀搀攀搀 戀礀 刀愀栀愀洀愀琀栀 #do {$ping=Test-Connection -ComputerName $ServerName -Quiet} until (!$ping)਀ऀ⌀圀刀䤀吀䔀ⴀ䠀伀匀吀 ␀匀䔀刀嘀䔀刀一䄀䴀䔀 ∀䐀伀䔀匀一伀吀 刀䔀匀倀伀一䐀 吀伀 倀䤀一䜀Ⰰ 圀䄀䤀吀䤀一䜀 ㄀  匀䔀䌀伀一䐀匀 䈀䔀䘀伀刀䔀 倀刀伀䌀䔀䔀䐀䤀一䜀 吀伀 刀䔀匀䔀吀∀ #Start-Sleep -Seconds 10਀   ऀ␀爀甀渀 㴀 ㄀ $command_issue = "no"਀ऀ␀礀攀猀开椀猀猀甀攀 㴀 ∀渀漀∀ $port = 23਀ write-host "Connecting to $ilo_address on port $port"਀    ␀猀漀挀欀攀琀 㴀 渀攀眀ⴀ漀戀樀攀挀琀 匀礀猀琀攀洀⸀一攀琀⸀匀漀挀欀攀琀猀⸀吀挀瀀䌀氀椀攀渀琀⠀␀椀氀漀开愀搀搀爀攀猀猀Ⰰ ␀瀀漀爀琀⤀  if($socket -eq $null) { return; } ਀  $stream = $socket.GetStream() ਀    ␀眀爀椀琀攀爀 㴀 渀攀眀ⴀ漀戀樀攀挀琀 匀礀猀琀攀洀⸀䤀伀⸀匀琀爀攀愀洀圀爀椀琀攀爀⠀␀猀琀爀攀愀洀⤀  ਀    ␀戀甀昀昀攀爀 㴀 渀攀眀ⴀ漀戀樀攀挀琀 匀礀猀琀攀洀⸀䈀礀琀攀嬀崀 ㄀ ㈀㐀  $encoding = new-object System.Text.AsciiEncoding ਀  ਀    眀栀椀氀攀⠀␀爀甀渀 ⴀ攀焀 ㄀⤀  { ਀       猀琀愀爀琀ⴀ猀氀攀攀瀀 ⴀ洀 㔀    ਀ऀऀ⌀圀爀椀琀攀ⴀ䠀漀猀琀 ∀刀䔀匀倀伀一匀䔀开匀吀䄀刀吀ⴀⴀⴀ ∀ ⬀ ␀琀渀开氀椀渀攀 ⬀ ∀ ⴀⴀⴀ刀䔀匀倀伀一匀䔀开䔀一䐀∀ऀ    ਀       眀栀椀氀攀⠀␀猀琀爀攀愀洀⸀䐀愀琀愀䄀瘀愀椀氀愀戀氀攀⤀   { ਀          ␀爀攀愀搀 㴀 ␀猀琀爀攀愀洀⸀刀攀愀搀⠀␀戀甀昀昀攀爀Ⰰ  Ⰰ ㄀ ㈀㐀⤀ write-host -n ($encoding.GetString($buffer, 0, $read)) ਀  [string] $tn_line = ($encoding.GetString($buffer, 0, $read))਀ऀऀ    ਀ऀऀ   椀昀 ⠀␀琀渀开氀椀渀攀⸀挀漀渀琀愀椀渀猀⠀∀䰀漀最椀渀 一愀洀攀㨀∀⤀⤀ {਀ऀऀ   ऀऀ圀爀椀琀攀ⴀ䠀漀猀琀 ∀䘀伀唀一䐀开开䰀伀伀䬀䤀一䜀开䘀伀刀开䤀䐀∀ $writer.WriteLine($userid) ਀       ऀऀऀ␀眀爀椀琀攀爀⸀䘀氀甀猀栀⠀⤀  }਀ if ($tn_line.contains("login:"))਀ऀऀ   笀 Write-Host "FOUND__LOOKING_FOR_ID"਀ऀऀऀऀ␀眀爀椀琀攀爀⸀圀爀椀琀攀䰀椀渀攀⠀␀甀猀攀爀椀搀⤀  $writer.Flush() ਀ऀऀऀ紀ऀऀऀ ਀ऀऀ   椀昀 ⠀␀琀渀开氀椀渀攀⸀挀漀渀琀愀椀渀猀⠀∀倀愀猀猀眀漀爀搀㨀∀⤀⤀ {਀ऀऀ   ऀऀ圀爀椀琀攀ⴀ䠀漀猀琀 ∀䘀伀唀一䐀开开䰀伀伀䬀䤀一䜀开䘀伀刀开倀䄀匀匀圀伀刀䐀∀ $writer.WriteLine($passwd) ਀       ऀऀऀ␀眀爀椀琀攀爀⸀䘀氀甀猀栀⠀⤀  }਀ऀऀ    ਀ऀऀ椀昀 ⠀␀琀渀开氀椀渀攀⸀挀漀渀琀愀椀渀猀⠀∀䠀倀 䈀氀愀搀攀匀礀猀琀攀洀 伀渀戀漀愀爀搀 䄀搀洀椀渀椀猀琀爀愀琀漀爀∀⤀⤀ {਀ऀऀऀ圀爀椀琀攀ⴀ䠀漀猀琀 ∀䘀伀唀一䐀开开䰀伀伀䬀匀开䰀伀䜀䜀䔀䐀开䤀一∀ if ($command_issue = "no")਀ऀऀऀऀ笀 # $writer.WriteLine("poweroff server " + $slot_number) #Added by Rahamath਀⌀ऀऀऀऀ␀眀爀椀琀攀爀⸀䘀氀甀猀栀⠀⤀ ⌀䄀搀搀攀搀 戀礀 刀愀栀愀洀愀琀栀 # start-sleep -m 1000਀ऀऀऀऀ␀眀爀椀琀攀爀⸀圀爀椀琀攀䰀椀渀攀⠀∀爀攀猀攀琀 猀攀爀瘀攀爀 ∀ ⬀ ␀猀氀漀琀开渀甀洀戀攀爀⤀ $writer.Flush()਀ऀऀऀऀ␀挀漀洀洀愀渀搀开椀猀猀甀攀 㴀 ∀礀攀猀∀ }਀ऀऀ紀 ਀    if ($tn_line.contains("Entering anything other than"))਀ऀऀ笀 Write-Host "FOUND__NEED_TO_SAY_YES"਀ऀऀऀऀ椀昀 ⠀␀礀攀猀开椀猀猀甀攀 㴀 ∀渀漀∀⤀ {਀ऀऀऀऀ猀琀愀爀琀ⴀ猀氀攀攀瀀 ⴀ洀 ㄀    $writer.WriteLine("YES")਀       ऀऀऀ␀眀爀椀琀攀爀⸀䘀氀甀猀栀⠀⤀ $yes_issue = "yes"਀ऀऀऀऀ紀 }਀ ਀ऀऀ椀昀 ⠀␀琀渀开氀椀渀攀⸀挀漀渀琀愀椀渀猀⠀∀䰀漀最椀渀 椀渀挀漀爀爀攀挀琀∀⤀⤀ {਀ऀऀऀ圀爀椀琀攀ⴀ䠀漀猀琀 ∀䘀伀唀一䐀开开䰀伀䜀䤀一开䠀䄀匀开䘀䄀䤀䰀䔀䐀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀∀ $result_data.WriteLine($ilo_address + "|" + $slot_number + "|" + "FOUND__LOGIN_HAS_FAILED!!!")਀ऀऀऀ␀眀爀椀琀攀爀⸀䘀氀甀猀栀⠀⤀ $run = 2਀ऀऀ紀ऀऀऀ ਀ऀऀऀ    if ($tn_line.contains("Invalid Arguments"))਀ऀऀ笀 Write-Host "FOUND__COMMAND_PROBLEM!!!!!!!!!!!!!!!!!!!!!!!!"਀ऀऀऀ␀眀爀椀琀攀爀⸀䘀氀甀猀栀⠀⤀ $result_data.WriteLine($ilo_address + "|" + $slot_number + "|" + "FOUND__COMMAND_PROBLEM!!!")਀ऀऀऀ␀爀甀渀 㴀 ㈀ } ਀   ਀ऀऀ椀昀 ⠀␀琀渀开氀椀渀攀⸀挀漀渀琀愀椀渀猀⠀∀匀甀挀挀攀猀猀昀甀氀氀礀 爀攀猀攀琀∀⤀⤀ {਀ऀऀऀ圀爀椀琀攀ⴀ䠀漀猀琀 ∀䘀伀唀一䐀开开刀䔀匀䔀吀开匀唀䌀䌀䔀匀匀䘀唀䰀∀ $writer.WriteLine("exit")਀ऀऀऀ␀眀爀椀琀攀爀⸀䘀氀甀猀栀⠀⤀ $result_data.WriteLine($ilo_address + "|" + $slot_number + "|" + "FOUND__RESET_SUCCESSFUL")਀             start-sleep -m 10000਀ऀऀऀ␀眀爀椀琀攀爀⸀圀爀椀琀攀䰀椀渀攀⠀∀瀀漀眀攀爀漀渀 猀攀爀瘀攀爀 ∀ ⬀ ␀猀氀漀琀开渀甀洀戀攀爀⤀ $writer.Flush()਀ ਀ऀऀऀ␀爀甀渀 㴀 ㈀ } ਀ऀऀ ਀ऀऀ椀昀 ⠀␀琀渀开氀椀渀攀⸀挀漀渀琀愀椀渀猀⠀∀䌀漀渀渀攀挀琀椀漀渀 琀漀 栀漀猀琀 氀漀猀琀∀⤀⤀ {਀ऀऀऀ圀爀椀琀攀ⴀ䠀漀猀琀 ∀䘀伀唀一䐀开开䌀伀一一䔀䌀吀䤀伀一开䰀伀匀吀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀℀∀ $writer.Flush()਀ऀऀऀ␀爀攀猀甀氀琀开搀愀琀愀⸀圀爀椀琀攀䰀椀渀攀⠀␀椀氀漀开愀搀搀爀攀猀猀 ⬀ ∀簀∀ ⬀ ␀猀氀漀琀开渀甀洀戀攀爀 ⬀ ∀簀∀ ⬀ ∀䘀伀唀一䐀开开䌀伀一一䔀䌀吀䤀伀一开䰀伀匀吀℀℀℀∀⤀ $run = 2਀ऀऀ紀ऀऀऀऀ ਀ऀ    }਀ऀ   ऀ␀眀爀椀琀攀爀⸀䌀氀漀猀攀⠀⤀  $stream.Close()਀    紀  ਀紀 #finally਀⌀笀 # $writer.Close() ਀⌀    ␀猀琀爀攀愀洀⸀䌀氀漀猀攀⠀⤀ #}਀紀 ਀ ਀⌀␀愀䠀漀猀琀吀漀䔀渀挀氀吀漀䈀愀礀 㴀 䤀洀瀀漀爀琀ⴀ䌀猀瘀 ␀䠀漀猀琀吀漀䔀渀挀氀漀猀甀爀攀䈀愀礀䴀愀瀀 #$aEnclCreds = Import-Csv $EnclosureCredentials਀⌀␀愀䠀漀猀琀猀吀漀刀攀猀攀琀 㴀 䤀洀瀀漀爀琀ⴀ䌀猀瘀 ␀䠀漀猀琀䰀椀猀琀 $aHostsToReset = Import-Csv $HostList਀ ਀昀漀爀攀愀挀栀⠀␀猀䠀漀猀琀吀漀刀攀猀攀琀 椀渀 ␀愀䠀漀猀琀猀吀漀刀攀猀攀琀⤀笀ऀ Write-Host "Actioning $($sHostToReset.ESXHostname) : $($sHostToReset.OAIP) : Bay $($sHostToReset.Bay) ..."਀    ⌀␀漀戀樀䴀愀瀀 㴀 ␀愀䠀漀猀琀吀漀䔀渀挀氀吀漀䈀愀礀 簀 圀栀攀爀攀ⴀ伀戀樀攀挀琀 笀␀开⸀䠀漀猀琀 ⴀ攀焀 ␀猀䠀漀猀琀吀漀刀攀猀攀琀⸀一愀洀攀紀 # $objCred = $aEnclCreds | Where-Object {$_.Name -eq $objMap.EnclosureName}਀⌀    椀昀 ⠀␀漀戀樀䴀愀瀀 ⴀ攀焀 ␀渀甀氀氀 ⴀ漀爀 ␀漀戀樀䌀爀攀搀 ⴀ攀焀 ␀渀甀氀氀⤀ 笀 # Write-Host "No mapping or OA credtials found for the specified host/enclosure"਀⌀    紀 # else {਀ऀ    椀昀 ⠀␀䔀砀攀挀甀琀攀⸀䤀猀倀爀攀猀攀渀琀⤀ 笀 Reset-OABlade -ilo_address $($sHostToReset.OAIP) -slot_number $($sHostToReset.Bay) -userid $($sHostToReset.Username) -passwd $($sHostToReset.Password) -Server $($sHostToReset.ESXHostname)਀         紀 else {਀            圀爀椀琀攀ⴀ䠀漀猀琀 ∀吀䔀匀吀 ⠀渀漀 攀砀攀挀甀琀攀⤀ 㨀 刀攀猀攀琀ⴀ伀䄀䈀氀愀搀攀 ⴀ椀氀漀开愀搀搀爀攀猀猀 ␀⠀␀猀䠀漀猀琀吀漀刀攀猀攀琀⸀伀䄀䤀倀⤀ ⴀ猀氀漀琀开渀甀洀戀攀爀 ␀⠀␀猀䠀漀猀琀吀漀刀攀猀攀琀⸀䈀愀礀⤀ ⴀ甀猀攀爀椀搀 ␀⠀␀猀䠀漀猀琀吀漀刀攀猀攀琀⸀唀猀攀爀渀愀洀攀⤀ ⴀ瀀愀猀猀眀搀 ␀⠀␀猀䠀漀猀琀吀漀刀攀猀攀琀⸀倀愀猀猀眀漀爀搀⤀ ⴀ匀攀爀瘀攀爀 ␀⠀␀猀䠀漀猀琀吀漀刀攀猀攀琀⸀䔀匀堀䠀漀猀琀渀愀洀攀⤀∀ }਀    ⌀紀 ਀紀