Recently, I came across a requirement to get a list of all installed applications and sever roles from all Windows machines regardless of VM or physical on-perm severs.
In addition to above, what made me disappointed was that Azure migrate doesn’t provide much information about such requirement to plan your sever migration, because there is only sever readiness coloumn or proposed VM type including process or and memory, but this doesn’t give much flexibility in-terms of flitering your required set of VMs to migrate.
Having an idea about what applications one each VM are installed is an essential part of planning process, therefore, I come up with below PowerShell script, which you can use to get the list of all installed application and sever roles from your envionrment.
Below PowerShell script would get all the applications installed all machines:
$computers = Get-Content "C:\Server.txt"
$results = @()
foreach ($computer in $computers) {
Write-Host "Retrieving installed applications from $computer..."
try {
$installedApps = Get-WmiObject -Class Win32_Product -ComputerName $computer | Select-Object -Property PSComputerName, Name, Version
$results += $installedApps
} catch {
Write-Host "Failed to retrieve installed applications from $computer."
}
}
$results | Export-Csv -Path "C:\InstalledApplications.csv" -NoTypeInformation
Below PowerShell script would get all the sever roles installed on all your machines:
$computers = Get-Content "C:\Server.txt" # Replace with the file path of your list of computers
$result = @()
foreach ($computer in $computers) {
try {
Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer |
Select-Object -Property PSComputerName, Caption, OSArchitecture |
ForEach-Object {
$roles = Get-WindowsFeature -ComputerName $_.PSComputerName |
Where-Object { $_.Installed } |
Select-Object -Property DisplayName
$obj = New-Object -TypeName PSObject
$obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $_.PSComputerName
$obj | Add-Member -MemberType NoteProperty -Name "OperatingSystem" -Value $_.Caption
$obj | Add-Member -MemberType NoteProperty -Name "OSArchitecture" -Value $_.OSArchitecture
$obj | Add-Member -MemberType NoteProperty -Name "InstalledRoles" -Value ($roles.DisplayName -join ', ')
$result += $obj
}
}
catch {
Write-Warning "Failed to retrieve information from $computer"
}
}
$result | Export-Csv -Path "C:\WindowsServerRoles.csv" -NoTypeInformation
Leave a comment