我正在處理 powershell 腳本,我正在嘗試從我的 csv 檔案中僅讀取“用戶”列,然后將其轉換為他們的 Microsoft AzureAD 顯示名稱,但不確定如何執行此操作,因此如果我能得到,我將不勝感激任何幫助或建議。
我的 csv 檔案看起來像這樣
C:\AuditLogSearch$($CurDate) Final Audit-Log-Records.csv
User Date &Time Activity
-------------------------------------
abc@gmail.com 11/22/2021 play soccer
kei@gmail.com 10/22/2021 play football
def@gmail.com 11/22/2021 play soccer
def@gmail.com 09/22/2021 play Baseball
xyz@gmail.com 08/22/2021 play soccer
klm@gmail.com 19/22/2021 play football
function Connect-AzureActiveDirectory {
$pso = New-PSSessionOption -SkipCACheck:$true -SkipCNCheck:$true -SkipRevocationCheck:$true -OperationTimeout 180000 -ProxyAccessType AutoDetect
Connect-AzureAD -Credential $credential -ConnectionUri https://outlook.office365.com/PowerShell-LiveID -PSSessionOption $pso
$host.ui.RawUI.WindowTitle = "Exchange Online - NAM Production Beta MFA"
Write-Host "Connected to Azure AD"
}
function Convert-UserColumn {
$ImportFile = "C:\AuditLogSearch\$($CurDate) Final Audit-Log-Records.csv"
$ExportFile = "C:\AuditLogSearch\FinalFile.csv"
// I'm struggling with the logic here
$list = @() foreach ($u in $ImportFile.User) {
$list = Get-AzureDisplayName -mail $u
}
Get-AzureADUser -ObjectId
| Export-Csv $ExportFile -NoTypeInformation
}
嘗試制作最終匯出 csv 檔案應如下所示 C:\AuditLogSearch\FinalFile.csv
User Date &Time Activity
-------------------------------------
Jonathan Sparkle 11/22/2021 play soccer
Randy Mod 10/22/2021 play football
Hanah P 11/22/2021 play soccer
Hanah P 09/22/2021 play Baseball
Cristiano Ronaldo 08/22/2021 play soccer
Leo Messi 19/22/2021 play football
uj5u.com熱心網友回復:
您可以只更新User匯入的 CSV 屬性上的值,無需創建一個$list = @()來保存結果。
假設$ImportFile.User包含有效UserPrincipalNames的 Azure AD 用戶,您正在努力處理的部分將如下所示(絕對不需要函式):
$ImportFile = Import-Csv "C:\AuditLogSearch\$($CurDate) Final Audit-Log-Records.csv"
$ExportFile = "C:\AuditLogSearch\FinalFile.csv"
foreach ($u in $ImportFile) {
$u.User = (Get-AzureADUser -ObjectId $u.User).DisplayName
}
$ImportFile | Export-Csv $ExportFile -NoTypeInformation
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/370372.html
