Solved

Looking for a file

Posted on 2011-02-28
8
365 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
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

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to pick specific file from ftp 13 37
replace in file 2 18
Vmware PowerCLI script 4 64
powershell script stop start resource remotely 6 32
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

14 Experts available now in Live!

Get 1:1 Help Now