Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8192165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:06:52+00:00 2026-06-07T04:06:52+00:00

I have a PowerShell script with the following excerpt: foreach ($pc in $ComputerName) {

  • 0

I have a PowerShell script with the following excerpt:

foreach ($pc in $ComputerName) {
  $appnames = $appnames | Sort-Object
  Write-Debug "Number of entries in `$appnames = $($appnames.count)"
  if ($AsHTML) {#Switch Parameter
    Write-Verbose "Generating HTML Report..."
    $th = "<TR><TH>Application Name</TH>" #Create Top header
    foreach ($pc in $ComputerName) {
       $th += "<TH>$pc</TH>" #Another header for each pc
    }
    $th += "</TR>" #Header finished
    $rows = ""
    foreach ($app in $appnames) {
      $rows += "<TR><TH>$app</TH>"
      foreach ($pc in $ComputerName) {
        Write-Debug $RegistryEntries[$pc].Value[$app]
        $currentApp = $RegistryEntries[$pc].Value[$app]
        if ($currentApp) {
          if ($currentApp.DisplayVersion) {
            $status = $currentApp.DisplayVersion
          } else {
            $status = "Version-nr. N/A"
          }
        } else {
          $status = "Application N/A"
        }
        $rows += "<TD>$status</TD>" #Intersection cell for each pc
      }
      $rows += "</TR>"
    }
    Write-Verbose "Finishing html report..."
    $html = "
    <html>
      <head>
        <style>
          body { background-color:#FFFFCC;
          font-family:Tahoma;
          font-size:12pt; }
          td, th { border:1px solid #000033;
          border-collapse:collapse; }
          th { color:white;
            background-color:#000033; }
          table, tr, td, th { padding: 0px; margin: 0px }
          table { margin-left:10px; }
        </style>
        <Title>Application versions Report</Title>
      </head>
      <body>
        <table>
          $th
          $rows
        </table>
      </body>
    </html>"
  }
}

So, to explain the wall of text above a bit;

  • $RegistryEntries is a Hashtable of Hashtables, with the top-level keys being computer names, and the low-level hashtable keys being application names found in the Uninstall part of the registry. The corresponding values to the Application-name-keys are custom PSObjects with three general properties: .Displayname, .DisplayVersion, and .UninstallString. (Not all objects have all of the three properties, but each object has at least one).
  • What I hope to achieve with this HTML-table is to get some kind of “pivot-table” (ref. Wikipedia entry for Pivot Tables, but not quite), where I can get Application Names on the Y-axis, and computer names on the X-axis, and the Version number of said application on said computer where they intersect.

So again, with that in mind, could someone help me understand why my script when run prompts me in the shell for permission to add application names to the array $appnames (elsewhere in the script), as well as doing the same with the HTML input that is being put into $rows?

Another thing which is a bit on the side (maybe even off-topic), my $RegistryEntries object, the hashtable of hashtables, is for some reason not possible to access in the way I do it on the two following lines:

Write-Debug $RegistryEntries[$pc].Value[$app]
$currentApp = $RegistryEntries[$pc].Value[$app]

Would anyone be able to tell me why?

To sum up/TL;DR:

  1. Why does my function when trying to add items to an array created inside the script prompt me for permission to do just this in the shell?

  2. With the custom object I’ve described above holding the data I want to display in my HTML table, what am I doing wrong in trying to access it in the above code excerpt?

PS: The script works in the sense that if I sit throughout all the prompts I get in the shell, hitting A + Return all the time, I will get a HTML table of the kind that I want, but all the cells where an application name interstices a computername will say “Application N/A”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:06:53+00:00Added an answer on June 7, 2026 at 4:06 am

    I guess you have your $DebugPreference and/or VerbosePreference set to Inquire which will prompt every time Write-Debug or Write-Verbose are called, respectively:

    Confirm
    Continue with this operation?
    [Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"):
    

    You probably want to set them to Continue instead. Another source might be the -Debug switch.

    Regarding your second question, it’s a little long to explain, but for arguments to commands you have to put such expressions in parentheses:

    Write-Debug ($RegistryEntries[$pc].Value[$app])
    $currentApp = $RegistryEntries[$pc].Value[$app]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a powershell script in which I do the following $somePSObjectHashtables = New-Object
I have the following string expression in a PowerShell script: select count(*) cnt from
I have a PowerShell script: param ( [Parameter(Mandatory=$true)][string]$input, [Parameter(Mandatory=$true)][string]$table ) Write-Host Args: $Args.Length Get-Content
I trying to write a PowerShell script (learning at the same time). I have
I have the following code snippet from my PowerShell script that... Loops through a
I have the following PowerShell script that will parse some very large file for
I have a powershell script with the following code in it... $appdir = Split-Path
I am currently trying to write a little powershell script (I have no experience
I have the following tiny PowerShell script that's meant to kill some certain processes
I have the following snippet of PowerShell script in my profile: . (join-path (split-path

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.