2017-04-21 52 views
1

我試圖讓從引導順序列表使用以下命令的內容,但$pr是空的,沒有錯誤消息:使用,其中設備名稱-contains並沒有得到結果

$pr = Get-HPBIOSUEFIBootOrder $conObj | select -Expand UEFIBootOrder |select -Expand DeviceName| Where DeviceName -contains "*Target:0, Lun:0)"^ 

哪裏是我的錯?

當我運行此:

$pr = Get-HPBIOSUEFIBootOrder $conObj | select -Expand UEFIBootOrder |select -Expand DeviceName 

它返回:

Generic USB Boot 
Embedded LOM 1 Port 1 : HP Ethernet 1Gb 4-port 331i Adapter - NIC (PXE IPv6) 
Embedded LOM 1 Port 1 : HP Ethernet 1Gb 4-port 331i Adapter - NIC (PXE IPv4) 
Slot 3 Port 1 : HP Ethernet 10Gb 2-port 530T Adapter - NIC (PXE IPv6) 
Embedded RAID 1 : Smart Array P440ar Controller - 279.43 GiB, RAID 1 Logical Drive(Target:0, Lun:1) 
Windows Boot Manager 
Internal USB 1 : HPE Dual 8GB MicroSD EM USB Kit - USB RAID LUN 
Embedded RAID 1 : Smart Array P440ar Controller - 279.37 GiB, RAID 1 Logical Drive(Target:0, Lun:0) 
Embedded FlexibleLOM 1 Port 1 : HP FlexFabric 10Gb 2-port 533FLR-T Adapter - NIC (PXE IPv6) 
Embedded RAID 1 : Smart Array P440ar Controller - 279.37 GiB, RAID 1 Logical Drive(Target:0, Lun:2) 
Embedded FlexibleLOM 1 Port 1 : HP FlexFabric 10Gb 2-port 533FLR-T Adapter - NIC (PXE IPv4) 
Slot 3 Port 1 : HP Ethernet 10Gb 2-port 530T Adapter - NIC (PXE IPv4) 
+0

什麼'Get-HPBIOSUEFIBootOrder $ conObj |選擇-Expand UEFIBootOrder | select -Expand DeviceName' return? –

+0

我還假設'^'在行尾是一個錯字? –

回答

1

使用-like而不是-contains

如果要確定值是否在值集合中,應使用包含。當你想部分匹配一個字符串時,應該使用(使用通配符)。這是一種常見的PowerShell誤解。

您還在DeviceName上使用-ExpandProperty,之後有一個沒有該屬性名稱的字符串集合。因此,你需要做到這一點在你的Where

| Where {$_ -like "*Target:0, Lun:0)"} 

$_是一個特殊的佔位符,代表了管道,這與以System.String對象(默認),當前項目的字符串值。

+0

非常感謝,幫了我很多。 –

0

下面是我的小項目的更大圖片。 到目前爲止,我已達成目標。 它會在不久的將來找到更多的材料。

## 
# The following Script is checking the current HPPowerProfile Setting on the local Server 
# and set it to Maximum_Performance if its not already set. 
# 
# Also it set´s the UEFIBootOrder to HDD firts (Target:0, Lun:0) 
## 


# Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File C:\mysecurestring.txt 
# Set Access Credentials 

    $username = "*******" 
    $password = cat C:\mysecurestring.txt | Convertto-SecureString 
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $password 

# Set ILO Hostname 

    $sv = hostname 
    $ri = $sv.replace("YY","XX") 

# Connect to HPBios 

    $conObj = Connect-HPBIOS $ri -Credential $cred -DisableCertificateAuthentication 

# Check current BootMode (depending on Boot Mode, other cmdlet´s will be executed) 

    $bm = $conObj | Get-HPBIOSBootMode | select -Expand BootMode 
     if ($bm -eq "UEFI Mode") 
      {echo "UEFI"} 
     else 
      {echo "echo $bm"} 

# Check current Server Power Profile 

    $pr = Get-HPBIOSPowerProfile $conObj | select -Expand HPPowerProfile 
     if (-not($pr -eq "Maximum Performance")) 
      {$conObj | Set-HPBIOSPowerProfile -HPPowerProfile Maximum_Performance} 
     else 
      {echo "No change needed"} 

# Find HDD and move it to Boot Order #1 

    $bo = Get-HPBIOSUEFIBootOrder $conObj | select -Expand UEFIBootOrder | Where DeviceName -like "*Drive(Target:0, Lun:0)" | select -Expand Index 
     if (-not($bo -eq "1")) 
      {$conObj | Set-HPBIOSUEFIBootOrder -UEFIBootOrder "$bo,1"} 
     else 
      {echo "No change needed"} 
相關問題