Added try/catch

This commit is contained in:
dfinke
2018-07-04 18:58:40 -04:00
parent 35553baa05
commit b591a4ab18
17 changed files with 84 additions and 51 deletions

View File

@@ -1,11 +1,13 @@
$file = ".\conditionalTextFormatting.xlsx" try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
rm $file -ErrorAction Ignore
Get-Service | $file = ".\conditionalTextFormatting.xlsx"
Select Status, Name, DisplayName, ServiceName | Remove-Item $file -ErrorAction Ignore
Get-Service |
Select-Object Status, Name, DisplayName, ServiceName |
Export-Excel $file -Show -AutoSize -AutoFilter -ConditionalText $( Export-Excel $file -Show -AutoSize -AutoFilter -ConditionalText $(
New-ConditionalText stop New-ConditionalText stop
New-ConditionalText runn darkblue cyan New-ConditionalText runn darkblue cyan
New-ConditionalText -ConditionalType EndsWith svc wheat green New-ConditionalText -ConditionalType EndsWith svc wheat green
New-ConditionalText -ConditionalType BeginsWith windows darkgreen wheat New-ConditionalText -ConditionalType BeginsWith windows darkgreen wheat
) )

View File

@@ -1,15 +1,17 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$ContainsBlanks = New-ConditionalText -ConditionalType ContainsBlanks $ContainsBlanks = New-ConditionalText -ConditionalType ContainsBlanks
$data = $( $data = $(
New-PSItem a b c (echo p1 p2 p3) New-PSItem a b c (echo p1 p2 p3)
New-PSItem New-PSItem
New-PSItem d e f New-PSItem d e f
New-PSItem New-PSItem
New-PSItem New-PSItem
New-PSItem g h i New-PSItem g h i
) )
$file ="c:\temp\testblanks.xlsx" $file ="c:\temp\testblanks.xlsx"
rm $file -ErrorAction Ignore Remove-Item $file -ErrorAction Ignore
$data | Export-Excel $file -show -ConditionalText $ContainsBlanks $data | Export-Excel $file -show -ConditionalText $ContainsBlanks

View File

@@ -1,4 +1,6 @@
Remove-Item -Path .\test.xlsx -ErrorAction Ignore try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
Remove-Item -Path .\test.xlsx -ErrorAction Ignore
$excel = Get-Process | $excel = Get-Process |
Select-Object -Property Name,Company,Handles,CPU,PM,NPM,WS | Select-Object -Property Name,Company,Handles,CPU,PM,NPM,WS |

View File

@@ -1,11 +1,13 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
$data = $( $data = $(
New-PSItem North 111 (echo Region Amount ) New-PSItem North 111 (echo Region Amount )
New-PSItem East 111 New-PSItem East 111
New-PSItem West 122 New-PSItem West 122
New-PSItem South 200 New-PSItem South 200
@@ -14,11 +16,11 @@ $data = $(
New-PSItem SouthWest 136 New-PSItem SouthWest 136
New-PSItem South 127 New-PSItem South 127
New-PSItem NorthByNory 100 New-PSItem NorthByNory 100
New-PSItem NothEast 110 New-PSItem NothEast 110
New-PSItem Westerly 120 New-PSItem Westerly 120
New-PSItem SouthWest 118 New-PSItem SouthWest 118
) )
#$data | Export-Excel $f -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType AboveAverage) #$data | Export-Excel $f -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType AboveAverage)

View File

@@ -1,6 +1,8 @@
rm .\testExport.xlsx -ErrorAction Ignore try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
ps | where Company | select Company, Name, PM, Handles, *mem* | Remove-Item .\testExport.xlsx -ErrorAction Ignore
Get-Process | Where-Object Company | Select-Object Company, Name, PM, Handles, *mem* |
Export-Excel .\testExport.xlsx -Show -AutoSize -AutoNameRange ` Export-Excel .\testExport.xlsx -Show -AutoSize -AutoNameRange `
-ConditionalFormat $( -ConditionalFormat $(

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
.\GenDates.ps1 | .\GenDates.ps1 |
Export-Excel $f -Show -AutoSize -ConditionalText $( Export-Excel $f -Show -AutoSize -ConditionalText $(

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
.\GenDates.ps1 | .\GenDates.ps1 |
Export-Excel $f -Show -AutoSize -ConditionalText $( Export-Excel $f -Show -AutoSize -ConditionalText $(

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
.\GenDates.ps1 | .\GenDates.ps1 |
Export-Excel $f -Show -AutoSize -ConditionalText $( Export-Excel $f -Show -AutoSize -ConditionalText $(

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
.\GenDates.ps1 | .\GenDates.ps1 |
Export-Excel $f -Show -AutoSize -ConditionalText $( Export-Excel $f -Show -AutoSize -ConditionalText $(

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
.\GenDates.ps1 | .\GenDates.ps1 |
Export-Excel $f -Show -AutoSize -ConditionalText $( Export-Excel $f -Show -AutoSize -ConditionalText $(

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
.\GenDates.ps1 | .\GenDates.ps1 |
Export-Excel $f -Show -AutoSize -ConditionalText $( Export-Excel $f -Show -AutoSize -ConditionalText $(

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
.\GenDates.ps1 | .\GenDates.ps1 |
Export-Excel $f -Show -AutoSize -ConditionalText $( Export-Excel $f -Show -AutoSize -ConditionalText $(

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
.\GenDates.ps1 | .\GenDates.ps1 |
Export-Excel $f -Show -AutoSize -ConditionalText $( Export-Excel $f -Show -AutoSize -ConditionalText $(

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
.\GenDates.ps1 | .\GenDates.ps1 |
Export-Excel $f -Show -AutoSize -ConditionalText $( Export-Excel $f -Show -AutoSize -ConditionalText $(

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
.\GenDates.ps1 | .\GenDates.ps1 |
Export-Excel $f -Show -AutoSize -ConditionalText $( Export-Excel $f -Show -AutoSize -ConditionalText $(

View File

@@ -1,23 +1,25 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx" $f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore Remove-Item $f -ErrorAction Ignore
$data = $( $data = $(
New-PSItem North 111 (echo Region Amount ) New-PSItem North 111 (echo Region Amount )
New-PSItem East 11 New-PSItem East 11
New-PSItem West 12 New-PSItem West 12
New-PSItem South 1000 New-PSItem South 1000
New-PSItem NorthEast 10 New-PSItem NorthEast 10
New-PSItem SouthEast 14 New-PSItem SouthEast 14
New-PSItem SouthWest 13 New-PSItem SouthWest 13
New-PSItem South 12 New-PSItem South 12
New-PSItem NorthByNory 100 New-PSItem NorthByNory 100
New-PSItem NothEast 110 New-PSItem NothEast 110
New-PSItem Westerly 120 New-PSItem Westerly 120
New-PSItem SouthWest 11 New-PSItem SouthWest 11
) )
$data | Export-Excel $f -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType DuplicateValues) $data | Export-Excel $f -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType DuplicateValues)

View File

@@ -1,16 +1,17 @@
ipmo ImportExcel -Force try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\testExport.xlsx"
rm $f -ErrorAction Ignore
function Get-DateOffset ($days=0) { $f = ".\testExport.xlsx"
Remove-Item $f -ErrorAction Ignore
function Get-DateOffset ($days=0) {
(Get-Date).AddDays($days).ToShortDateString() (Get-Date).AddDays($days).ToShortDateString()
} }
$( $(
New-PSItem (Get-DateOffset -1) (Get-DateOffset 1) (echo Start End) New-PSItem (Get-DateOffset -1) (Get-DateOffset 1) (echo Start End)
New-PSItem (Get-DateOffset) (Get-DateOffset 7) New-PSItem (Get-DateOffset) (Get-DateOffset 7)
New-PSItem (Get-DateOffset -10) (Get-DateOffset -1) New-PSItem (Get-DateOffset -10) (Get-DateOffset -1)
) | ) |
Export-Excel $f -Show -AutoSize -AutoNameRange -ConditionalText $( Export-Excel $f -Show -AutoSize -AutoNameRange -ConditionalText $(
New-ConditionalText -Range Start -ConditionalType Yesterday -ConditionalTextColor Red New-ConditionalText -Range Start -ConditionalType Yesterday -ConditionalTextColor Red