【问题标题】:Secure and encrypt usernamae/password in PowerShell在 PowerShell 中保护和加密用户名/密码
【发布时间】:2019-09-16 15:06:01
【问题描述】:

尝试在 PowerShell 中保护/加密密码。

现在我有一个脚本,它通过多个服务器并调用 SQL 命令。

我曾经对密码和用户名进行硬编码,出于安全考虑,我想对其进行加密。

  $query = @'
 SELECT TOP 10 FROM [dbo].[TABLE]
   '@

 $SERVERS = LIST OF SERVERS

(Get-Credential).Password | ConvertFrom-SecureString | Set-Content "C:\ Password.txt"

$passWord1 = Get-Content "C:\ Password.txt" | ConvertTo-SecureString 
$credential = New-Object System.Management.Automation.PsCredential ('username',$passWord1)

$SQLCredentials = @{
    server = $server
    database = 'databasename'
    Query= $query
    Credential = $credential
}

 $Results  = Invoke-SqlCmd @SQLCredentials 
 $Results | Select-Object -Property * -Skip 1 

我也尝试了以下方法,但似乎不起作用 Invoke SQL Command with Secure Creds

error: Invoke-Sqlcmd : A parameter cannot be found that matches parameter name 'Credential'.

目标是使用安全的用户名和密码运行Invoke-SqlCmd。

【问题讨论】:

  • 尝试Credential = $credential 而不是Username = 'username'; Password = $credential。并将(''username'$passWord1) 更改为('username', $passWord1)。
  • 找不到与参数名称“凭据”匹配的参数。不工作。我怎么也能加密用户名
  • Crendetial -> Credential
  • 找不到与参数名称“凭据”匹配的参数
  • 我之前看到我的错误,我纠正了但仍然没有通过

标签: powershell


【解决方案1】:

invoke-sqlcmd的某些版本没有-credential参数:PowerShell: invoke-sqlcmd with Get-Credential doesn't work(其实我也没有。)

【讨论】:

  • 带有 -credential 参数的错误信息是什么?
  • 找不到与参数名称“凭据”匹配的参数
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-21
  • 1970-01-01
  • 2017-05-18
  • 1970-01-01
  • 1970-01-01
  • 2011-06-20
  • 2016-10-03
相关资源
最近更新 更多