Link to home
Start Free TrialLog in
Avatar of samiam41
samiam41Flag for United States of America

asked on

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!
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of samiam41

ASKER

just simply brilliant!  thanks oBdA.  great to see you again.