Skip to content

Commit

Permalink
Fix for #12
Browse files Browse the repository at this point in the history
  • Loading branch information
prashant3535 committed Dec 5, 2018
1 parent ff39f1e commit fe53954
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions ADRecon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4289,16 +4289,33 @@ Function Get-ADRExcelPivotTable

# xlDatabase = 1 # this just means local sheet data
# xlPivotTableVersion12 = 3 # Excel 2007
If ($SrcSheetName -eq "Computer SPNs")
$PivotFailed = $false
Try
{
$rows = $SrcWorksheet.UsedRange.Rows.Count
$ComputerSPNsRange = $SrcWorksheet.Range("A1:B"+$rows)
$PivotCaches = $workbook.PivotCaches().Create([Microsoft.Office.Interop.Excel.XlPivotTableSourceType]::xlDatabase, $ComputerSPNsRange, [Microsoft.Office.Interop.Excel.XlPivotTableVersionList]::xlPivotTableVersion12)
$PivotCaches = $workbook.PivotCaches().Create([Microsoft.Office.Interop.Excel.XlPivotTableSourceType]::xlDatabase, $SrcWorksheet.UsedRange, [Microsoft.Office.Interop.Excel.XlPivotTableVersionList]::xlPivotTableVersion12)
}
Else
Catch
{
$PivotCaches = $workbook.PivotCaches().Create([Microsoft.Office.Interop.Excel.XlPivotTableSourceType]::xlDatabase, $SrcWorksheet.UsedRange, [Microsoft.Office.Interop.Excel.XlPivotTableVersionList]::xlPivotTableVersion12)
$PivotFailed = $true
Write-Verbose "[EXCEPTION] $($_.Exception.Message)"
}
If ( $PivotFailed -eq $true )
{
$rows = $SrcWorksheet.UsedRange.Rows.Count
If ($SrcSheetName -eq "Computer SPNs")
{
$PivotCols = "A1:B"
}
ElseIf ($SrcSheetName -eq "Users")
{
$PivotCols = "A1:AI"
}
$UsedRange = $SrcWorksheet.Range($PivotCols+$rows)
$PivotCaches = $workbook.PivotCaches().Create([Microsoft.Office.Interop.Excel.XlPivotTableSourceType]::xlDatabase, $UsedRange, [Microsoft.Office.Interop.Excel.XlPivotTableVersionList]::xlPivotTableVersion12)
Remove-Variable Columns
Remove-Variable UsedRange
}
Remove-Variable PivotFailed
$PivotTable = $PivotCaches.CreatePivotTable($PivotLocation,$PivotTableName)
# $workbook.ShowPivotTableFieldList = $true

Expand Down Expand Up @@ -5347,8 +5364,7 @@ Function Export-ADRExcel
}

$row++
$worksheet.Cells.Item($row, 1) = "© ADRecon 2018"
$workbook.Worksheets.Item(1).Hyperlinks.Add($workbook.Worksheets.Item(1).Cells.Item($row,2) , "https://github.com/adrecon/ADRecon", "" , "", "github.com/adrecon/ADRecon") | Out-Null
$workbook.Worksheets.Item(1).Hyperlinks.Add($workbook.Worksheets.Item(1).Cells.Item($row,1) , "https://github.com/adrecon/ADRecon", "" , "", "github.com/adrecon/ADRecon") | Out-Null

$worksheet.UsedRange.EntireColumn.AutoFit() | Out-Null

Expand Down

0 comments on commit fe53954

Please sign in to comment.