Clean up the $Server name in the log file - Powershell

Greetings Experts!  As I continue my path towards a script to monitor my backups, I need this script to pull the log files from servers that have the log files in different directories.  The standard hadn't been set yet.  I figured out how to pull the log files in from the other directories however how can I clean-up the $server name in log file?

$ServerList = 'w2k8sentry01\c$\path\to\file', 'w2k12share01\c$\path\to\file', 'mgt01\e$\path\to\file'

$Pattern = (Get-Date (Get-Date).AddDays(-1) -f 'MM\/dd\/yyyy') + ' * --- SCHEDULEREC STATUS BEGIN*'
$in = $false
$ServerList | ForEach-Object {
	$Server = $_
	"========== $($Server) ============================================================"
	Switch -Wildcard (Get-Content -Path "\\$($Server)") {
		$Pattern					{$in = $true}
		'*SCHEDULEREC STATUS END*'	{$in = $false}
		default						{If ($in) {$_}}
	}
} | Set-Content -Path C:\tools\logs\new_test3.log

Open in new window


[log file]
MGT01\long file name\
w2k8sentry01\long file name\
w2k12share01\long file name\

Thanks for your continued help with this script!
LVL 9
samiam41Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
You can use a Here-String in csv format:
$ServerList = @'
	"Name",			"Path"
	"MGT01",		"E:\Program Files\Tivoli\TSM\baclient\dsmsched.log"
	"w2k8sentry01",	"C:\Program Files\Tivoli\TSM\baclient\dsmsched.log"
	"w2k12share01",	"C:\Program Files\Tivoli\TSM\baclient\dsmsched.log"
'@ | ConvertFrom-Csv

$Pattern = (Get-Date).AddDays(-1).ToString('MM\/dd\/yyyy') + ' * --- SCHEDULEREC STATUS BEGIN*'
$in = $false
$ServerList | ForEach-Object {
	$Server = $_
	"========== $($Server.Name) ============================================================"
	Try {
		Switch -Wildcard (Get-Content -Path "\\$($Server.Name)\$($Server.Path.Replace(':', '$'))" -ErrorAction Stop) {
			$Pattern					{$in = $true}
			'*SCHEDULEREC STATUS END*'	{$in = $false}
			default						{If ($in) {$_}}
		}
	} Catch {
		"ERROR accessing '$($Server.Path)': $($_.Exception.Message)"
	}
} | Set-Content -Path C:\tools\logs\new_test3.log

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
samiam41Author Commented:
just simply brilliant!  thanks oBdA.  great to see you again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.