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 8487309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:11:59+00:00 2026-06-10T21:11:59+00:00

Probably a really simple answer to this one. I am having trouble getting write-progress

  • 0

Probably a really simple answer to this one. I am having trouble getting write-progress to work. I’m fairly sure the issue is with my variables, but I can’t seem to figure out exactly what.

What it does now is bombs on the first run when none of the output files exist. It will tell me:

Write-Progress : Cannot validate argument on parameter 'PercentComplete'. The 300 ar
gument is greater than the maximum allowed range of 100. Supply an argument that is
less than 100 and then try the command again.

The “300 argument” it mentions is a different, random number each time.

Now if I run the script again with the livepcs.txt now existing, it may work and it may not work. Even if it does, the progress bar starts half way across.

This is my first time trying to get write-progress working, so it’s probably something very simple, but I’m not too sure what to look for as of yet. Any advice you could offer would be greatly appreciated.

Final code:

    #Import active directory module
Import-Module active*

#Query AD for all computers by name filter, AND that have an IP listed in AD, store in variable (use line 10)

$PCs = Get-ADComputer -Properties * -Filter {name -like "PCNameDomainPrefix*"} | Where-Object {$_.Ipv4Address -ne $null} | select name,ipv4address

#Dump list of PCs into CSV
$PCs | Export-Csv c:\script\pcs.csv

#Begin foreach loop to see which servers are alive

$i = 0

$livePCs = ForEach($name.name in $PCs) #specify the name string using .name after the variable
    {
    $entry = Test-Connection $name.name -count 1 -quiet #Test-connection pings. The -quiet parameter forces a boolean result (True/False).
    if ($entry -eq "True") {out-file -InputObject $name.name -Encoding ASCII -Width 50 -Append c:\script\livepcs.txt ; Write-Host "$name.name pings"} 
    else { write-host "server $name could not be contacted"}
    $i++
    Write-Progress -activity "Pinging servers . . ." -status "Pinged: $i of $($PCs.Count)" -percentComplete (($i / $PCs.Count)  * 100)
    }


#Announce WMI portion of script, clear host to get rid of status bar    
Clear-Host
Write-Host
Write-Host
Write-Host
Write-Host "Beginning WMI scans. Please wait..."
Write-Host
Write-Host
Write-Host


$livePCs = Get-Content C:\script\livepcs.txt

#Begin foreach loop to query each live machine using WMI. 

$i = 0    

foreach($livePC in $livePCs)
{
   $entry = Get-WmiObject win32_product -computername $livePC -Filter "Name LIKE '%db2%'"

   # do the work
   if ($entry -ne $null)
   {
     $livePc,$entry | out-file c:\script\db2pcs.txt -Encoding ASCII -Width 50 -Append
     Write-Host "$livePC has DB2 installed"
   } 
   else
   {
     write-host "$livePC does not have DB2 installed"
   }

   # update counter and write progress
   $i++
   Write-Progress -activity "Scanning WMI . . ." -status "Scanned: $i of $($livePCs.Count)" -percentComplete (($i / $livePCs.Count)  * 100)
}
  • 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-10T21:12:00+00:00Added an answer on June 10, 2026 at 9:12 pm

    In the final loop, you need to increment your counter after every WMI query, then call Write-Progress using the updated value.

    Cleaned up and nicely formatted:

    $i = 0    
    
    foreach($livePC in $livePCs)
    {
       $entry = Get-WmiObject win32_product -computername $livePC -Filter "Name LIKE '%db2%'"
    
       # do the work
       if ($entry -ne $null)
       {
         $livePc,$entry | out-file c:\script\db2pcs.txt -Encoding ASCII -Width 50 -Append
         Write-Host "$livePC has DB2 installed"
       } 
       else
       {
         write-host "$livePC does not have DB2 installed"
       }
    
       # update counter and write progress
       $i++
       Write-Progress -activity "Scanning WMI . . ." -status "Scanned: $i of $($livePCs.Count)" -percentComplete (($i / $livePCs.Count)  * 100)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a really simple one but I couldn't find the answer. I
This is probably a really dumb question with a simple answer but... I am
I know this probably really simple but Im not sure what im doing wrong...
Probably something really simple, but I'm having some real trouble with it. I have
This is probably a really simple question but one I've never quite worked out
There is probably a really simple answer for this ... I have a project
There is probably a really simple answer to this but, as I'm a Rails
Ok, this probably has a really simple answer, but I've never tried to do
This is probably a really simple jQuery question, but I couldn't answer it after
There is probably a really straightforward answer to this but I'm having difficulty finding

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.