Skip to content

Instantly share code, notes, and snippets.

@lholman
Created October 10, 2013 10:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lholman/6915950 to your computer and use it in GitHub Desktop.
Save lholman/6915950 to your computer and use it in GitHub Desktop.
Provides a quick way to list and save to file Windows Feature configuration, installed Hotfixes and installed programs (originally from here http://bit.ly/t2Ofi0) on a Windows Server, tested on Windows 2008 R2 Save as ServerSnapshot.ps1 and run using PS C:\>.\ServerSnapshot.ps1
function Get-InstalledPrograms() {
$array = @()
$computername="$env:computername"
#Define the variable to hold the location of Currently Installed Programs
$UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
#Create an instance of the Registry Object and open the HKLM base key
$reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computername)
#Drill down into the Uninstall key using the OpenSubKey Method
$regkey=$reg.OpenSubKey($UninstallKey)
#Retrieve an array of string that contain all the subkey names
$subkeys=$regkey.GetSubKeyNames()
#Open each Subkey and use GetValue Method to return the required values for each
foreach($key in $subkeys){
$thisKey=$UninstallKey+"\\"+$key
$thisSubKey=$reg.OpenSubKey($thisKey)
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computername
$obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
$obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))
$obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))
$obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))
$array += $obj
}
$array | Where-Object { $_.DisplayName } | Select ComputerName, DisplayName, DisplayVersion, Publisher | Sort-Object -Property DisplayName | ft -auto
}
Write-Host "Getting list of installed Windows Hotfixes..."
Get-Hotfix > "$env:computername.hotfixes.txt"
Write-Host "Windows installed Hotfixes list saved to: $env:computername.hotfixes.txt"
Write-Host "Getting Windows Features configuration..."
Import-Module ServerManager
Get-WindowsFeature > "$env:computername.windowsfeatures.txt"
Write-Host "Windows Feature configuration saved to: $env:computername.windowsfeatures.txt"
Write-Host "Getting installed programs list..."
Get-InstalledPrograms > "$env:computername.installedprograms.txt"
Write-Host "Installed programs list saved to: $env:computername.installedprograms.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment