From e4b80dd43c23b94b0c9072a7afb71b5af55c1e7d Mon Sep 17 00:00:00 2001 From: Jon Hawkesworth Date: Sun, 31 Aug 2014 16:20:50 +0100 Subject: [PATCH] Added null check in case http connection used and no cert found. --- library/windows/setup.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/windows/setup.ps1 b/library/windows/setup.ps1 index 381fc973c5..1d24ce2138 100644 --- a/library/windows/setup.ps1 +++ b/library/windows/setup.ps1 @@ -66,4 +66,13 @@ $ips = @() Foreach ($ip in $netcfg.IPAddress) { If ($ip) { $ips += $ip } } Set-Attr $result.ansible_facts "ansible_ip_addresses" $ips +$psversion = $PSVersionTable.PSVersion.Major +$winrm_cert_expiry = Get-ChildItem -Path Cert:\LocalMachine\My | where Subject -EQ "CN=$env:COMPUTERNAME" | select NotAfter + +Set-Attr $result.ansible_facts "ansible_powershell_version" $psversion +if ($winrm_cert_expiry) +{ + Set-Attr $result.ansible_facts "ansible_winrm_certificate_expires" $winrm_cert_expiry.NotAfter.ToString("yyyy-MM-dd HH:mm:ss") +} + Exit-Json $result;