Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Looking for a file

Posted on 2011-02-28
8
Medium Priority
?
370 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
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.

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

704 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