Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ansible WinRM-Prep
#
# Detection script to see if the 'ansible-winrm-configure.ps1' has already been run
#
# NOTE: If at any point we 'Exit' (Returning nothing to SCCM), this indicates that the main script
# hasn't been run (Because a component isn't configured). Returning $True means the opposite.
$VerboseActionPreference = 'SilentlyContinue' # Change this to 'Continue' to debug
# Check that a HTTPS listener has been created
$WSManListeners = (Get-ChildItem WSMan:\localhost\Listener | Select-Object -ExpandProperty Keys) -Join "`r`n"
if (-not ($WSManListeners -like '*HTTPS*')) {
Write-Verbose 'HTTPS listener not created'
Exit
}
# Check that a self-signed cert has been created
# (Loop through each cert's subject and see if one is just CN=<COMPUTERNAME>)
$CertExists = $False
(Get-Childitem -Path "Cert:\LocalMachine\My" | Select -Expand Subject) | % {
if ($_ -eq "CN=$($env:COMPUTERNAME)") { $CertExists = $True }
}
if ($CertExists -ne $True) {
Write-Verbose 'Self-signed cert created'
Exit
}
# Return $True if all of the above have already been set up
Write-Verbose 'Configured!'
Return $True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment