This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 802
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from aaalzand/master
New checks and minor enhancements # Systems Manager/SSMAgent-Toolkit-Windows
- Loading branch information
Showing
50 changed files
with
1,340 additions
and
889 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file modified
BIN
+6.37 KB
(110%)
Systems Manager/SSMAgent-Toolkit-Windows/SSMAgent-Toolkit.zip
Binary file not shown.
52 changes: 52 additions & 0 deletions
52
Systems Manager/SSMAgent-Toolkit-Windows/SSMAgent-Toolkit/Private/Get-AppVersionNumber.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<# | ||
.Synopsis | ||
Get the application version number | ||
.Description | ||
This is a helper function to get the application version number. | ||
.Example | ||
Get-AppVersionNumber -Path 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall' -Value 'Environment' | ||
.INPUTS | ||
Path = The registry path | ||
AppName = The name of the application under the DisplayName under the registry | ||
.OUTPUTS | ||
Return the version number under the registry | ||
#> | ||
function Get-AppVersionNumber { | ||
[CmdletBinding()] | ||
param ( | ||
[String]$RegHive = "LocalMachine", | ||
[String]$Path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", #Define the variable to hold the location of Currently Installed Programs | ||
[parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()]$AppName | ||
) | ||
|
||
if ((Get-WmiObject -Class Win32_ComputerSystem).SystemType -match 'x64') { | ||
$RegView = [Microsoft.Win32.RegistryView]::Registry64 | ||
} | ||
else { | ||
$RegView = [Microsoft.Win32.RegistryView]::Registry32 | ||
} | ||
|
||
#Create an instance of the Registry Object and open the HKLM base key | ||
$reg = [microsoft.win32.registrykey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::$RegHive, $RegView) | ||
|
||
#Drill down into the Uninstall key using the OpenSubKey Method | ||
$regkey = $reg.OpenSubKey($Path) | ||
|
||
#Retrieve an array of string that contain all the subkey names | ||
$subkeys = $regkey.GetSubKeyNames() | ||
|
||
#Open each Subkey and use GetValue Method to check the match values for AppName | ||
foreach ($key in $subkeys) { | ||
$thisKey = $Path + "\\" + $key | ||
$thisSubKey = $reg.OpenSubKey($thisKey) | ||
if ($($thisSubKey.GetValue("DisplayName")) -eq $AppName) { | ||
write-host $($thisSubKey.GetValue("DisplayVersion")) | ||
return [System.Version]$($thisSubKey.GetValue("DisplayVersion")) | ||
break | ||
} | ||
else { | ||
continue | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,5 +35,4 @@ function Test-RegistryValue { | |
Write-Log -Message $($PSitem) -LogLevel "ERROR" | ||
return $false | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
Systems Manager/SSMAgent-Toolkit-Windows/SSMAgent-Toolkit/Public/Get-SSMAgentVersion.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<# | ||
.Synopsis | ||
Check the installed and latest version of SSM Agent. | ||
.Description | ||
This is a public function used to check the SSM Agent version values for both installed and publicly available. | ||
.Example | ||
Get-SSMAgentVersion | ||
.INPUTS | ||
Region = The region to when SSM Agent register to. | ||
RegistryHive = The registry hive where we look for installed applications. Default value: "LocalMachine". | ||
RegistryPath = The path for the install applications in the registry. Default value: "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall". | ||
Skip = Switch to skip this function if the service is not available. | ||
.OUTPUTS | ||
New-PSObjectResponse -Check "$check" -Status "$value" -Note "$note" | ||
#> | ||
Function Get-SSMAgentVersion { | ||
[CmdletBinding()] | ||
param ( | ||
[String]$Region, | ||
[String]$RegistryHive = "LocalMachine", | ||
[String]$RegistryPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", #Define the variable to hold the location of Currently Installed Programs, | ||
[Switch]$Skip | ||
) | ||
|
||
$check = "SSMAgent version" | ||
Write-Log -Message "New check....." | ||
Write-Log -Message "$check" | ||
|
||
if (-not ($Skip)) { | ||
$LatestVersionUrl = "https://s3.$Region.amazonaws.com/amazon-ssm-$Region/latest/VERSION" | ||
Write-Log -Message "Checking the latest SSM agent from $LatestVersionUrl." | ||
|
||
try { | ||
Write-Log -Message "Checking the install agent version from $RegistryHive`:\$RegistryPath" | ||
$CurrentSSMAgentVersion = Get-AppVersionNumber -RegHive $RegistryHive -Path $RegistryPath -AppName "Amazon SSM Agent" | ||
$CurrentSSMAgentVersion = [System.Version]$CurrentSSMAgentVersion | ||
Write-Log -Message "The install SSM Agent version is $CurrentSSMAgentVersion" | ||
} | ||
catch { | ||
Write-Log -Message ("Unable to retrieve the install SSM Agent version from $RegistryHive`:\$RegistryPath. " + $($PSitem.ToString())) -LogLevel "ERROR" | ||
$CurrentSSMAgentVersion = [System.Version]"0.0.0.0" | ||
} | ||
|
||
try { | ||
$LatestSSMAgentVersion = Invoke-RestMethod -Uri $LatestVersionUrl | ||
Write-Log -Message "The latest agent version in $Region is $LatestSSMAgentVersion." | ||
$value = "Pass" | ||
if ([System.Version]$CurrentSSMAgentVersion -eq "0.0.0.0") { | ||
$note = "The latest agent version in $Region is $LatestSSMAgentVersion" | ||
} | ||
elseif ([System.Version]$CurrentSSMAgentVersion -eq [System.Version]$LatestSSMAgentVersion) { | ||
Write-Log -Message "The install and the latest agent version in $Region is $LatestSSMAgentVersion." | ||
$note = "The install and the latest agent version in $Region is $LatestSSMAgentVersion" | ||
} | ||
elseif ([System.Version]$CurrentSSMAgentVersion -ne [System.Version]$LatestSSMAgentVersion) { | ||
Write-Log -Message "The install SSM Agent version is $CurrentSSMAgentVersion, the latest in $Region is $LatestSSMAgentVersion." | ||
$note = "The install SSM Agent version is $CurrentSSMAgentVersion, the latest in $Region is $LatestSSMAgentVersion" | ||
} | ||
} | ||
catch { | ||
if ([System.Version]$CurrentSSMAgentVersion -eq "0.0.0.0") { | ||
$value = "N/A" | ||
Write-Log -Message ("Unable to retrieve the install or latest SSM Agent version from $LatestVersionUrl. " + $($PSitem.ToString())) -LogLevel "ERROR" | ||
$note = "Unable to retrieve the install or latest SSM Agent version" | ||
} | ||
else { | ||
$value = "Pass" | ||
Write-Log -Message ("Unable to retrieve the latest SSM Agent version from $LatestVersionUrl." + $($PSitem.ToString())) -LogLevel "ERROR" | ||
$note = "The install SSM Agent version is $CurrentSSMAgentVersion" | ||
} | ||
} | ||
} | ||
|
||
else { | ||
$value = "Skip" | ||
$note = "This test skipped since the SSM Agent is not installed" | ||
Write-Log -Message "The SSMAgent Version check skipped since the SSM Agent is not installed" -LogLevel "ERROR" | ||
Write-Log -Message "Installing and configuring SSM Agent on EC2 instances for Windows Server - https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-install-ssm-win.html" -LogLevel "INFO" | ||
} | ||
|
||
return New-PSObjectResponse -Check "$check" -Status "$value" -Note "$note" | ||
} |
Oops, something went wrong.