Powershell secure string conversion(PowerShell安全字符串转换)
本文介绍了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安全字符串转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:PowerShell安全字符串转换
基础教程推荐
猜你喜欢
- 在多列上分布任意行 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
