[英]Powershell script to pass parameters using psexec in commandline
Hi I am trying to run a powershell script remotely to create the webapplication pool for 2 servers: Below is the code in my Website_pararrel.ps1 which i run on 2nd server: 嗨,我正在尝试远程运行Powershell脚本来为2台服务器创建Web应用程序池:以下是我在2台服务器上运行的Website_pararrel.ps1中的代码:
workflow pbatch{
param ([string]$iisAppName,[string]$directoryPath,[string]$iisAppPoolName,
[string]$un,[string]$pw,[string]$path,[string]$servers)
foreach -parallel ( $server in $servers)
{
(InlineScript{
Import-Module WebAdministration
Set-Location "IIS:\AppPools"
if (Test-Path $Using:iisAppPoolName -pathType container)
{
Remove-Item $Using:iisAppPoolName -recurse
}
New-Item $Using:iisAppPoolName -Force
Set-ItemProperty -Path IIS:\AppPools\WhereIsTest -Name managedRuntimeVersion -Value v4.0
Set-ItemProperty -Path IIS:\AppPools\WhereIsTest -Name processmodel.identityType -Value 3
Set-ItemProperty -Path IIS:\AppPools\WhereIsTest -Name ProcessModel.userName -Value $Using:un1
Set-ItemProperty -Path IIS:\AppPools\WhereIsTest -Name processmodel.password -Value $Using:pw1
})
}
}
pbatch -servers $servers -iisAppPoolName $iisAppPoolName -un $un -pw $pw
and i run using this command from 1st servers: 我从第一台服务器使用此命令运行:
Psexec \\CPDEVWEB03.blfdev.lab /s cmd /c %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -file D:\Website_Parallel.ps1 -servers "xyz" -iisAppPoolName "Test" -un "***\****" -pw "*******"
But i get this error: 但是我得到这个错误:
Test-Path : Cannot bind argument to parameter 'Path' because it is an empty
string.
At pbatch:14 char:14
+
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingVa
lidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl
lowed,Microsoft.PowerShell.Commands.TestPathCommand
+ PSComputerName : [localhost]
New-Item : Cannot bind argument to parameter 'Path' because it is an empty
string.
t pbatch:14 char:14
+
+ CategoryInfo : InvalidData: (:) [New-Item], ParameterBindingVal
idationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl
lowed,Microsoft.PowerShell.Commands.NewItemCommand
+ PSComputerName : [localhost]
Set-ItemProperty : Cannot process argument because the value of argument
"obj"
is null. Change the value of argument "obj" to a non-null value.
At pbatch:14 char:14
+
+ CategoryInfo : InvalidArgument: (:) [Set-ItemProperty], PSArgum
entNullException
+ FullyQualifiedErrorId : InvalidArgument,Microsoft.PowerShell.Commands.Se
tItemPropertyCommand
+ PSComputerName : [localhost]
Set-ItemProperty : Cannot process argument because the value of argument
"obj"
is null. Change the value of argument "obj" to a non-null value.
cmd exited on CPDEVWEB03.blfdev.lab with error code 0.
Somehow the values of the variables from my commandline script is not getting passed to my powershell script. 不知何故,我的命令行脚本中的变量值未传递到Powershell脚本中。 Any help would be greatly appreciated. 任何帮助将不胜感激。
You need to put the parameter for /c into single quotes ( ' ) so that it is noticed as one parameter. 您需要将/ c的参数放在单引号(')中,以便将其视为一个参数。
Does the following work? 请问以下工作吗?
Psexec \\CPDEVWEB03.blfdev.lab /s cmd /c '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -file "D:\Website_Parallel.ps1 -servers xyz -iisAppPoolName Test -un ***\**** -pw *******"'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.