{"id":2263,"date":"2025-05-01T20:45:00","date_gmt":"2025-05-02T00:45:00","guid":{"rendered":"https:\/\/enterpriseadmins.org\/blog\/?p=2263"},"modified":"2025-05-01T08:40:22","modified_gmt":"2025-05-01T12:40:22","slug":"comparing-installed-packages-on-photon-os-using-powershell-and-ssh","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/comparing-installed-packages-on-photon-os-using-powershell-and-ssh\/","title":{"rendered":"Comparing Installed Packages on Photon OS Using PowerShell and SSH"},"content":{"rendered":"\n<p>When debugging inconsistencies between Photon OS systems, say one is failing and another is stable, it&#8217;s useful to compare their installed package versions.  In one recent case, I needed a quick way to do just that from my admin workstation.  Here\u2019s how I solved it using PowerShell and the <code>Posh-SSH<\/code> module.<\/p>\n\n\n\n<p>In this test case, both hosts have a user account with the same name\/password, so only one credential was created.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Prompt for SSH credentials\n$creds = Get-Credential\n\n# Connect to Host 1 and get package list as JSON\n$host1        = '192.168.10.135'\n$host1session = New-SSHSession -ComputerName $host1 -Credential $creds -AcceptKey\n$host1json    = (Invoke-SSHCommand -Command 'tdnf list installed -json' -SessionId $host1session.SessionId).Output | ConvertFrom-Json\n\n# Connect to Host 2 and get package list as JSON\n$host2        = '192.168.127.174'\n$host2session = New-SSHSession -ComputerName $host2 -Credential $creds -AcceptKey\n$host2json    = (Invoke-SSHCommand -Command 'tdnf list installed -json' -SessionId $host2session.SessionId).Output | ConvertFrom-Json\n\n# Compare the resulting package lists\n$compared = Compare-Object -ReferenceObject $host1json -DifferenceObject $host2json -Property Name, Evr\n\n# Group the results by package name and build tabular results for side-by-side compare\nforeach ($thisPackage in ($compared | Group-Object -Property Name)) {\n  &#91;pscustomobject]&#91;ordered]@{\n    Name = $thisPackage.Name\n    $host1 = ($thisPackage.Group | ?{$_.SideIndicator -eq '&lt;='}).Evr\n    $host2 = ($thisPackage.Group | ?{$_.SideIndicator -eq '=>'}).Evr\n  }\n}<\/code><\/pre>\n\n\n\n<p>The script gets a list of all installed packages from each host as JSON (using <code>tdnf list installed -json<\/code>), then converts the JSON output to a powershell object.<br>The two list of installed packages are then compared using <code>Compare-Object<\/code>. <br>Finally, we loop through each unique package and create a new object to compare the versions side by side.<\/p>\n\n\n\n<p>I&#8217;ve included the first 10 rows of output below for reference.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Name                           192.168.10.135       192.168.127.174\n----                           --------------       ---------------\ncloud-init                     24.3.1-1.ph4         25.1-1.ph4\ncurl                           8.7.1-4.ph4          8.12.0-1.ph4\ncurl-libs                      8.7.1-4.ph4          8.12.0-1.ph4\nelfutils                       0.181-7.ph4          0.181-8.ph4\nelfutils-libelf                0.181-7.ph4          0.181-8.ph4\nexpat                          2.4.9-3.ph4          2.4.9-4.ph4\nexpat-libs                     2.4.9-3.ph4          2.4.9-4.ph4\ngettext                        0.21-4.ph4           0.21-5.ph4\nglib                           2.68.4-2.ph4         2.68.4-4.ph4\nglibc                          2.32-19.ph4          2.32-20.ph4<\/code><\/pre>\n\n\n\n<p>Looking at this output, we can see which packages are different between our two hosts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Comparing installed packages across Photon OS systems can be an invaluable troubleshooting and auditing tool &#8211; especially when dealing with configuration drift, unexpected behavior, or undocumented changes.  By using PowerShell and the <code>Posh-SSH<\/code> module, you can quickly automate the comparison process without needing to log in to each system manually.  Hopefully, this gives you a solid starting point for your own comparisons and debugging tasks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When debugging inconsistencies between Photon OS systems, say one is failing and another is stable, it&#8217;s useful to compare their installed package versions. In one recent case, I needed a quick way to do just that from my admin workstation. &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/comparing-installed-packages-on-photon-os-using-powershell-and-ssh\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2263","post","type-post","status-publish","format-standard","hentry","category-scripting"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=2263"}],"version-history":[{"count":1,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2263\/revisions"}],"predecessor-version":[{"id":2264,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2263\/revisions\/2264"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=2263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=2263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=2263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}