Windows 7 Search folders for a bunch of part numbers

Discussion in 'General Computing' started by rc0213, Oct 14, 2016.

  1. rc0213

    rc0213 New Member

    Joined:
    Oct 13, 2016
    Messages:
    6
    Likes Received:
    0
    I have a lot of part numbers that are spread all over the network. I would like to know if there is a macro that I can use to copy and paste all these numbers and have the macro search for these numbers. Is this possible?
     
  2. Neemobeer

    Neemobeer Windows Forum Team
    Staff Member

    Joined:
    Jul 4, 2015
    Messages:
    2,415
    Likes Received:
    366
    Powershell could do that, but you would need to give more details to write a script. Are these files on server shares, how are the files named how do you know a file will have a part number, what kind of files are they stored in. Are all the part numbers formatted the same
     
  3. rc0213

    rc0213 New Member

    Joined:
    Oct 13, 2016
    Messages:
    6
    Likes Received:
    0
    These files are all on different network drives. They all have the basic same format.
     
  4. Neemobeer

    Neemobeer Windows Forum Team
    Staff Member

    Joined:
    Jul 4, 2015
    Messages:
    2,415
    Likes Received:
    366
    So something like this may work, you would need to tweak the server shares and pattern

    Code:
    # Define an array with the server shares to look ing
    $server_shares = @("\\server1\share1","\\server2\share2")
    
    # Local repository to collect the files into
    $local_repo = "$env:USERNAME\Documents\Repo"
    
    $pattern = "*FILENAME*.txt*"
    $map_drive = ""
    
    # Create the repo if it doesn't exist
    If (-not (Test-Path -Path $local_repo))
    {
        New-Item -Path $local_repo -ItemType Directory
    }
    
    # D - Z
    # Find an unused drive letter
    $char_index = 68..91
    foreach($index in $char_index)
    {
        $letter = [char]$index
        if (-not (Test-Path "$($letter):\"))
        {
            $map_drive = "$($letter)"
            break
        }   
    }
    
    # Connect to each share and find files to copy
    foreach($server in $server_shares)
    {
        $files = @()
    
        New-PSDrive -Name $letter -PSProvider FileSystem -Root $server
        $files += @((Get-ChildItem -Path "$($letter):\" -Filter $pattern -Recurse))
    
        foreach($file in $files)
        {
            Copy-Item -Path $file.FullName -Destination $local_repo
        }
    
        Start-Sleep -Seconds 2
        Remove-PSDrive $letter
        Start-Sleep -Seconds 2
    }
     
  5. BIGBEARJEDI

    BIGBEARJEDI Honorable Member
    Premium Supporter

    Joined:
    Jan 28, 2013
    Messages:
    1,803
    Likes Received:
    219
    If the network you are describing is a Domain-based network such as Windows Server 2008, 2012, etc. you would need to have a Domain user login with proper rights to search all the shared drives on all the different servers on the networks as well as across different subnets and different physical locations. The only way you could be certain you were able to search all your mapped drive locations would be if you had an aliased user login with temporary Admin equivalent permissions for the Global domain. This is usually only available from the Domain admin or owner of the Global network (usually an IT manager or above).

    Hope neemo's script works for you; looks pretty promising.
    <<<BIGBEARJEDI>>>
     
  6. Neemobeer

    Neemobeer Windows Forum Team
    Staff Member

    Joined:
    Jul 4, 2015
    Messages:
    2,415
    Likes Received:
    366
    Yup that is certainly correct BBJ. If the user runs the above script logged in as a domain user with proper access they should be ok.

    If you do need to run this as a different user you can add the following to the above script. After defining the $server_shares add the line
    $creds = (Get-Credentials) and append -Credentials $creds to the line
    New-PSDrive -Name $letter -PSProvider FileSystem -Root $server -Credentials $creds

    This will generate a pop-up asking for credentials and you can enter them as username: domain\domainuser and that users password
     
  7. rc0213

    rc0213 New Member

    Joined:
    Oct 13, 2016
    Messages:
    6
    Likes Received:
    0
    Thanks for all your help!
     

Share This Page

Loading...