PowerShell安全字符串转换 [英] Powershell secure string conversion

查看:34
本文介绍了PowerShell安全字符串转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试这样做

Import-Csv C:sl.csv |$pass = convertto-securestring "abc123"-asplaintext -force | ForEach-Object {New-Item $(Encode-Sqlname $_.Name) -ItemType Registration -Value ("server=$($_.Name);integrated security=true") -Credential (New-Object System.Management.Automation.PSCredential("sa", $pass)) }

但是遇到这样的错误

Expressions are only allowed as the first element of a pipeline.
At line:1 char:29
+ Import-Csv C:sl.csv |$pass  <<<< = convertto-securestring "abc123"-asplaintext -fo
rce | ForEach-Object {New-Item $(Encode-Sqlname $_.Name) -ItemType Registration -Value ("server=$($_.Name);integrated security=true") -Credential (New-Object System.Management.Automation.PSCredential("sa", $pass)) }
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline

我基本上希望能够添加用户名和密码(使用SQL身份验证),并尝试将密码转换为securestring,但从外观上看并不是很好。请协助TKS 我转到此链接,那里的代码很有帮助,但问题是,当我右键单击已注册的服务器并看到属性时,我看到它处于windows身份验证模式而不是sql身份验证模式

推荐答案

尝试在管道之前的$PASS处赋值:

$pass = convertto-securestring "abc123"-asplaintext -force 
Import-Csv C:sl.csv | ForEach-Object {New-Item $(Encode-Sqlname $_.Name) -ItemType Registration -Value ("server=$($_.Name);integrated security=true") -Credential (New-Object System.Management.Automation.PSCredential("sa", $pass)) }

这篇关于PowerShell安全字符串转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆