我下载了 Excel 报告,但需要使用 PowerShell 调整一些列的宽度大小。因此,我想知道如何实现。感谢任何帮助或建议。
例如,我想将用户、日期和时间、项目列调整为宽度大小为 30,活动列调整为宽度大小为 50,其他一些列调整为宽度大小为 30 等等...
function Modify-Columns {
$params = @{
AutoSize = $true
# TableName = 'exampleTable'
TableStyle = 'Light9' # => Here you can chosse the Style you like the most
BoldTopRow = $true
WorksheetName = "Audit Log"
PassThru = $true
Path = "C:\AuditLogSearch\$((Get-Date).AddDays(-7).ToString('yyyy-MM-dd')) _ $(Get-Date -Format "yyyy-MM-dd") Audit-Log-Records.xlsx" # => Define where to save it here!
}
Write-Host "Start Modifiying Column and Row using AD DisplayName and Excel Files"
$modifiedFile = Import-Csv "C:\AuditLogSearch\Modified-Audit-Log-Records.csv"
$actionReference = Import-Csv "C:\AuditLogSearch\Reference\eDiscovery_Activities_List.csv"
$result = foreach ($u in $modifiedFile) {
$u.User = (Get-AzureADUser -ObjectId $u.User).DisplayName
New-Object PsObject -Property @{
User = $u.User
# "Search Criteria" = $u."Search Criteria"
"Result Status" = $u."Result Status"
"Date & Time" = $u."Date & Time"
"Search Conditions" = $u."Search Conditions"
"SharePoint Sites" = $u."SharePoint Sites"
"Exchange Public Folders" = $u."Exchange Public Folders"
"Exchange Mailboxes" = $u."Exchange Mailboxes"
"Case Name" = $u."Case Name"
"Search Criteria" = $u."Search Criteria"
"Item" = $u."Item"
"Activity" = if (($actionReference | where-object { $_.Name -eq $u."Activity" }).Value -ne $null) { ($actionReference | where-object { $_.Name -eq $u."Activity" }).Value }
else { $u."Activity" }
} | Select-object -Property User, "Date & Time", "Case Name", "Item", "Activity" , "SharePoint Sites", "Exchange Mailboxes", "Exchange Public Folders" , "Search Criteria", "Result Status"
}
$xlsx = $result | Export-Excel @params
$ws = $xlsx.Workbook.Worksheets[$params.Worksheetname]
$ws.View.ShowGridLines = $false # => This will hide the GridLines on your file
Close-ExcelPackage $xlsx
Write-Host "Finished Modifiying Column and Row using AD DisplayName and Excel Files"
}