远程位置pipe理复制并安装大型软件更新到50局域网

最初发布到堆栈溢出,并被指示在这里。 我是新手编程,正在尝试编写一个PowerShell脚本来pipe理软件更新。 我在一个拥有50多个远程办公室的Windows域环境中。 每个办公室有4台电脑。 一台计算机“计算机A”安装了Dropbox,用于备份和现在的软件更新。 我想从本地机器上执行一个脚本,将一个文件夹(〜1 GB)复制到该局域网中的其他计算机上,然后运行目录中的setup.exe文件来更新这些计算机上的软件。

据我所知,为了使用Enter-pssession cmdlet并运行复制项目和启动过程,我必须:

  1. 在远程机器上启用winrm:enable-psremoting -force
  2. 在远程计算机上启用CredSSP身份validation:enable-smancredssp -role server -force
  3. 在本地计算机上启用CredSSP身份validation:enable-SmanCredSSP -role client -force

从这里我可以进入Power shell会话并开始复制和安装。 这是我正在运行的代码:

#Allow my computer to send credentials to remote computers Enable-WSManCredSSP -Role Client -DelegateComputer * -Force $credential = Get-Credential -Credential domain\user #Getting Content $path = "C:\computernames.csv" Import-Csv -path $path | foreach-object { $computername = $_.Name if (Test-Connection -cn $_.Name -quiet) { #copy the batch file that allows remote powershell access $source = "c:\" $destination = "\\$computername\c$\install files\remoteaccess" robocopy $source $destination #open file to allow remote PS access & psexec \\$computername -a runas -u domain\user -p password -c -f -h "\\$computername\c$\install files\remoteaccess\remoteaccess.bat" #Initiates Power Shell session with remote computer Enter-PSSession -cn $_.Name -Credential $credential -Authentication Credssp #begin copy #be sure to refine destination copy-item -path $_.Source -Destination $_.Destination -force -verbose -recurse | out-file c:\copylog.txt #begin silent install #code here #stop wsmancredssp accep disable-wsmancredssp -role server #close pssession exit-pssession } else { "$computername is not online" } } Disable-wsmancredssp -role client 

computernames.csv具有标题:名称,源,具有UNC目录的目标,每个局域网的计算机都带有保pipe箱以及复制文件的位置。
“remoteaccess.bat”文件包含以下两行代码:

 powershell.exe enable-psremoting -force >>c:\remotelog.txt powershell.exe Enable-WSManCredSSP -role Server -force >>c:\remotelog.txt 

启动与远程计算机的psexec会话后,powershell窗口会冻结,并发送第一个powershell命令以启用远程处理。 没有错误产生,或input请求。 该命令的输出保存在remotelog文本文件中:“WinRM已经更新以接收请求,WinRM服务启动。

WinRM已经被设置为在这台机器上进行远程pipe理。“

看来powershell命令启用wsmancredssp是永远不会收到的。 当我从远程访问软件运行远程计算机上的batch file时,这两个命令执行并成功logging。 我的psexec命令出错了,或者如何设置这些计算机以允许使用远程命令而不使用GPO进行远程会话?

代码closures的方式有很多种:

  1. 如果您处于Windows域环境中,为什么不通过GPO启用Powershell远程处理?
  2. Enter-PSSession是一个交互式远程会话的命令,你正在寻找的是带会话参数的New-PSSession和Invoke-Command
  3. CredSSP仅在您要从您连接的远程系统访问远程系统时才是必需的
  4. 为什么要将1GB的数据复制到分支机构? 与主办公室的连接是否太不稳定?
  5. robocopy命令正在将C:\的所有内容复制到远程目标,这绝对不是你想要的(pagefile.sys,bootmgr等)。