PowerShell安全字符串转换

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安全字符串转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)