Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Looking for a file

Posted on 2011-02-28
8
Medium Priority
?
372 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
Screencast - Getting to Know the Pipeline

916 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