Solved

Looking for a file

Posted on 2011-02-28
8
363 Views
Last Modified: 2012-05-11
I have the following script

[PowerShell]

clear
function check-remotefile {
   
      PROCESS {

 $file = "\\$_\\c$\temp\fulldotnetfx35.exe"  

                                if (test-path $file)

                {

                echo "$_ ,OK"
                  }
            else
            {
                  echo($_ + ",Not Found")
            }
      }
}


Get-Content  c:\DotNetFile.txt | check-remotefile


I need to modify it so that it will tell me when a pc is not reachable. and only if its reachable then is the file there.

0
Comment
Question by:jfgray
  • 4
  • 2
  • 2
8 Comments
 
LVL 5

Expert Comment

by:daveTechSearch
ID: 34999888
You could add something like this to your script


{
	if((get-wmiobject -query "SELECT * FROM Win32_PingStatus WHERE Address='$comp'").statuscode -eq 0)
     	{
	#put what you wish to process here
	#this will process if the pingstatus = 0 above, meaning the system is ONLINE
        }

    #if the system is NOT ONLINE, report as such
    else    
    {write-output "$comp is not reachable"
}

Open in new window

0
 

Author Comment

by:jfgray
ID: 34999894
I could use the following script and include the test file if alive

"Computername   True/False" | out-file -filePath “c:\DotNetResults.txt”

$readfile=get-content "c:\DotNetFile.txt"

$file = "\\$_\\c$\temp\fulldotnetfx35.exe"  

foreach($readf in $readfile)
{
$ALive=get-wmiobject win32_pingstatus -Filter "Address='$readf'" | Select-Object statuscode

if($ALive.statuscode -eq 0)
{ $readf  + " ,Online" | out-file -filePath “c:\DotNetResults.txt”  -append }

else
{$readf  + " ,Offline" | out-file -filePath “c:\DotNetResults.txt”  -append }
}
0
 

Author Comment

by:jfgray
ID: 34999910
How would I include the file check to out put in this line

if($ALive.statuscode -eq 0)
{ $readf  + " ,Online" | out-file -filePath “c:\DotNetResults.txt”  -append }
0
 
LVL 5

Expert Comment

by:daveTechSearch
ID: 35000006
not sure i understand the question?  output to screen, or file?... if to file:

{ write-output "$readf  is Online" | out-file -filePath “c:\DotNetResults.txt”  -append }
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:jfgray
ID: 35000046
This is what I am trying to do

 
{ $readf  + " ,Online ,"  test-path $readf $file)| out-file -filePath “c:\DotNetResults.txt”  -append }

Output would be

PCNAME, Online, File OK
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35000059
Try this code...

clear

Function check-remotefile {
    PROCESS {
    If (Test-Connection -ComputerName "$_" -Quiet){
   
              $_ + "computer responded"
              
              $file = "\\$_\\c$\temp\fulldotnetfx35.exe"
       
              If (test-path $file)        
                  {          
                        echo "$_ ,OK"
                  }
              Else
                  {
                        echo($_ + ",Not Found")
                  }
                  }
           
    Else{
            $_ + "computer did not respond"
        }
        }    
   }
           
           
  Get-Content  c:\File.txt | check-remotefile
0
 

Author Comment

by:jfgray
ID: 35000097
This worked output was like this

B000967435computer responded
B000967435 ,OK

any way to make it look like this

B000967435, computer responded ,OK
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
ID: 35000179
Try this code...

clear

Function check-remotefile {
    PROCESS {
    If (Test-Connection -ComputerName "$_" -Quiet){
   
              $file = "\\$_\\c$\temp\fulldotnetfx35.exe"
       
              If (test-path $file)        
                  {          
                        echo "$_ , Computer Responded - File Found"
                  }
              Else
                  {
                        echo "$_ , Computer Responded - File Not Found"
                  }
                  }
           
    Else{
            $_ + " computer did not respond"
        }
        }    
   }
           
           
  Get-Content  c:\File.txt | check-remotefile
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now