Various improvements to win_package

This commit is contained in:
Trond Hindenes 2015-10-28 21:52:32 +01:00
parent 205115ea1f
commit f6ea32b9ec

View file

@ -100,7 +100,15 @@ Function Throw-TerminatingError
[System.Management.Automation.ErrorRecord] $ErrorRecord [System.Management.Automation.ErrorRecord] $ErrorRecord
) )
if ($errorRecord)
{
$exception = new-object "System.InvalidOperationException" $Message,$ErrorRecord.Exception $exception = new-object "System.InvalidOperationException" $Message,$ErrorRecord.Exception
}
Else
{
$exception = new-object "System.InvalidOperationException" $Message
}
$errorRecord = New-Object System.Management.Automation.ErrorRecord $exception,"MachineStateIncorrect","InvalidOperation",$null $errorRecord = New-Object System.Management.Automation.ErrorRecord $exception,"MachineStateIncorrect","InvalidOperation",$null
throw $errorRecord throw $errorRecord
} }
@ -186,7 +194,19 @@ Function Validate-StandardArguments
try try
{ {
Trace-Message "Parsing $ProductId as an identifyingNumber" Trace-Message "Parsing $ProductId as an identifyingNumber"
$TestGuid = [system.guid]::NewGuid()
#Check to see if the productid is a guid
if ([guid]::TryParse($ProductId, [ref]$TestGuid))
{
$identifyingNumber = "{{{0}}}" -f [Guid]::Parse($ProductId).ToString().ToUpper() $identifyingNumber = "{{{0}}}" -f [Guid]::Parse($ProductId).ToString().ToUpper()
Trace-Message "Parsed $ProductId as $identifyingNumber (is guid)"
}
Else
{
$identifyingNumber = $ProductId
Trace-Message "Parsed $ProductId as $identifyingNumber (is not guid)"
}
Trace-Message "Parsed $ProductId as $identifyingNumber" Trace-Message "Parsed $ProductId as $identifyingNumber"
} }
catch catch
@ -1287,17 +1307,12 @@ Else
} }
catch catch
{ {
$errormsg = $_[0].exception $errormsg = $_
}
if ($errormsg)
{
Fail-Json -obj $result -message $errormsg.ToString() Fail-Json -obj $result -message $errormsg.ToString()
} }
Else
{
#Check if DSC thinks the computer needs a reboot: #Check if DSC thinks the computer needs a reboot:
if ($global:DSCMachineStatus -eq 1) if ((get-variable DSCMachinestatus -Scope Global -ea 0) -and ($global:DSCMachineStatus -eq 1))
{ {
Set-Attr $result "restart_required" $true Set-Attr $result "restart_required" $true
} }
@ -1305,6 +1320,6 @@ Else
#Set-TargetResource did its job. We can assume a change has happened #Set-TargetResource did its job. We can assume a change has happened
Set-Attr $result "changed" $true Set-Attr $result "changed" $true
Exit-Json -obj $result Exit-Json -obj $result
}
} }