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 Provider 安全密码功能

Summary: Dell Command |PowerShell Provider 安全密码功能、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 是,其输出不能直接写入文件以供将来使用。我们必须使用 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 交换机。下面显示了一个示例,其中用户尝试设置 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