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?
 
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
 
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
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
oBdACommented:
Do you have enough permissions to access C$ on the remote machines?
Did you run that from an elevated Powershell console?
0
 
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
 
samiam41Author Commented:
Yep!  The get-content path was the key.  Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.