Skip to content

Commit 95efae9

Browse files
authored
Major Update!
1 parent eefcef9 commit 95efae9

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

Powershell/Clear-SCOMCache.ps1

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ PROCESS
155155
)
156156
BEGIN
157157
{
158+
trap
159+
{
160+
Write-Host $error[0] -ForegroundColor Yellow
161+
}
158162
Function Time-Stamp
159163
{
160164
$TimeStamp = Get-Date -Format "MM/dd/yyyy hh:mm:ss tt"
@@ -450,26 +454,55 @@ PROCESS
450454
}
451455
else
452456
{
453-
try
457+
if ($All)
454458
{
455-
Invoke-Command -ErrorAction Stop -ComputerName $server -ArgumentList $InnerClearSCOMCacheFunctionScript -ScriptBlock {
456-
Param ($script)
457-
. ([ScriptBlock]::Create($script))
458-
return Inner-ClearSCOMCache
459+
try
460+
{
461+
Invoke-Command -ErrorAction Stop -ComputerName $server -ArgumentList $InnerClearSCOMCacheFunctionScript -ScriptBlock {
462+
Param ($script)
463+
. ([ScriptBlock]::Create($script))
464+
return Inner-ClearSCOMCache -All
465+
}
459466
}
467+
catch { Write-Host $Error[0] -ForegroundColor Red }
468+
}
469+
else
470+
{
471+
try
472+
{
473+
Invoke-Command -ErrorAction Stop -ComputerName $server -ArgumentList $InnerClearSCOMCacheFunctionScript -ScriptBlock {
474+
Param ($script)
475+
. ([ScriptBlock]::Create($script))
476+
return Inner-ClearSCOMCache
477+
}
478+
}
479+
catch { Write-Host $Error[0] -ForegroundColor Red }
460480
}
461-
catch { Write-Host $Error[0] -ForegroundColor Red }
462481
continue
463482
}
464483
if ($containslocal)
465484
{
466-
Inner-ClearSCOMCache
485+
if ($All)
486+
{
487+
Inner-ClearSCOMCache -All
488+
}
489+
else
490+
{
491+
Inner-ClearSCOMCache
492+
}
467493
$completedlocally = $true
468494
}
469495
}
470496
if ($containslocal -and !$completedlocally)
471497
{
472-
Inner-ClearSCOMCache
498+
if ($All)
499+
{
500+
Inner-ClearSCOMCache -All
501+
}
502+
else
503+
{
504+
Inner-ClearSCOMCache
505+
}
473506
}
474507

475508
}
@@ -480,7 +513,7 @@ PROCESS
480513
}
481514
else
482515
{
483-
<# Edit line 479 to modify the default command run when this script is executed.
516+
<# Edit line 510 to modify the default command run when this script is executed.
484517
485518
Example:
486519
Clear-SCOMCache -Servers Agent1.contoso.com, Agent2.contoso.com, MS1.contoso.com, MS2.contoso.com

0 commit comments

Comments
 (0)