安装 ADFS 会引发"null parameter"



这是我安装ADFS脚本的一部分。相当简单,但StartProcess似乎以一种有趣的方式解析开关。我缺了什么吗?

write-host "Installing ADFS - process should take 30-45 seconds"
$installtime=get-date -uformat "%Y_%h_%d_%H_%M"
$logfile="$pwdadfssetup_$installtime.log"
$ADFSInstall = "AdfsSetup.exe"
$ADFSInstallParams = '/quiet /logfile '+$logfile
Start-Process $ADFSInstall $ADFSInstallParams -wait
if ({gc -path $logfile | select-string -pattern "AD FS 2.0 is already installed on this computer"} -eq $null){write-host -ForegroundColor Cyan "ADFS Installed"} Else{write-host -ForegroundColor "There was an error Installing ADFS, please check the log file: $logfile;break}

如果我执行上面的脚本,我会在日志文件中得到以下内容:

Microsoft.IdentityServer.Setup错误:5124:6[2070099085]:System.FormatException:索引(从零开始)必须大于或等于零并且小于参数列表的大小。位于System.Text.StringBuilder.AppendFormat(IFormatProvider提供程序,字符串格式,Object[]参数)位于Microsoft.IdentityServer.Setup.Diagnostics.TraceLog.WriteLine(TraceEventType事件类型,字符串消息,对象[]参数)

如果我手动执行完全相同的命令(从写主机的输出),一切都很好。

有什么想法吗?非常感谢。

我不能删除这个问题,但我通过调查旧日志发现,即使我以常规方式运行命令,也会出现错误。因此,上面的脚本实际上是按预期工作的。

(我真的不明白这里发生了什么,但这里有两种可能性。)

一种选择是您的get-date不能按您的意愿工作。结果是$logfile包含一个百分号(%),这将导致AD FS 2.0安装程序中的"格式字符串注入"。错误消息指向该方向。

但是,如果我在自己的系统上运行你的PowerShell脚本,我就无法重现这一点。

还要注意,看起来您在一个参数中传递了三个命令行参数(/quiet/logfile和日志文件名)。试着这样传球:

$ADFSInstallParams = @('/quiet', '/logfile', $logfile)
Start-Process $ADFSInstall @ADFSInstallParams -wait

然而,如果这是问题的原因,那么我本以为adfssetup.exe会抱怨像command line argument '/quiet /logfile ...' not recognized这样的错误。

相关内容

最新更新