I am working on a PowerShell script to create pivot tables in Excel, for the first time. I have a field that has dates in it and I want to group on that field in the pivot table on the Days and the Months, but I cannot find how to do that through PowerShell.
#### Pivot Table
$xlPivotTableVersion15 = 5 # Excel 2013
$xlPivotTableVersion12 = 3 # Excel 2007
$xlPivotTableVersion10 = 1
$xlSum = -4157
$xlAverage = -4106
$xlCount = -4112
$xlRight = -4152
$xlDescending = 2
$xlDatabase = 1 # this just means local sheet data
$xlHidden = 0
$xlRowField = 1
$xlColumnField = 2
$xlPageField = 3
$xlDataField = 4
$xlDirection = [Microsoft.Office.Interop.Excel.XLDirection]
$range1 = $ExcelWorksheet.Range("C1")
$range1 = $ExcelWorksheet.Range($range1,$range1.End($xlDirection::xlDown))
$range2 = $ExcelWorksheet.Range("M1")
$range2 = $ExcelWorksheet.Range($range2,$range2.End($xlDirection::xlDown))
$selection = $ExcelWorksheet.Range($range1, $range2)
$PivotTable = $ExcelWorkbook.PivotCaches().Create($xlDatabase, $selection, $xlPivotTableVersion15)
$PivotTable.CreatePivotTable("R1C15","Tables1") | Out-Null
[void]$ExcelWorksheet.Select()
$ExcelWorksheet.Cells.Item(1,15).Select()
$ExcelWorkbook.ShowPivotTableFieldList = $true
$PivotFields = $ExcelWorksheet.PivotTables("Tables1").PivotFields("ASSIGNEDEMPID")
$PivotFields.Orientation = $xlRowField
#$PivotFields.Orientation = $xlDataField
$PivotFields.Position = 1
$PivotFields = $ExcelWorksheet.PivotTables("Tables1").PivotFields("CREATEDTIME")
$PivotFields.Orientation = $xlRowField
#$PivotFields.Orientation = $xlDataField
$PivotFields = $ExcelWorksheet.PivotTables("Tables1").PivotFields("TELNO")
$PivotFields.Orientation = $xlRowField
$PivotFields.Orientation = $xlDataField
#### Pivot Table - End