开发者

Installing ADFS throws a "null parameter"

开发者 https://www.devze.com 2023-03-08 16:19 出处:网络
This is a portion of my script for installing ADFS. Pretty straightforward, but it seems Start-Process is parsing switches in a funny way. Is there something I\'m missing?

This is a portion of my script for installing ADFS. Pretty straightforward, but it seems Start-Process is parsing switches in a funny way. Is there something I'm missing?

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}

If I Execute the above script I get the following in a log file:

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.App开发者_运维百科endFormat(IFormatProvider provider, String format, Object[] args)
   at Microsoft.IdentityServer.Setup.Diagnostics.TraceLog.WriteLine(TraceEventType eventType, String msg, Object[] args)

If I execute the exact same command manually (from the output of write-host), everything works fine.

Any ideas? Thank you.


I cant delete the question, but what I found by investigating older logs is that the error occurs even when I run the command the regular way. So the above script is actually working as intended.


(I don't really understand what is happening here, but here are two possibilities.)

One option is that your get-date does not work as you intend. The result is that $logfile contains a percent sign (%), which causes 'format string injection' in the AD FS 2.0 installer. The error message points in that direction.

However, I cannot reproduce that if I run your PowerShell script on my own system.

Also note that it looks like you're passing three command line arguments (/quiet, /logfile, and the log file name) in one argument. Try passing them like so:

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

However, if this were the cause of the problem then I would have expected adfssetup.exe to complain with an error like command line argument '/quiet /logfile ...' not recognized.

0

精彩评论

暂无评论...
验证码 换一张
取 消