Added Export-MultipleExcelSheets

This commit is contained in:
Doug Finke
2015-04-10 10:02:33 -04:00
parent 90d4379a21
commit e6c8380c58
2 changed files with 37 additions and 1 deletions

View File

@@ -144,3 +144,29 @@ function Export-Excel {
if($Show) {Invoke-Item $Path}
}
}
function Export-MultipleExcelSheets {
param(
[Parameter(Mandatory)]
$Path,
[Parameter(Mandatory)]
[hashtable]$InfoMap,
[Switch]$Show,
[Switch]$AutoSize
)
$parameters = @{}+$PSBoundParameters
$parameters.Remove("InfoMap")
$parameters.Remove("Show")
$parameters.Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)
foreach ($entry in $InfoMap.GetEnumerator()) {
Write-Progress -Activity "Exporting" -Status "$($entry.Key)"
$parameters.WorkSheetname=$entry.Key
& $entry.Value | Export-Excel @parameters
}
if($Show) {Invoke-Item $Path}
}

10
test.ps1 Normal file
View File

@@ -0,0 +1,10 @@
cls
$DataToGather = @{
Processes = {ps}
Services = {gsv}
Files = {dir -File}
Albums = {(Invoke-RestMethod http://www.dougfinke.com/powershellfordevelopers/albums.js)}
}
Export-MultipleExcelSheets -Show -AutoSize .\testExport.xlsx $DataToGather