2014-12-03 27 views
0

我有一個Powershell腳本,用於遠程調用其他服務器上的其他Powershell腳本。該腳本用於關閉並啓動不同服務器上的服務。 Powershell腳本的設置方式是我所要做的就是通過調用serverStartStop [START|STOP]來調用它,並自動並有條不紊地將其列入服務器列表,並關閉每臺服務器上的服務列表。使用當前Powershell憑證進行遠程調用

我最近升級了系統,需要啓動一些服務後運行批處理腳本。我可以遠程調用批處理腳本,但批處理腳本調用另一個嘗試訪問網絡上的共享的命令。該命令失敗,因爲用於調用該命令的用戶沒有足夠的權限訪問該共享。

我已經試過幾件事情要糾正這種情況,並做了一些研究,在PowerShell中的Invoke-Command命令行和Windows批量的runas命令。 runas命令要求輸入用戶密碼,這是不可接受的,因爲這是一個自動腳本。除了進行初始START或STOP呼叫之外,是否有人有任何想法可以使我的工作乾淨利落,無需用戶干預?

+0

使用Credssp的'Invoke-Command'是最常用的方法。看到我對[這個問題]的答案(http://stackoverflow.com/questions/24903878/powershell-server-network-drive)。 – 2014-12-04 05:01:11

回答

1

Invoke-Command上的-Credential方法可能是你想要的。我發現這非常適用於以加密方式存儲用於腳本使用的憑證集。

Add-Type -assembly System.Security 

# String to Crypt 
$passwordASCII = Read-Host -Prompt "Enter the Password" 

# String to INT Array 
$enc = [system.text.encoding]::Unicode 
$clearPWD_ByteArray = $enc.GetBytes($passwordASCII.tochararray()) 

# Crypting 
$secLevel = [System.Security.Cryptography.DataProtectionScope]::LocalMachine 
$bakCryptedPWD_ByteArray = [System.Security.Cryptography.ProtectedData]::Protect($clearPWD_ByteArray, $null, $secLevel) 

# Store in Base 64 form 
$B64PWD_ByteArray = [Convert]::ToBase64String($bakCryptedPWD_ByteArray) 
Set-Content -LiteralPath c:\Temp\pass.txt -Value $B64PWD_ByteArray 

<#> 
Use... 
Add-Type -assembly System.Security 
$resCryptedPWD_ByteArray = [Convert]::FromBase64String((Get-Content -LiteralPath "$Password_File")) 
$secLevel = [System.Security.Cryptography.DataProtectionScope]::LocalMachine 
$clearPWD_ByteArray = [System.Security.Cryptography.ProtectedData]::Unprotect($resCryptedPWD_ByteArray, $null, $secLevel) 
$enc = [system.text.encoding]::Unicode 

...To retrieve the password from $Password_File 

Then use... 

$enc.GetString($clearPWD_ByteArray) 

...As your password 
</#> 
+0

謝謝。我使用此解決方案將密碼存儲在從腳本調用的服務器上。然後我修改我的腳本以使用我創建的會話調用.bat文件。 – sfedak 2014-12-18 20:58:53

1

聽起來像是double hop problem。這些都是非常難以解決的,因爲您將通過的憑據無法通過第二個系統進行身份驗證。

CredSSP is a solution,但它確實增加了安全風險,所以請謹慎使用,確保您瞭解配置,並確保您配置正確。

+0

這是一個有用的建議。我決定採用稍微不同的路線,並在遠程調用的powershell腳本中創建一個會話。 – sfedak 2014-12-18 21:00:37