从PowerShell传递到Windows PowerShell时,PSCustomObject存在传递问题



我正在尝试通过PowerShell 7.1.1设置IIS应用程序池。

我将JSON文件中的配置读取到变量$configuration中,由于WebAdministration模块本机不支持PS 7.1.1,该变量已移交给Windows Powershell。

在顶级函数中定义了脚本块,将配置作为PSCustomObject注入脚本块,并在Windows PowerShell中执行。

function Set-AxisAppPool
{
Write-Message 'Setting up a resource pool for Axis...'
$executeInWindowsPowerShellForCompatibilityReasons = {
param (
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[PSCustomObject]
$Configuration
)
Import-Module WebAdministration
Remove-WebAppPool -Name $Configuration.AppPool.Name -Confirm:$false -ErrorAction:SilentlyContinue
New-WebAppPool -Name $Configuration.AppPool.Name -Force | Write-Verbose
$params = @{
Path  = "IIS:AppPools$($Configuration.AppPool.Name)"
Name  = 'processModel'
Value = @{
userName     = $Configuration.AxisUser.Name
password     = $Configuration.AxisUser.Password
identitytype = 'SpecificUser'
}
}
Set-ItemProperty @params
}
powershell -NoLogo -NoProfile $executeInWindowsPowerShellForCompatibilityReasons -Args $configuration # This is a line 546
}

当配置JSON文件超过某个级别时,PowerShell无法将此反序列化的JSONPSCustomObject传递到Windows PowerShell中。

Program 'powershell.exe' failed to run: The Process object must have the UseShellExecute property set to false in order to use environment
| variables.At C:UsersJohnDoeDesktopLocalhost automatizationSet-AxisEnvironment.ps1:546 char:5 +     powershell -NoLogo -NoProfile
| $executeInWindowsPowerShellForCompa … +

它实际上可以处理JSON中对象的n级别,而不处理配置JSON中对象n+1级别。JSON模式经过验证,反序列化按预期工作。

当我使用Start-Process调用Windows PowerShell时,我会收到不同的问题。有人对此有任何暗示吗?

更新

这似乎是PowerShell中的一个错误。

我怀疑这是溢出到其他字段的参数列表的大小,从而给您带来奇怪的错误消息。起始流程:

指定给Arguments属性的字符串长度必须小于32699。

如果您传递的配置超过32699个字符(包括空格),那么这可能是您的问题。可能需要前32699个字符,然后继续到下一个字段-UseShellExecute,该字段将接收不是zerofalse的字符,从而接收true。这会绊倒";错误";,以及误导性错误信息。

最新更新