安装ADFS会抛出“null参数”

时间:2011-05-25 03:35:35

标签: powershell installation adfs

这是我安装ADFS脚本的一部分。非常简单,但似乎Start-Process以有趣的方式解析交换机。有什么我想念的吗?

write-host "Installing ADFS - process should take 30-45 seconds"
$installtime=get-date -uformat "%Y_%h_%d_%H_%M"
$logfile="$pwd\adfssetup_$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 Error: 5124 :   6 [ 2070099085 ]: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
   at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
   at Microsoft.IdentityServer.Setup.Diagnostics.TraceLog.WriteLine(TraceEventType eventType, String msg, Object[] args)

如果我手动执行完全相同的命令(来自write-host的输出),一切正常。

有什么想法吗? 谢谢。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

一个选项是您的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之类的错误。

相关问题