uses get-attr and fixes file path issues by escaping quotes around path

This commit is contained in:
Phil 2015-09-16 20:34:56 -05:00 committed by Matt Clay
parent 5ff4d219e0
commit 3781c5ccb0

View file

@ -21,52 +21,38 @@
$params = Parse-Args $args; $params = Parse-Args $args;
$result = New-Object psobject; $path = Get-Attr $params "path" -failifempty $true
Set-Attr $result "changed" $false; $state = Get-Attr $params "state" "present"
$wait = $false $creates = Get-Attr $params "creates" $false
$extra_args = Get-Attr $params "extra_args" ""
$wait = Get-Attr $params "wait" $false | ConvertTo-Bool
If (-not $params.path.GetType) If (-not $params.path.GetType)
{ {
Fail-Json $result "missing required arguments: path" Fail-Json $result "missing required arguments: path"
} }
If ($params.wait -eq "true" -Or $params.wait -eq "yes")
{
$wait = $true
}
$extra_args = ""
If ($params.extra_args.GetType)
{
$extra_args = $params.extra_args;
}
If (($creates -ne $false) -and ($state -ne "absent") -and (Test-Path $creates))
{
Exit-Json $result;
}
$logfile = [IO.Path]::GetTempFileName(); $logfile = [IO.Path]::GetTempFileName();
If ($params.state.GetType -and $params.state -eq "absent") If ($params.state.GetType -and $params.state -eq "absent")
{ {
If ($wait) If ($wait)
{ {
Start-Process -FilePath msiexec.exe -ArgumentList "/x $params.path /qb /l $logfile $extra_args" -Verb Runas -Wait; Start-Process -FilePath msiexec.exe -ArgumentList "/x `"$path`" /qn /l $logfile $extra_args" -Verb Runas -Wait;
} }
Else Else
{ {
Start-Process -FilePath msiexec.exe -ArgumentList "/x $params.path /qb /l $logfile $extra_args" -Verb Runas; Start-Process -FilePath msiexec.exe -ArgumentList "/x `"$path`" /qn /l $logfile $extra_args" -Verb Runas;
} }
} }
Else Else
{ {
If ($wait) If ($wait)
{ {
Start-Process -FilePath msiexec.exe -ArgumentList "/i $params.path /qb /l $logfile $extra_args" -Verb Runas -Wait; Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$path`" /qn /l $logfile $extra_args" -Verb Runas -Wait;
} }
Else Else
{ {
Start-Process -FilePath msiexec.exe -ArgumentList "/i $params.path /qb /l $logfile $extra_args" -Verb Runas; Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$path`" /qn /l $logfile $extra_args" -Verb Runas;
} }
} }