Created
July 25, 2014 20:10
-
-
Save mbrownnycnyc/1451e9ab378fd41ccc65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
http://techibee.com/tips/powershell-script-to-get-ilo-version-and-server-model-remotely/572 | |
Note: | |
If you're going to schedule this task to run, use the following action: | |
Program/script: powershell | |
add arguments: -command &{[path to find_pc_owner.ps1]} | |
Start in: [the working directory] | |
see: http://blogs.technet.com/b/heyscriptingguy/archive/2011/0/12/use-scheduled-tasks-to-run-powershell-commands-on-windows.aspx | |
#> | |
Function veryfastping { | |
[CmdletBinding()] | |
param( | |
[String]$computername = "127.0.0.1", | |
[int]$delay = 100 | |
) | |
$ping = new-object System.Net.NetworkInformation.Ping | |
$pingresult = $ping.send($computername,$delay).status | |
if ($pingresult -ne "Success") { | |
throw $false; | |
return $false; | |
} | |
else { | |
return $true; | |
} | |
} | |
$debug = $true | |
Function main { | |
param( | |
[string]$outputcsv = ".\out_ilo.csv", | |
[string]$referencecsv = ".\out_ilo.csv", | |
[string]$errorcsv = ".\out_iloerrors.csv", | |
[string]$inputlist = ".\list.txt" | |
) | |
if (test-path $errorcsv ) { | |
rm -force $errorcsv | |
} | |
cat $inputlist | foreach { | |
$targethost = $_ | |
#conditional, checking if $targethost is found in $referencecsv | |
#if ( -not ( get-content $referencecsv | select-string "$targethost$" ) ) { | |
if ( $debug ) { write-host "Checking if $targethost is up" } | |
try { | |
if ( veryfastping -ComputerName $targethost -delay 100 ) { | |
if ( $debug ) { write-host "attempting connection on tcp 80 to $targethost" } | |
$socket = new-object System.Net.Sockets.TcpClient($targethost, '80') -erroraction "stop" | |
try { | |
if ( $debug ) { write-host "attempting to get iLO XML from $targethost" -backgroundcolor "darkyellow" } | |
$doc = New-object System.XML.XMLDocument | |
$doc.Load(“http://$targethost/xmldata?item=All“) | |
$iloversion = $doc.RIMP.MP.PN | |
if ( $debug ) { write-host "iLO version: $iloversion" -backgroundcolor "darkgreen" } | |
} | |
catch { | |
$iloversion = "$targethost is not an iLO server, but is an HTTP server." | |
if ( $debug ) { write-host "$targethost is not an iLO server, but is an HTTP server." -backgroundcolor "red" } | |
} | |
$obj1 = new-object system.object | |
if ( $debug ) { "targethost = $targethost" } | |
$obj1 | Add-Member -MemberType NoteProperty -Name "date" -Value $(get-date -format "yyyy-MM-dd HH:mm:ss") | |
$obj2 = new-object system.object | |
$obj2 | Add-Member -MemberType NoteProperty -Name "targethost" -Value $targethost | |
$obj3 = new-object system.object | |
$obj3 | Add-Member -MemberType NoteProperty -Name "iloversion" -Value $iloversion | |
if ( $obj3.iloversion.length -gt 0 ) | |
{ | |
$Combined = New-Object -Type PSObject | |
$obj1,$obj2,$obj3|%{$CurObj = $_;$_|gm|?{$_.MemberType -match "NoteProperty"}|%{$NewMember = $_.Name;$Combined|Add-Member -MemberType NoteProperty -Name $NewMember -Value $CurObj.$NewMember}} | |
$Combined | export-csv -append -notypeinformation $outputcsv -encoding utf8 | |
$iloversion="" | |
} | |
else { | |
#we can connect, no iloversion | |
throw | |
} | |
} | |
} | |
catch { | |
#then we will not add to the CSV | |
$objectionunderruled = new-object system.object | |
$objectionunderruled | Add-Member -MemberType NoteProperty -Name "date" -Value $(get-date -format "yyyy-MM-dd HH:mm:ss") -ea 0 | |
$objectionunderruled | Add-Member -MemberType NoteProperty -Name "targethost" -Value "$targethost" -ea 0 | |
$objectionunderruled | Add-Member -MemberType NoteProperty -Name "iloversion" -Value "$iloversion is inaccessible" | |
$objectionunderruled | export-csv -append -notypeinformation $errorcsv -encoding utf8 | |
$iloversion = "" | |
} | |
#} | |
} | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment