📎 AI Summary:
The thread discusses automating the search of part numbers across distributed network files. The original poster requests a macro or script for this task, and Neemobeer suggests using PowerShell with a sample script, emphasizing the need for proper network access. BIGBEARJEDI notes that domain permissions may be necessary for full access, and Neemobeer provides guidance on running the script with different credentials. The overall sentiment is helpful and collaborative, with a successful resolution implied by the original poster's thanks.
The thread discusses automating the search of part numbers across distributed network files. The original poster requests a macro or script for this task, and Neemobeer suggests using PowerShell with a sample script, emphasizing the need for proper network access. BIGBEARJEDI notes that domain permissions may be necessary for full access, and Neemobeer provides guidance on running the script with different credentials. The overall sentiment is helpful and collaborative, with a successful resolution implied by the original poster's thanks.
Solution
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...
- Joined
- Jul 4, 2015
- Messages
- 8,995
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
- Joined
- Jul 4, 2015
- Messages
- 8,995
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
}
- Joined
- Jan 28, 2013
- Messages
- 2,423
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>>>
Hope neemo's script works for you; looks pretty promising.
<<<BIGBEARJEDI>>>
- Joined
- Jul 4, 2015
- Messages
- 8,995
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
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