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

Dell Command PowerShell 提供者安全密碼功能

Summary: Dell Command |PowerShell 提供者安全密碼功能,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


Symptoms

受影響的產品:

  • Dell Command | PowerShell Provider

Cause

不適用

Resolution

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

請考慮我們要從主控台的使用者讀取使用者名稱和密碼。我們瞭解使用者名稱通常不需要任何安全性,而且可以在所有使用者中顯示。但對於密碼,我們不應讓管理員知道使用者的密碼。我們可以使用以下命令來促進此需求:

$user = Read-Host "Enter Username"

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

以上概觀說明當我們必須保護密碼等重要資訊時,如何增加安全性。在上述範例中,變數$pass為類型 System.Security.SecureString 。我們介紹另外兩個廣泛使用的 Cmdlet PowerShell,可在觸及 DCPP 的各個層面之前,協助進行安全欄位。

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

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

在上述範例中,純文字 P@assword1 會轉換為類型 System.Security.SecureString 。這更多的是資訊,不一定會廣泛使用。

下一個 Cmdlet ConvertFrom-SecureString 是更廣泛使用的 Cmdlet,用來將安全字串轉換為加密的標準字串。主要限制 ConvertTo-SecureString 是其輸出無法直接寫入檔案以供日後使用。我們必須使用可 System.Security.SecureString 輕鬆儲存至檔案的加密標準字串來解決 ConvertFrom-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 交換器) 加以傳遞。以下範例顯示使用者嘗試設定 AdvancedBatteryChargeCfgDisabled 密碼及傳遞 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

11 Sep 2023

Version

7

Article Type

Solution