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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:27:48+00:00 2026-06-13T13:27:48+00:00

Ok, am having some issues with my script, they probably are pretty apparent but

  • 0

Ok, am having some issues with my script, they probably are pretty apparent but here is the script. Would greatly appreciate a review of the script with some feedback as why they are broken.

## Script Startup
$Computers = Get-Content .\computers.txt
$Total = $Computers.length
$consoleObject = (Get-Host).UI.RawUI

## Set Variables
$Run = 0
$Successful = 0

# Checks to see if there is a log file already created. If so check number of successful computer ran against, if not, create the log file.
IF ( test-path .\~temp.txt ) {
    $Log = Get-Content .\~temp.txt
    ForEach ($LogLine in $Log) {
    $LogCheck = $LogLine.ToString().Split(",")[2]
        IF ( "$LogCheck" -eq "Successful" ) {
            $Successful += 1
        }
    }
} ELSE {
    add-content .\~temp.txt "Computer Name,Attempts,Last Attempt,Time,Date"
}



while ( "$Completed" -le "$total" ) {
    $Run += 1
    $Time = Get-Date
    $consoleObject.WindowTitle = “Admin Check - $Successful Out Of $Total Successful `| Run`: $Run”

    ForEach ($Computer in $Computers) {
        IF ( Select-String .\~temp.txt -pattern "$Computer" -quiet ) {
            $LogUpdate = Select-String .\~Temp.txt -pattern $Computer
            $Attempts = $LogUpdate.ToString().Split(",")[1]
            $Result = $LogUpdate.ToString().Split(",")[3]
        } ELSE {
            add-content .\~temp.txt "$Computer,0,Not Checked,Not Run Yet,Not Run Yet"
            $Attempts = ""
            $Result = ""
        }

        IF ( "$Result" -eq "Successful") {
            write-output "$Computer Already Completed"
        } ELSE {
            IF ( test-connection $Computer -quiet ) {
                # Command Here
                $Successful += 1
                $IsOn = "True"
            } ELSE {
                $IsOn = "False"
            }
            $Attempts += 1
        }
        ( Get-Content .\~temp.txt ) | Foreach-Object {$_ -replace "$Computer,.*", ($Computer + "," + $Attempts + "," + $IsOn + "," + $Result + "," + $Time.ToShortTimeString() + "," + $Time.ToShortDateString())} | Set-Content .\~temp.txt
    }
}

~temp.txt

Computer Name,Attempts,Last Attempt Result,Time,Date
52qkkgw-94210jv,11111111111111,False,,8:47 PM,10/27/2012
HELLBOMBS-PC,11111111111111111111111111111111111111111111111111111111111,True,,8:47 PM,10/27/2012
52qkkgw-94210dv,11111111111111111111111111111111111111111111111111111111,False,,8:46 PM,10/27/2012

Current Issue:
– Doesn’t actually stop when successful equals total.
– doesn’t check result vs successful so keeps redoing all comps forever.
– The Attempts tab just keeps adding 1 to the last time or something, so it makes some weird continuous “1111” thing.
Probably more just havn’t noticed them yet.

  • 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-13T13:27:49+00:00Added an answer on June 13, 2026 at 1:27 pm

    Here’s working code:

    clear
    ## Script Startup
    $Computers = Get-Content \computers.txt
    cd c:\pst
    $Total = $Computers.length
    $consoleObject = (Get-Host).UI.RawUI
    
    ## Set Variables
    $Run = 1
    $Successful = 0
    
    # Checks to see if there is a log file already created. If so check number of successful         computer ran against, if not, create the log file.
    IF ( test-path .\~temp.txt ) {
    $Log = Get-Content .\~temp.txt
    ForEach ($LogLine in $Log) {
    $LogCheck = $LogLine.ToString().Split(",")[2]
        IF ( "$LogCheck" -eq "Successful" ) {
            $Successful += 1
        }
    }
    } ELSE {
    add-content .\~temp.txt "Computer Name,Attempts,Last Attempt,Time,Date"
    }
    
    while ( $Run -ne $total ) {
    $Run += 1
    $Time = Get-Date
    $consoleObject.WindowTitle = “Admin Check - $Successful Out Of $Total Successful `| Run`: $Run”
    
    ForEach ($Computer in $Computers) {
        IF ( Select-String .\~temp.txt -pattern "$Computer" -quiet ) {
            $LogUpdate = Select-String .\~Temp.txt -pattern $Computer
            $Attempts = $LogUpdate.ToString().Split(",")[1]
            $Result = $LogUpdate.ToString().Split(",")[3]
        } ELSE {
            add-content .\~temp.txt "$Computer,0,Not Checked,Not Run Yet,Not Run Yet"
            $Attempts = ""
            $Result = ""
        }
    
        IF ( "$Result" -eq "Successful") {
            write-output "$Computer Already Completed"
        } ELSE {
            IF ( test-connection $Computer -quiet ) {
                # Command Here
                $Successful += 1
                $IsOn = "True"
            } ELSE {
                $IsOn = "False"
            }
            $Attempts += 1
        }
        ( Get-Content .\~temp.txt ) | Foreach-Object {$_ -replace "$Computer,.*", ($Computer + "," + $Attempts + "," + $IsOn + "," + $Result + "," + $Time.ToShortTimeString() + "," + $Time.ToShortDateString())} | Set-Content .\~temp.txt
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some issues using mysqli to execute a script with SELECT,DELETE,INSERT and UPDATE
I'm having some IE7 (and presumably IE6) issues with the script. <script type=text/javascript> $(document).ready(function(){
I'm having some issues with my code maybe you could help? Jquery: [updated] <script>
Ok, So I'm writing a task organizer script and I'm having some issues with
I'm having some issues with a content script being injected to the same page
I have a bash script I am having some issues with concatenating 2 variables
Having some issues getting my head around the differences between UTF-8, UTF-16, ASCII and
Having some issues with the ... in ObjectiveC. I'm basically wrapping a method and
I am having some issues passing commands through to flash from javascript. My code
I am having some issues with multiple form submissions with a jQuery/ajax form. I

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.