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

Dell Command PowerShell Provider 安全密码功能

Summary: Dell Command | PowerShell Provider (DCPP) 安全密码功能, Dell Command | PowerShell Provider (DCPP) Secure Password feature, ConvertTo-SecureString, ConvertFrom-SecureString

This article applies to This article does not apply to This article is not tied to any specific product. Not all product versions are identified in this article.

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

Affected Products

Dell Command | Powershell Provider
Article Properties
Article Number: 000146459
Article Type: How To
Last Modified: 18 Jul 2024
Version:  8
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.