我正在尝试创建一个Powershell脚本,以使用工作流在3台服务器上并行部署来创建Web应用程序池,网站和虚拟目录:这是我的代码:
param (
[string]$iisAppName,
[string]$directoryPath,
[string]$iisAppPoolName,
[string]$un,
[string]$pw,
[string]$virtualdirectoryname,
[string]$path,
[string]$virtualDirectoryPath,
[string]$servers
)
Import-Module WebAdministration
workflow pbatch{
param (
[string]$iisAppName,
[string]$directoryPath,
[string]$iisAppPoolName,
[string]$un,
[string]$pw,
[string]$virtualdirectoryname,
[string]$path,
[string]$virtualDirectoryPath,
[string]$servers
)
foreach -parallel ( $server in $servers)
{
(InlineScript{
Import-Module WebAdministration
Set-Location IIS:\AppPools\})
$appPool = New-WebAppPool $iisAppPoolName -Force
(InlineScript{ Import-Module WebAdministration
Set-ItemProperty -Path IIS:\AppPools\$iisAppPoolName -Name managedRuntimeVersion -Value v4.0})
(InlineScript{Import-Module WebAdministration
Set-ItemProperty -Path IIS:\AppPools\$iisAppPoolName -Name processmodel.identityType -Value 3 })
(InlineScript{Import-Module WebAdministration
Set-ItemProperty -Path IIS:\AppPools\$iisAppPoolName -Name ProcessModel.userName -Value $un})
(InlineScript{Import-Module WebAdministration
Set-ItemProperty -Path IIS:\AppPools\$iisAppPoolName -Name processmodel.password -Value $pw })
}
}
pbatch -servers 'xyz' -iisAppName 'xyz' -iisAppPoolName 'xyz' -directoryPath 'D:\xyz\xyz' -un 'xyz\xyz' -pw 'xyz' -virtualdirectoryname 'Content/Data' -path 'D:\xyz' -virtualDirectoryPath 'IIS:\Sites\xyz\Content\Data'
我不确定应该将内联脚本放在哪里,因为每次更改内联脚本时都会遇到不同的错误。我刚开始首先创建Web应用程序池,但是在这里,当我更改内联脚本时,我会遇到多个错误内联脚本的位置。例如:
Set-ItemProperty : Property managedRuntimeVersion is not found on \\xyz\AppPools.
Parameter name: propName
At pbatch:45 char:45
+
+ CategoryInfo : InvalidArgument: (:) [Set-ItemProperty], ArgumentException
+ FullyQualifiedErrorId : InvalidArgument,Microsoft.PowerShell.Commands.SetItemPropertyCommand
+ PSComputerName : [localhost]
Set-ItemProperty : Property processmodel.identityType is not found on \\xyz\AppPools.
Parameter name: propName
At pbatch:47 char:47
+
+ CategoryInfo : InvalidArgument: (:) [Set-ItemProperty], ArgumentException
+ FullyQualifiedErrorId : InvalidArgument,Microsoft.PowerShell.Commands.SetItemPropertyCommand
+ 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:49 char:49
+
+ CategoryInfo : InvalidArgument: (:) [Set-ItemProperty],
PSArgumentNullException
+ FullyQualifiedErrorId :
InvalidArgument,Microsoft.PowerShell.Commands.SetItemPropertyCommand
+ 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:51 char:51
+
+ CategoryInfo : InvalidArgument: (:) [Set-ItemProperty],
PSArgumentNullException
+ FullyQualifiedErrorId :
InvalidArgument,Microsoft.PowerShell.Commands.SetItemPropertyCommand
+ PSComputerName : [localhost]
每次更改内联脚本的位置时,都会遇到不同的错误。任何帮助将不胜感激。