Run script on two remote servers

Hey Experts.  As a continued evolution of this script, I need this script I to run on the two servers listed.  Since the results will be listed in the log file, I need the server name included in the results.

Script:
$in = $false
$pattern = (get-date (get-date).AddDays(-1) -f 'MM\/dd\/yyyy') + ' * --- SCHEDULEREC STATUS BEGIN*'
$(
  switch -wildcard -file C:\tools\logs\dsmsched.log
  {
    $pattern   { $in = $true }
    '*SCHEDULEREC STATUS END*'  { $in = $false }
    default { $_ | ? { $in } }
  }
)

Open in new window


Servers:
\\serverA
\\serverB
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:
Something like that?
$ServerList = 'ServerA', 'ServerB'

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

Open in new window

0
samiam41Author Commented:
Here is what I have for the script:
$ServerList = 'w2k8sentry01', 'w2k12share01'

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

Open in new window


Which gives me this error (not sure what I didn't add to the script):

obda_script_error.png
0
oBdACommented:
Do you have enough permissions to access C$ on the remote machines?
Did you run that from an elevated Powershell console?
0
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

samiam41Author Commented:
Full control on all remote servers and I ran the script (obda.ps1) from a PS console which I opened as an admin.

From the ps prompt, if I type out \\w2k12share01\c$\program files\tivoli\tsm\baclient\dsmsched.log, it opens
0
samiam41Author Commented:
From the prompt, I can also get the log file to open when using:
get-content -path "\\w2k12share01\c$\Program Files\Tivoli\TSM\baclient\dsmsched.log"

Open in new window

0
oBdACommented:
Can't reproduce, sorry. Does this work:
$ServerList = 'w2k8sentry01', 'w2k12share01'

$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)\C$\Program Files\Tivoli\TSM\baclient\dsmsched.log") {
		$Pattern					{$in = $true}
		'*SCHEDULEREC STATUS END*'	{$in = $false}
		default						{If ($in) {$_}}
	}
} | Set-Content -Path C:\tools\logs\new_test.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:
Yep!  The get-content path was the key.  Thank you!
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.