简体   繁体   English

PSSession中的Powershell foreach

[英]Powershell foreach in pssession

I am installing Office 2010 with parameter, I created a PSSession with admin rights to deploy my scripts, but I have a problem with multiple user. 我正在使用参数安装Office 2010,我创建了具有管理员权限的PSSession来部署脚本,但是多用户存在问题。

I can't use invoke because installation does not start. 我无法使用invoke,因为安装不会开始。

Is there another method to deploy this script to multiple computers? 还有另一种方法可以将此脚本部署到多台计算机吗?

CLS
Start-Job -Name Job1 -ScriptBlock { 
$domainuser = "$env:USERDNSDOMAIN\administrator"
$domainpassword = 'Credential' | ConvertTo-SecureString -AsPlainText -Force
$domaincredentials = New-Object System.Management.Automation.PSCredential ($domainuser, $domainpassword)
$ip = "192.168.10.75" 

Enter-PSSession -ComputerName $ip -Credential $domaincredentials }
Wait-Job -Name Job1
Start-Process -FilePath "powershell" -Verb runAs
Start-Process -FilePath "C:\temp\32 Bit\setup.exe" -ArgumentList "/adminfile Office2010.MSP"

To just run setup.exe (as Administrator), on the remote computer: 要仅在远程计算机上运行setup.exe (以管理员身份),请执行以下操作:

$domainuser = "$env:USERDNSDOMAIN\administrator"
$domainpassword = 'Credential' | ConvertTo-SecureString -AsPlainText -Force
$domaincredentials = New-Object System.Management.Automation.PSCredential ($domainuser, $domainpassword)
$ip = "192.168.10.75" 

Enter-PSSession -ComputerName $ip -Credential $domaincredentials
Start-Process -FilePath "C:\temp\32 Bit\setup.exe" -ArgumentList '/adminfile "C:\temp\32 Bit\Office2010.MSP"' -Verb runAs -Wait
Exit-PSSession

I've assumed the MSP is in the same folder as setup, so I've included the full path to the MSP file... and used double quotes around it due to the space folder name. 我假设MSP与安装程序位于同一文件夹中,所以我包含了MSP文件的完整路径...,并且由于空间文件夹名称的原因,在其周围使用了双引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM