Skip to main content
  • Place orders quickly and easily
  • View orders and track your shipping status
  • Create and access a list of your products
  • Manage your Dell EMC sites, products, and product-level contacts using Company Administration.

Dell Command PowerShell Provider 安全密碼功能

Summary: Dell Command |PowerShell Provider (DCPP) 安全密碼功能、ConvertTo-SecureString、ConvertFrom-SecureString

This article may have been automatically translated. If you have any feedback regarding its quality, please let us know using the form at the bottom of this page.

Article Content


Instructions

受影響的產品:

  • Dell Command | PowerShell Provider

安全密碼背後的概念是,在生產腳本中,我們不應將重要密碼作為純視圖傳遞。這是嚴重缺乏安全。因此,使用PowerShell,我們可以保護密碼或至少降低密碼可見性。我們先討論安全字串的一般層面,然後討論 Dell Command PowerShell Provider (DCPP) 如何運用 PowerShell 的固有功能來保護密碼。

假設我們要在主控台讀取使用者的使用者名和密碼。我們知道使用者名通常不需要任何安全性,並且所有人都可以看到。但是對於密碼,我們不應該讓陌生人知道用戶的密碼。我們可以使用以下命令來滿足此要求:

$user = Read-Host "Enter Username"

$pass = Read-Host "Enter Password" -AsSecureString

以上概述了當我們必須保護密碼等關鍵資訊時,我們如何添加更多安全性。在上面的範例中,變數$pass的類型為 System.Security.SecureString。在觸及 DCPP 的各個方面之前,我們會介紹 PowerShell 提供的另外兩個廣泛使用的 cmdlet,以促進安全欄位。

這兩個命令是 ConvertTo-SecureStringConvertFrom-SecureStringConvertTo-SecureString 將純文字轉換為文字 System.Security.SecureString。範例如以下所示:

"P@ssword1" | ConvertTo-SecureString -AsPlainText -Force

在上面的範例中,純文字 P@assword1 已轉換為類型 System.Security.SecureString。這更像是一種資訊,可能會也可能不會廣泛使用。

下一個 cmdlet ConvertFrom-SecureString 是一種使用更廣泛的 cmdlet,用於將安全字串轉換為加密的標準字串。主要限制 ConvertTo-SecureString 是它的輸出不能直接寫入檔以供將來使用。我們必須使用 ConvertFrom-SecureString 轉換 System.Security.SecureString 轉換為加密的標準字串,可以方便地保存到檔中,以克服此限制。

我們正在轉換純文字 P@ssword1 以保護字串,然後將其輸出管道傳輸到 ConvertFrom-SecureString 獲取可以安全方便地保存到檔中的加密字串。

例如,假設在計算機上設置了管理員密碼,我們必須將其保存到檔中。我們可以使用:

Read-Host "Enter Admin Password" -AsSecureString |
ConvertFrom-SecureString | Out-File "C:\Scripts\AdminPassword.txt"

我們可以將此管理員密碼作為安全物件檢索回變數中,如下所示:

$pass = Get-Content "C:\Scripts\AdminPassword.txt" | ConvertTo-SecureString

現在考慮如何使用 DCPP 的安全密碼。在 DCPP 中,如果使用者的電腦設定了系統或管理員密碼,則所有 set 命令我們必須傳遞相應的密碼。因此,以純文本形式提供此密碼會違反安全性。我們必須將密碼傳遞為 System.Security.SecureString。此外,當我們通過 SecureString 密碼我們必須用 -PasswordSecure 開關而不是正常 –Password 開關。下面顯示了使用者嘗試設置的範例 AdvancedBatteryChargeCfg 變更為 Disabled 和傳遞 SecureString 密碼:

Set-item AdvancedBatteryChargeCfg disabled –PasswordSecure $pass

此處$pass存有系統密碼和管理員密碼,並且屬於 System.Security.SecureString。與上面的討論類似,我們可以閱讀 $pass 如:

$pass = Read-Host "Enter system/admin password" –AsSecureString

我們可以省 $pass 如果需要,到檔案中,作為:

$pass| ConvertFrom-SecureString | Out-File "C:\Scripts\AdminPassword.txt

Additional Information

Article Properties


Affected Product

Dell Command | Powershell Provider

Last Published Date

18 Jul 2024

Version

8

Article Type

How To