码迷,mamicode.com
首页 > 系统相关 > 详细

PowerShell代码再次测试

时间:2016-08-09 00:26:54      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:

放一段PowerShell代码
 
技术分享
 1 #Requires -Version 3.0 -Modules @{ModuleName=‘HPiLOCmdlets‘;ModuleVersion=‘1.2.0.0‘}
 2 # =============================================================================================
 3 # Example script for reading HPiLO settings.
 4 # Only iLO 3 and higher is supported.
 5 
 6 # AUTHOR        thomas.franke@sepago.de / sepago GmbH
 7 # German Blog    http://www.powercli.de
 8 # English Blog    http://www.thomas-franke.net
 9 # LASTEDIT        15.10.2015
10 # =============================================================================================
11 Set-StrictMode -Version Latest
12 Clear-Host
13 
14 Push-Location $(Split-Path $Script:MyInvocation.MyCommand.Path)
15 
16 . .\include\Get-PSCredential.ps1
17 
18 # Create/read user credentials from file
19 $UserName        = "<UserName>"
20 $PSCredential    = Get-PSCredential $UserName
21 
22 # A higher timeout improves the detection rate if iLO is connected will less than 1 GBit/s. 
23 # Default is 300 milliseconds
24 #
25 $TimeOut        = 1000
26 
27 # The IPRange is read from a file which must contain a single IP address per row. 
28 # You can use Discover-HPiLO.ps1 to generate the file or create it manually. 
29 #
30 $InputFileName    = "Discovered-HPiLOs.txt"
31 $IPRange        = Get-Content $InputFileName
32 
33 Write-Output "Discovering iLO boards...`n"
34 ForEach($IPAddress in $IPRange)
35 {
36     $IsOnline = Find-HPiLO $IPAddress -Timeout $TimeOut
37     If ($IsOnline)
38     {
39         $Output = "[online] $IPAddress`t" + $IsOnline.Hostname
40         $ForegroundColor = "Green"
41         Write-Host $Output -ForegroundColor $ForegroundColor
42 
43         If (($IsOnline.PN -eq "Integrated Lights-Out 4 (iLO 4)") -Or ($IsOnline.PN -eq "Integrated Lights-Out 3 (iLO 3)"))
44         {
45             $Output = "`n[$($IsOnline.PN)] detected`n"
46             $ForegroundColor = "Green"
47             Write-Host $Output -ForegroundColor $ForegroundColor
48             
49             Write-Output "Reading data from iLO $($IsOnline.HostName) [$($IsOnline.IP)]`n"
50             
51             # Change the following HPiLO cmdlet to read other data from the iLO board
52             # Modify or delete the Select-statement to get more properties
53             $HPiLOData    = Get-HPiLOSNMPIMSetting -Server $IPAddress -Credential $PSCredential | Select-Object -Property IP,HOSTNAME,STATUS_MESSAGE,SNMP_ADDRESS_1
54             Write-Output $HPiLOData "`n"
55         }
56         Else
57         {
58             $Output = "`n[$($IsOnline.PN)] detected, which is not supported!`n"
59             $ForegroundColor = "Red"
60             Write-Host $Output -ForegroundColor $ForegroundColor
61         }
62     }
63     Else
64     {
65         $Output = "[offline] $IPAddress`n"
66         $ForegroundColor = "Red"
67         Write-Host $Output -ForegroundColor $ForegroundColor
68     }
69     
70     Write-Output "---`n"
71 }
72 
73 Pop-Location
View Code

 

PowerShell代码再次测试

标签:

原文地址:http://www.cnblogs.com/hinkerliu/p/5751392.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!