Powershell 脚本将信息导出到 CSV 文件

Powershell 脚本将信息导出到 CSV 文件

我正在尝试弄清楚为什么商务电话未出现在报告中。如能提供任何帮助,我将不胜感激

    # Connect to AzureAD
Connect-AzureAD

# Get all Azure AD users
$AzADUsers = Get-AzureADUser -All $true

# Display progress bar
$progressCount = 0
for ($i = 0; $i -lt $AzADUsers.Count; $i++) {

    Write-Progress `
        -Id 0 `
        -Activity "Retrieving User " `
        -Status "$progressCount of $($AzADUsers.Count)" `
        -PercentComplete (($progressCount / $AzADUsers.Count) * 100)

    $progressCount++

}

# Create list
$AzADUsers | Sort-Object GivenName | Select-Object `
@{Label = "First name"; Expression = { $_.GivenName } },
@{Label = "Last name"; Expression = { $_.Surname } },
@{Label = "Display name"; Expression = { $_.DisplayName } },
@{Label = "User type"; Expression = { $_.UserType } },
@{Label = "E-mail"; Expression = { $_.Mail } },
@{Label = "Job Title"; Expression = { $_.JobTitle } },
@{Label = "Company"; Expression = { $_.CompanyName } },
@{Label = "Manager"; Expression = { (Get-AzureADUserManager -ObjectId $_.ObjectId).DisplayName } },
@{Label = "Office"; Expression = { $_.PhysicalDeliveryOfficeName } },
@{Label = "Employee ID"; Expression = { $_.ExtensionProperty.employeeId } },
@{Label = "Dirsync"; Expression = { if (($_.DirSyncEnabled -eq 'True') ) { 'True' } Else { 'False' } } },
@{Label = "Business Phone"; Expression = { if ($_.BusinessPhones) { $_.BusinessPhones[0] } else { "N/A"} } },
@{Label = "Mobile"; Expression = { $_.Mobile } },
@{Label = "Account status"; Expression = { if (($_.AccountEnabled -eq 'True') ) { 'Enabled' } Else { 'Disabled' } } } |

# Export report to CSV file
Export-Csv -Encoding UTF8 -Path "c:\scripts\Users.csv" -NoTypeInformation

答案1

@{Label = "Business Phone"; Expression = { $users = Get-MsolUser -All $users |Select-Object -ExpandProperty PhoneNumber} },

我发现这有效

相关内容