Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
- $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
- if (Test-Path $scriptPath\servers.csv) {
- $csv = Import-Csv $scriptPath\servers.csv
- } elseif (Test-Path $scriptPath\..\servers.csv) {
- $csv = Import-Csv $scriptPath\..\servers.csv
- } else {
- [Microsoft.VisualBasic.Interaction]::MsgBox("Could not find .\servers.csv or ..\servers.csv.", 16, "Error")
- exit
- }
- $domainUser = [Environment]::UserDomainName+"\"+[Environment]::UserName
- $credentials = Get-Credential -Message "Domain Admin Credentials" -UserName $domainUser
- $uncPath = [Microsoft.VisualBasic.Interaction]::InputBox("Path (no trailing slash): \\server\", "Path", "")
- $uncFileName = [Microsoft.VisualBasic.Interaction]::InputBox("Filename:", "Filename", "")
- $credPassword = $credentials.GetNetworkCredential().Password
- $credUser = $credentials.UserName
- if ($uncPath -and $uncFileName -and $credPassword -and $credUser) {
- Remove-Item $scriptPath\results.txt | Out-Null
- foreach ($line in $csv) {
- $uncServer = $line.Name
- $server = "\\" + $uncServer + "\C$"
- $networkLocation = New-PSDrive -Name "PowerShell" –PSProvider FileSystem –Root $server -Credential $credentials
- try {
- $filename = "\\" + $uncServer + "\" + $uncPath + "\" + $uncFileName
- if (Test-Path $filename) {
- Write-host $uncServer":" $filename
- Add-Content $scriptPath\results.txt $filename
- } else {
- Write-host $uncServer":"
- }
- } catch [System.Exception] {
- Write-host "Error: $_.Exception.Message"
- }
- Remove-PSDrive "PowerShell"
- }
- notepad.exe $scriptPath\results.txt
- } else {
- switch ("") {
- $uncPath {"Path cannot be empty."}
- $uncFileName {"Filename cannot be empty."}
- $credPassword {"Password not supplied."}
- $credUser {"Username not supplied."}
- }
- }
- Read-Host
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement