Solved

Looking for a file

Posted on 2011-02-28
8
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 
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
 

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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