Added try/catch. Expanded aliases

This commit is contained in:
dfinke
2018-07-05 16:14:56 -04:00
parent e4fbf7e92e
commit eac352c28a
47 changed files with 204 additions and 136 deletions

View File

@@ -1,3 +1,4 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
ConvertFrom-ExcelToSQLInsert People .\testSQLGen.xlsx

View File

@@ -1,4 +1,4 @@
Import-Module ..\..\ImportExcel.psd1 -Force
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$f = ".\dashboard.xlsx"
Remove-Item $f -ErrorAction Ignore

View File

@@ -1,5 +1,4 @@
Import-Module ..\..\ImportExcel.psd1 -Force
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
ConvertFrom-ExcelToSQLInsert -TableName "Movies" -Path ".\Movies.xlsx" -ConvertEmptyStringsToNull
''

View File

@@ -1,7 +1,9 @@
param ($fibonacciDigits=10)
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$file = "fib.xlsx"
rm "fib.xlsx" -ErrorAction Ignore
Remove-Item "fib.xlsx" -ErrorAction Ignore
$(
New-PSItem 0
@@ -9,7 +11,7 @@ $(
(
2..$fibonacciDigits |
ForEach {
ForEach-Object {
New-PSItem ('=a{0}+a{1}' -f ($_+1),$_)
}
)

Binary file not shown.

View File

@@ -1,3 +1,7 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$xlfile = "$env:temp\testFmt.xlsx"
Get-Process |
Select-Object Company,Handles,PM, NPM|
Export-Excel $xlfile -Show -AutoSize -CellStyleSB {

View File

@@ -1,3 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$xlfile = "$env:temp\testFmt.xlsx"
Remove-Item $xlfile -ErrorAction Ignore
$RandomStyle = {
param(
$workSheet,

View File

@@ -1,2 +1,4 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
Import-Html "http://en.wikipedia.org/wiki/Demographics_of_India" 4

View File

@@ -1 +1,3 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
Import-Html "http://www.science.co.il/PTelements.asp" 1

View File

@@ -1 +1,3 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
Import-Html "https://en.wikipedia.org/wiki/List_of_Star_Trek:_The_Original_Series_episodes" 2

View File

@@ -1,4 +1,6 @@
ColumnChart -Title "Central Limit Theorem" -NoLegend ($(
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
ColumnChart -Title "Central Limit Theorem" -NoLegend ($(
for ($i = 1; $i -le 500; $i++) {
$s = 0
for ($j = 1; $j -le 100; $j++) {

View File

@@ -2,5 +2,7 @@
# Sum up handles by company
# Show the Pie Chart
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
PieChart -Title "Total Handles by Company" `
(Invoke-Sum (Get-Process|Where company) company handles)
(Invoke-Sum (Get-Process | Where-Object company) company handles)

View File

@@ -2,6 +2,8 @@
# Sum up PM by company
# Show the Pie Chart
PieChart -Title "Total PM by Company" `
(Invoke-Sum (Get-Process|Where company) company pm)
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
PieChart -Title "Total PM by Company" `
(Invoke-Sum (Get-Process|Where-Object company) company pm)

View File

@@ -1 +1,3 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
BarChart (.\TargetData.ps1) "A BarChart"

View File

@@ -1 +1,3 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
ColumnChart (.\TargetData.ps1) "A ColumnChart"

View File

@@ -1 +1,3 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
PieChart (.\TargetData.ps1) "A PieChart"

View File

@@ -1,3 +1,5 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$header = echo `
'Date/Time - Peak Brightness (UT)' `
'Latitude (Deg)' `

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
Remove-Item $file -ErrorAction Ignore
$data = $(
New-PSItem 100 -100

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
Remove-Item $file -ErrorAction Ignore
$data = $(
New-PSItem 100 -100

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
Remove-Item $file -ErrorAction Ignore
$data = $(
New-PSItem 1

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
Remove-Item $file -ErrorAction Ignore
$data = $(
New-PSItem 100 -100

View File

@@ -1,7 +1,9 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
Remove-Item $file -ErrorAction Ignore
Get-CimInstance win32_logicaldisk -filter "drivetype=3" |
Select DeviceID,Volumename,Size,Freespace |
Select-Object DeviceID,Volumename,Size,Freespace |
Export-Excel -Path $file -Show -AutoSize -NumberFormat "0"

View File

@@ -1,7 +1,9 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
Remove-Item $file -ErrorAction Ignore
Get-CimInstance win32_logicaldisk -filter "drivetype=3" |
Select DeviceID,Volumename,Size,Freespace |
Select-Object DeviceID,Volumename,Size,Freespace |
Export-Excel -Path $file -Show -AutoSize

Binary file not shown.

View File

@@ -1,6 +1,8 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$file = "sales.xlsx"
rm $file -ErrorAction Ignore
Remove-Item $file -ErrorAction Ignore
$xlPkg = Import-Csv .\sales.csv | Export-Excel $file -PassThru
@@ -10,7 +12,7 @@ $ws.Cells["E1"].Value = "TotalSold"
$ws.Cells["F1"].Value = "Add 10%"
2..($ws.Dimension.Rows) |
ForEach {
ForEach-Object {
$ws.Cells["E$_"].Formula = "=C$_+D$_"
$ws.Cells["F$_"].Formula = "=E$_+(10%*(C$_+D$_))"
}

Binary file not shown.

View File

@@ -1,4 +1,4 @@
Import-Module ..\..\ImportExcel.psd1 -Force
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
Remove-Item .\test1.xlsx -ErrorAction Ignore

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,4 @@
Import-Module ..\..\ImportExcel.psd1 -Force
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$xlFile=".\testPivot.xlsx"
Remove-Item $xlFile -ErrorAction Ignore

View File

@@ -1,3 +1,5 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$plt = New-Plot
$plt.Plot((Get-Range 0 5 .02|%{[math]::Cos(2*[math]::pi*$_)}))
$plt.SetChartSize(800,300)

View File

@@ -1,4 +1,4 @@
 Import-Module -name ImportExcel -Force -Verbose
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$sql = @"
SELECT rootfile.baseName , rootfile.extension , Image.fileWidth AS width , image.fileHeight AS height ,
@@ -14,7 +14,7 @@ $sql = @"
LEFT JOIN AgInternedExifLens LensRef ON LensRef.id_Local = metadata.lensRef
LEFT JOIN AgInternedExifCameraModel Camera ON Camera.id_local = metadata.cameraModelRef
"@
``
#Sql Statement gets 20 columns of data from Adobe lightroom database
#Define a pivot table and chart for total pictures with each lens.

View File

@@ -1,8 +1,8 @@
ipmo C:\Users\mcp\Documents\GitHub\ImportExcel\ImportExcel.psd1 -Force
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
Get-SQL -Session f1 -Excel -Connection C:\Users\mcp\OneDrive\Public\F1\f1Results.xlsx -showtables -Verbose
del .\demo3.xlsx
Remove-Item .\demo3.xlsx
$session = $DbSessions["f1"]
$SQL = "SELECT top 25 DriverName, Count(RaceDate) as Races ,

View File

@@ -1,9 +1,10 @@

$p = ps | select Company, Handles | Export-Excel c:\temp\testBackgroundColor.xlsx -ClearSheet -KillExcel -PassThru
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$p = Get-Process | Select-Object Company, Handles | Export-Excel c:\temp\testBackgroundColor.xlsx -ClearSheet -KillExcel -PassThru
$ws = $p.Workbook.WorkSheets[1]
$totalRows = $ws.Dimension.Rows
Set-Format -Address $ws.Cells["B2:B$($totalRows)"] -BackgroundColor LightBlue
Export-Excel -ExcelPackage $p -show
Export-Excel -ExcelPackage $p -show -AutoSize

View File

@@ -1,6 +1,9 @@
. ..\New-PSItem.ps1
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
rm *.xlsx
#. ..\New-PSItem.ps1
Remove-Item *.xlsx
$(
New-PSItem 12001 Nails 37 3.99 =C2*D2 (echo ID Product Quantity Price Total)

View File

@@ -1,3 +1,5 @@
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
Remove-Item .\testFormula.xlsx -ErrorAction Ignore
@"

View File

@@ -1,6 +1,6 @@
. ..\New-PSItem.ps1
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
rm *.xlsx
Remove-Item *.xlsx
$(
New-PSItem =2%/12 60 500000 "=pmt(rate,nper,pv)" (echo rate nper pv pmt)

View File

@@ -1,4 +1,6 @@
rm *.xlsx
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
Remove-Item *.xlsx
$(
New-PSItem '=Hyperlink("http://dougfinke.com/blog","Doug Finke")' @("Link")

Binary file not shown.

View File

@@ -1,3 +1,7 @@
<#
Revisit I think yahoo deprecated their service
#>
function Get-StockInfo {
param(
$stock,
@@ -7,15 +11,15 @@ function Get-StockInfo {
Process {
if(!$endDate) { $endDate = $startDate}
if (!$endDate) { $endDate = $startDate}
$baseUrl = "http://query.yahooapis.com/v1/public/yql?q="
$q = @"
$baseUrl = "http://query.yahooapis.com/v1/public/yql?q="
$q = @"
select * from yahoo.finance.historicaldata where symbol = "$($stock)" and startDate = "$($startDate.ToString('yyyy-MM-dd'))" and endDate = "$($endDate.ToString('yyyy-MM-dd'))"
"@
$suffix = "&env=store://datatables.org/alltableswithkeys&format=json"
$r=Invoke-RestMethod ($baseUrl + $q + $suffix)
$r.query.results.quote
$suffix = "&env=store://datatables.org/alltableswithkeys&format=json"
$r = Invoke-RestMethod ($baseUrl + $q + $suffix)
$r.query.results.quote
}
}

View File

@@ -1,14 +1,20 @@
$Symbol = "MSFT"
<#
Revisit I think yahoo deprecated their service
#>
. .\Get-StockInfo.ps1
# try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
rm *.xlsx
# $Symbol = "MSFT"
$chart = New-ExcelChart -XRange Date -YRange Volume `
-ChartType ColumnStacked `
-Column 9 -Title "$Symbol Volume"
# . .\Get-StockInfo.ps1
Get-StockInfo $Symbol 11/2 11/30 |
Export-Excel .\stocks.xlsx -Show `
-AutoSize -AutoNameRange `
-ExcelChartDefinition $chart
# Remove-Item *.xlsx -ErrorAction Ignore
# $chart = New-ExcelChart -XRange Date -YRange Volume `
# -ChartType ColumnStacked `
# -Column 9 -Title "$Symbol Volume"
# Get-StockInfo $Symbol 11/2 11/30 |
# Export-Excel .\stocks.xlsx -Show `
# -AutoSize -AutoNameRange `
# -ExcelChartDefinition $chart

BIN
Examples/Stocks/stocks.xlsx Normal file

Binary file not shown.

View File

@@ -1,38 +1,40 @@
$xlfile = "testData.xlsx"
rm *.xlsx
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$r = dir C:\WINDOWS\system32
$xlfile = "testData.xlsx"
Remove-Item *.xlsx
$r = Get-ChildItem C:\WINDOWS\system32
$BySize=@{}
$r | ForEach{ $BySize.($_.extension)+=$_.length }
$r | ForEach-Object{ $BySize.($_.extension)+=$_.length }
$top10BySize = $BySize.GetEnumerator() |
ForEach{ [PSCustomObject]@{Name=$_.key;Size=[double]$_.value} } |
Sort size -Descending |
Select -First 10
ForEach-Object{ [PSCustomObject]@{Name=$_.key;Size=[double]$_.value} } |
Sort-Object size -Descending |
Select-Object -First 10
$top10ByCount = $r.extension |
Group |
Sort count -Descending |
Select -First 10 Name, count
Group-Object |
Sort-Object count -Descending |
Select-Object -First 10 Name, count
$top10ByFileSize = $r |
Sort length -Descending |
Select -First 10 Name, @{n="Size";e={$_.Length}} #,Extension,Path
Sort-Object length -Descending |
Select-Object -First 10 Name, @{n="Size";e={$_.Length}} #,Extension,Path
$top10BySize | Export-Excel $xlfile -WorkSheetname FileInfo -TableName ExtSize
$top10ByCount | Export-Excel $xlfile -WorkSheetname FileInfo -StartRow 13 -TableName ExtCount
$top10ByFileSize | Export-Excel $xlfile -WorkSheetname FileInfo -StartRow 25 -AutoSize -TableName FileSize
$ps = ps | ? Company
$ps = Get-Process | Where-Object Company
$ps |
sort handles -Descending |
select -First 10 company, handles |
Sort-Object handles -Descending |
Select-Object -First 10 company, handles |
Export-Excel $xlfile -WorkSheetname Handles -AutoSize -TableName Handles
$ps |
sort PM -Descending |
select -First 10 company, PM |
Sort-Object PM -Descending |
Select-Object -First 10 company, PM |
Export-Excel $xlfile -WorkSheetname Handles -AutoSize -TableName PM -StartRow 13 -Show

Binary file not shown.

View File

@@ -1,10 +1,11 @@
ipmo .\ImportExcel.psd1 -Force
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
. .\ConvertExcelToImageFile.ps1
$xlFileName = "C:\Temp\testPNG.xlsx"
rm C:\Temp\testPNG.xlsx -ErrorAction Ignore
Remove-Item C:\Temp\testPNG.xlsx -ErrorAction Ignore
$range = @"
Region,Item,Cost

BIN
fib.xlsx Normal file

Binary file not shown.