如何使用Powershell将扩展属性从Azure AD导出到CSV

布朗镇

我的目标是将用户列表从Azure AD导出到可以从Python读取的csv文件中。使用以下命令就足够简单了:

Get-MsolUser -All | Select-Object UserPrincipalName, WhenCreated | export-csv c:\try2.csv

但是,如何在输出中包括扩展属性?我试过了:

Get-MsolUser -All | Select-Object UserPrincipalName, WhenCreated, 
    extension_60a1274a0a9d4344bd172d81b06d0f50_MemberNumber | export-csv c:\try2.csv

但这只会导出空白的第三列

我想要的扩展属性在那里(extension_60a1274a0a9d4344bd172d81b06d0f50_MemberNumber),我可以使用以下命令看到它:

$user = Get-AzureADUser -ObjectID [email protected]

然后

Get-AzureADUserExtension -ObjectId $User.ObjectId

哪个输出:

Key                                                     Value
---                                                     -----
odata.metadata                                          https://graph.windows.net/3523a793-0e50-4646...
odata.type                                              Microsoft.DirectoryServices.User
createdDateTime                                         4/23/2020 10:22:17 PM
employeeId                                              12345
onPremisesDistinguishedName
[email protected]                      directoryObjects/7fed7e4a-78be-4e87-9d88...
[email protected]                   image/Jpeg
userIdentities                                          []
extension_60a1274a0a9d4344bd172d81b06d0f50_MemberNumber 19999

但是,如何将所有扩展名属性以及常规属性导出到CSV文件中?我不在乎它是否仅导出我需要的一个扩展属性,还是全部导出-我可以从Python端使用所需的属性。

我已经阅读了许多Microsoft和其他文章,但是找不到如何执行此操作。

非常感谢!

好吧,根据萨蒂亚的出色建议,我正在取得进步。我认为遍历所有用户将它们导出到一个csv文件很容易,但是我出错了……这是当前的:

$all = get-azureaduser -All $true
$all | foreach-object {
$user = $_
#Expanding only the Extension Attributes related to the user and converting the Dictionary to Custom Object so that keys can be accessed through the dot (.) operator
$Extension_Attributes = New-Object Psobject -Property $user.ExtensionProperty 

#Combining the required attributes from the user object and extension_attributes to A single object

$u_properties = [pscustomobject] @{
"UserPrincipalName" = $user.UserPrincipalName 
"Country" = $user.Country 
"Created" = $Extension_Attributes.createdDateTime 
"MemberNumber" = $Extension_Attributes.extension_60a1274a0a9d4344bd172d81b06d0f50_MemberNumber
}

# check
write-host "got $u_properties"

}
Select-object $u_properties | Export-csv -Path c:\ulist.csv -NoTypeInformation -Force

该循环起作用,并且写主机显示每个记录,但是export-csv在文件中不产生任何记录。我也尝试过-append,但阅读它存在一些问题,阻止了它在foreach中工作。

萨蒂亚五世

您可以尝试以下代码段:

据我研究,从计算机中检索数据的可能性可能会略少一些。 Get-MSOLUser

我已利用Get-AzureAD满足您要求的

#Gettting the User from the AAD
$user= Get-AzureADUser -ObjectID [email protected]

#Expanding only the Extenstion Attributes related to the user and converting the Dictionary to Custom Object so that keys can be accessed through the dot (.) operator
$Extension_Attributes = New-Object Psobject -Property $user.ExtensionProperty 

#Combining the required attributes from the user object and extension_attributes to A single object
$u_properties = [pscustomobject] @{
"UserPrincipal" = $user.UserPrincipalName
"Name" = $user.Country
"Created" = $Extension_Attributes.createdDateTime
}
#if you need more attributes you can accordingly


#Exporting the object to a file in an append fashoin
$u_properties | Export-Csv -Path D:\File.csv -Append -NoTypeInformation

样本输出

在此处输入图片说明

更新的代码

$all = get-azureaduser -All $true
$all | foreach-object {
$user = $_
#Expanding only the Extension Attributes related to the user and converting the Dictionary to Custom Object so that keys can be accessed through the dot (.) operator
$Extension_Attributes = New-Object Psobject -Property $user.ExtensionProperty 

#Combining the required attributes from the user object and extension_attributes to A single object

$u_properties = [pscustomobject] @{
"UserPrincipalName" = $user.UserPrincipalName 
"Country" = $user.Country 
"Created" = $Extension_Attributes.createdDateTime 
"MemberNumber" = $Extension_Attributes.extension_60a1274a0a9d4344bd172d81b06d0f50_MemberNumber
}

# check
write-host "got $u_properties"

 $u_properties | Export-csv -Path D:\File3.csv -NoTypeInformation -Force -Append

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使用 PowerShell 将 AD 用户属性导出到 .csv 文件?

来自分类Dev

从CSV导入的Powershell脚本,检查AD帐户状态,然后导出到CSV

来自分类Dev

将所有Azure AD组及其所有者导出到csv文件

来自分类Dev

如何使用 Powershell 正确导出到 CSV

来自分类Dev

SQL Azure导出到CSV

来自分类Dev

将DataTable导出到csv

来自分类Dev

将scrapy导出到csv

来自分类Dev

将结果导出到CSV Azure PowerShell警告标志

来自分类Dev

使用nzsql将数据导出到CSV

来自分类Dev

使用Python将列表导出到CSV

来自分类Dev

扩展System.Object []以导出到CSV

来自分类Dev

如何将powershell代码导出到csv正确列

来自分类Dev

使用Powershell将Excel范围导出到csv

来自分类Dev

使用 Powershell 将大输出从 Oracle 导出到 CSV

来自分类Dev

将大数据导出到CSV文件

来自分类Dev

BigQuery将表格导出到CSV文件

来自分类Dev

将Python结果导出到CSV

来自分类Dev

将elasticsearch结果导出到CSV

来自分类Dev

Excel将多余的逗号导出到CSV

来自分类Dev

将SQL查询结果导出到CSV

来自分类Dev

将.po文件导出到.csv

来自分类Dev

将抓取的表格导出到CSV

来自分类Dev

将postgres表导出到csv错误

来自分类Dev

将工作表导出到CSV

来自分类Dev

将数据从Cassandra导出到CSV文件

来自分类Dev

将HTML表从iframe导出到CSV

来自分类Dev

将github问题导出到csv

来自分类Dev

将API响应导出到CSV

来自分类Dev

NetLogo:将表结果导出到CSV