Hi All,
So I'm runnung the below script to be able to retrieve the details of files on a Remote Server at the specified location.
Clear-Host
Set-Location $env:USERPROFILE
Push-Location $env:USERPROFILE
#
# Set Output file Location
#
$OutPutFilename=$env:USERPROFILE+"\Desktop\Filelists.txt"
$ServersFileName=$env:USERPROFILE+"\Desktop\ServerNames.txt"
$ReadDrive=Read-Host "Enter the Drive"
#
# Remove string :\
#
$DriveName=($ReadDrive).Contains(":\")
if ($DriveName=$true)
{
$ReadDrive=$ReadDrive.Remove(1,2)
}
$ReadDirectory=Read-Host "Enter the Directory to List (exclude drive)"
#
# Remove Output file is file already exists
#
if (Test-Path $OutPutFilename)
{
Remove-Item $OutPutFilename
}
$AuthorizedUser=Get-Credential
Get-Content $ServersFilename | ForEach-Object
{
if(-Not(Test-Connection -ComputerName $_ -Count 1 -Quiet))
{
Write-Host Server - $_ `t Is currently down or Unreachable -ForegroundColor White -BackgroundColor Red
return
}
else
{
Write-Host `nServer - $_ `t Is Reachable -ForegroundColor Green -BackgroundColor Black
if (Test-Path -Path \\$_\$ReadDrive$\$ReadDirectory)
{
$GCCount=(Get-Childitem "\\$_\$ReadDrive$\$ReadDirectory" -Filter *.txt).count
if ($GCCount -ge 0)
{
Write-Host Searching.... "\\$_\ReadDrive$\$ReadDirectory"
WriteHost File listing count is $GCCount -ForegroundColor Green -BackgroundColor Black
Get-Childitem "\\$_\$ReadDrive$\$ReadDirectory" -Filter *.txt | select @{n='ComputerName';e={_$}},
FullName, LastAccessTime | select -first 5 | Format-Table -AutoSize | Out-File -Append $OutPutFilename
}
}
else
{
Write-Host "`n$_ - Path Not Found `n" -BackgroundColor Red -ForegroundColor Yellow
}
return
}
}
Invoke-Item $OutPutFilename
I have already made the Filelists.txt and ServerNames.txt available at the specified location (e.g. C:\Users\User_Name\Desktop\Filelists.txt)
The script prompts me for the below values..
Enter the Drive: E:\
Enter the Directory to List (exclude drive): Folder1\Folder2
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
I go ahead and enter the relevant credentials as prompted.
But after this it's prompting me for certain parameters (as below) which I'm not able to figure out :(
cmdlet ForEach-Object at command pipeline position 2
Supply values for the following parameters:
Process[0]:
I'm basically following the inputs from this link and have compiled the script as per the same.
https://www.slideshare.net/mvcp007/how-to-list-files-on-remote-server-powershell
But for the life of me, I'm unable to proceed beyond the above point. Also the expected execution trace mentioned at the above site doesn't mention this behaviour, so I'm currently lost for options. Can someone please add any tips to help me figure out what I'm missing here?
Thank You.
SV