summaryrefslogtreecommitdiff
path: root/windows/win_package.ps1
diff options
context:
space:
mode:
authorTrond Hindenes <trond@hindenes.com>2015-10-28 21:52:32 +0100
committerTrond Hindenes <trond@hindenes.com>2015-10-28 21:52:32 +0100
commitf6ea32b9ec26e10f8bc52ffa7a7ea03f84178bbf (patch)
treea9cd7e1749959e7af17bcb5e3eec144ef7ba86b9 /windows/win_package.ps1
parent205115ea1fc85b99fd7e505b58e84db3a4377f5f (diff)
downloadansible-modules-extras-f6ea32b9ec26e10f8bc52ffa7a7ea03f84178bbf.tar.gz
Various improvements to win_package
Diffstat (limited to 'windows/win_package.ps1')
-rw-r--r--windows/win_package.ps147
1 files changed, 31 insertions, 16 deletions
diff --git a/windows/win_package.ps1 b/windows/win_package.ps1
index 6cdc6bf6..53b2ab60 100644
--- a/windows/win_package.ps1
+++ b/windows/win_package.ps1
@@ -100,7 +100,15 @@ Function Throw-TerminatingError
[System.Management.Automation.ErrorRecord] $ErrorRecord
)
- $exception = new-object "System.InvalidOperationException" $Message,$ErrorRecord.Exception
+ if ($errorRecord)
+ {
+ $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
throw $errorRecord
}
@@ -186,7 +194,19 @@ Function Validate-StandardArguments
try
{
Trace-Message "Parsing $ProductId as an identifyingNumber"
- $identifyingNumber = "{{{0}}}" -f [Guid]::Parse($ProductId).ToString().ToUpper()
+ $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()
+ 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"
}
catch
@@ -1287,24 +1307,19 @@ Else
}
catch
{
- $errormsg = $_[0].exception
+ $errormsg = $_
+ Fail-Json -obj $result -message $errormsg.ToString()
}
- if ($errormsg)
+ #Check if DSC thinks the computer needs a reboot:
+ if ((get-variable DSCMachinestatus -Scope Global -ea 0) -and ($global:DSCMachineStatus -eq 1))
{
- Fail-Json -obj $result -message $errormsg.ToString()
+ Set-Attr $result "restart_required" $true
}
- Else
- {
- #Check if DSC thinks the computer needs a reboot:
- if ($global:DSCMachineStatus -eq 1)
- {
- Set-Attr $result "restart_required" $true
- }
- #Set-TargetResource did its job. We can assume a change has happened
- Set-Attr $result "changed" $true
- Exit-Json -obj $result
- }
+ #Set-TargetResource did its job. We can assume a change has happened
+ Set-Attr $result "changed" $true
+ Exit-Json -obj $result
+
}