我有一个Powershell脚本,用于远程调用其他服务器上的其他Powershell脚本。 该脚本用于closures并启动不同服务器上的服务。 Powershell脚本的设置方式是,我所要做的就是通过调用serverStartStop [START|STOP]
调用它,并自动并有条不紊地将其serverStartStop [START|STOP]
到服务器列表,并closures每个服务器上的服务列表。
我最近升级了系统,需要启动一些服务后运行批处理脚本。 我可以远程调用批处理脚本,但批处理脚本会调用另一个尝试访问networking上共享的命令。 该命令失败,因为用于调用该命令的用户没有足够的权限访问该共享。
我已经尝试了几件事情来解决这种情况,并对Powershell中的Invoke-Command
行和Windows Batch的runas
命令进行了一些研究。 runas
命令要求input用户密码,这是不可接受的,因为这是一个自动脚本。 有没有人有任何想法,我可以做这个工作干净,没有用户的互动,而不是做初步的START或STOP呼叫?
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 </#>
听起来像是一个双跳问题 。 这些是非常困难的解决办法,因为您将通过的凭据无法通过第二个系统进行身份验证。
CredSSP是一个解决方案 ,但它确实增加了安全风险,所以请谨慎使用,确保您了解配置,并确保正确配置它。