none
need help creating a powershell script to call a list of networked servers and to find a file in each RRS feed

  • Question

  • need help creating a powershell script to call a list of networked servers and to find a file in each. This should search in all servers irrespective of model, architecture and OS version and in elevated mode and should be able to tackle UAC settings.  :)

    Could any expert help ?


    Regards, Vivek Nambiar

    Tuesday, April 29, 2014 9:18 AM

Answers

  • First, a list of requirements you want to accomplish is not a scripting question. It sounds more like a "I want for someone to write the code for me" question.

    Second, saying that something "does not work" isn't very useful. When you say that something didn't work, you have to say precisely how it did not work.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, May 14, 2014 4:51 PM
    Moderator

All replies

  • THis is a very basic Windows issue.  Just search.

    Get-ChildItem \\server\c$\* -include file.ext -recurse

    If you prefer WMI

    Get-WmiObject Cim_DataFile -Filter 'FileName="filename" AND Extension="ext"' -computer remotepc


    ¯\_(ツ)_/¯

    Tuesday, April 29, 2014 9:32 AM
  • Hi Thanks for the reply. However this does not work . First one works for local system but when try for remote it hangs. Second one will not work in my ENV.

    Regards, Vivek Nambiar


    Wednesday, May 14, 2014 4:46 PM
  • First, a list of requirements you want to accomplish is not a scripting question. It sounds more like a "I want for someone to write the code for me" question.

    Second, saying that something "does not work" isn't very useful. When you say that something didn't work, you have to say precisely how it did not work.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, May 14, 2014 4:51 PM
    Moderator
  • Hi Thanks for the reply. However this does not work

    Regards, Vivek Nambiar

    What doesn't work.  My computer works fine.  I also have a working phone.  I bet you watch works.  What is it that does not work?  I have run out of guesses.

    All code posted requires you to be an Administrator on the system being scanned.  If you are not a trained technician you will likeil not be able to understand what we are showing you.  In that case you might want to call you system admin or someone who is a technician to help you.


    ¯\_(ツ)_/¯

    Wednesday, May 14, 2014 4:51 PM
  • Hi , If someone has knowledge on how to write a script, why should he waste time asking such qustions ? Anyway thanks for your efforts.


    Regards, Vivek Nambiar

    Wednesday, May 14, 2014 5:05 PM
  • It does not stop even if you try for a single remote server. I am trying this .. $value = Get-childItem -recurse -path \\MC0R2A8C\c$\* -include openssl.exe


    Regards, Vivek Nambiar

    Wednesday, May 14, 2014 5:07 PM
  • It does not stop even if you try for a single remote server. I am trying this .. $value = Get-childItem -recurse -path \\MC0R2A8C\c$\* -include openssl.exe


    Regards, Vivek Nambiar

    As I posted it is very slow use the one I posted with WMI.  It is much faster.

    Get-WmiObject Cim_DataFile -Filter 'FileName="openssl" AND Extension="exe"' -computer MC0R2ABC

    I will tell you know that the web sites that have that problem have all been fixed.  This is only an issue on web servers.  If you do not have a web server then the openssl issue will not exist.  Look for other threads here on this.  The issue was addressed about a month ago in this forum.

    Notice how when you provide useful information about what you are doing we can actually be somewhat helpful.  We cannot guess what you want and we cannot see your screen.  You need to give accurate information and ask specific questions.


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, May 14, 2014 5:48 PM
    Wednesday, May 14, 2014 5:46 PM
  • Well you are running an get-childitem on the whole c drive of the server, this is running until it has searched each file for your filter. This will take time even on my local machine. If you can narrow down the search path it will complete a lot faster.

    If you know the complete path to your file you could just use test-path.

    Test-Path \\server\C$\pathtofile\openssl.exe

    Wednesday, May 14, 2014 5:47 PM
  • Well you are running an get-childitem on the whole c drive of the server, this is running until it has searched each file for your filter. This will take time even on my local machine. If you can narrow down the search path it will complete a lot faster.

    If you know the complete path to your file you could just use test-path.

    Test-Path \\server\C$\pathtofile\openssl.exe

    The problem with running over the network with Get-ChildItem is that it brings every single file over the network.  This is very slow and can take forever on a slow network.  WMI will search the whole system and only return what you asked for.  It will always be faster even if you use a full path.  You will find that it is even faster if the search service is running.  On Windows 7 and later all systems I have are running the search service and indexer.  The query results on 1 1+Tb drive are almost instantaneous.  On an XP system with now index the spe3ed is still very fast.  About 3 minutes on a full 350Gb drive that is very slow and very old.

    As I pointed out above.  This is unnecessary if you do not have an Apache or other open source web server.


    ¯\_(ツ)_/¯

    Wednesday, May 14, 2014 5:54 PM
  • Second one will not work in my ENV.

    Regards, Vivek Nambiar


    Just to share some of my experiences that i have been collecting while playing with both possibilities and the Measure-Command cmdlet:

    remote Get-Childobject: 4-5 minutes
    local Get-Childobject: 30 seconds
    remote WMI: 4-5 seconds
    local WMI: 4-5 seconds

    So if the WMI solution is not working for you could try the Get-Childobject with the Invoke-Command cmdlet.

    Invoke-Command -ScriptBlock {Get-ChildItem C:\ -Include test.txt -Recurse} -ComputerName remoteserver
    That will be a lot faster than running the Get-Childobject through the network, e. g. for my testsystem 30 seconds to 5 minutes.

    Wednesday, May 14, 2014 8:39 PM
  • Second one will not work in my ENV.


    Regards, Vivek Nambiar


    Just to share some of my experiences that i have been collecting while playing with both possibilities and the Measure-Command cmdlet:

    remote Get-Childobject: 4-5 minutes
    local Get-Childobject: 30 seconds
    remote WMI: 4-5 seconds
    local WMI: 4-5 seconds

    So if the WMI solution is not working for you could try the Get-Childobject with the Invoke-Command cmdlet.

    Invoke-Command -ScriptBlock {Get-ChildItem C:\ -Include test.txt -Recurse} -ComputerName remoteserver
    That will be a lot faster than running the Get-Childobject through the network, e. g. for my testsystem 30 seconds to 5 minutes.

    Invoke-Command assumes advance knowledge of system.  Our OP is a newbie and does not have a configured remoting setup. That would be good.  It would still not be as fast as WMI. Why?  Ask and I will try to 'splain it.


    ¯\_(ツ)_/¯

    Thursday, May 15, 2014 12:09 AM