You can create add to a hashtable with your parameters based on if IIS service is running then “splat” it into the start-dashboard. Below I extracted out just the part of my function for this that changes the parameters based on if IIS is running.
$StartdashboardParams=@{}
if ((get-service W3svc -ea SilentlyContinue | Where-Object { $_.status -eq “running” }))
{
$StartdashboardParams += @{
Wait = $true
}
write-host “IIS running. Will run dashboard with IIS parameters”
}
else
{
write-host “IIS not running. Will run as a service”
$StartdashboardParams += @{
Port = 1000
}
}