2012-02-15 78 views
0

嗨,我想這樣做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驗證)並試圖將我的密碼轉換爲安全字符串,並且從外觀上看並不是很好。請幫助TKS 我去這個鏈接和代碼有幫助,但問題是,當我用鼠標右鍵單擊我的註冊服務器上,看見我看到它是在Windows身份驗證模式的性質,而不是在SQL認證模式

回答

0

嘗試分配在$值管道前傳:

$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)) } 
+0

但奇怪的是,當我嘗試連接的默認連接設置爲Windows身份驗證而不是SQL身份驗證,所以我改變了集成安全爲假,現在我能夠看到選中的SQL身份驗證,但用戶名和密碼都是空白的,所以我的sa和密碼在哪裏呢?我在做什麼錯了? – JackyBoi 2012-02-15 14:23:11

相關問題