我需要一些关于CSV文件及其数据的订购/删除帮助。输出文件如下所示:
@{[email protected]}
@{UserPrincipalName=name1.surna[email protected]}
@{[email protected]}
但是我喜欢的是以下内容:
'[email protected]', '[email protected]', '[email protected]'
我尝试了替换,修剪和其他命令,但到目前为止没有成功。这里是我的AAD脚本,我用它来获取用户。
Write-Host "Fetching data from Azure Active Directory..."
$cred = New-Object -TypeName PSCredential -argumentlist $username, $pwd
#Connect to M365
Connect-MsolService -Credential $cred
$Users = Get-MsolUser -All | Where-Object { $_.UserType -ne "Guest" }
$userlist = [System.Collections.Generic.List[Object]]::new() # Create output file
ForEach ($User in $Users) {
$ReportLine = [PSCustomObject] @{
UserPrincipalName = $User.UserPrincipalName
}
$userlist.Add($ReportLine)
}
$Output = "c:\logging\data\AAD_Users_only.csv"
Set-Content -path $Output -value $userlist
谢谢你的帮助。
1条答案
按热度按时间2sbarzqh1#
只需替换最后一行:
有:
Export-Csv
将检查输入对象上的属性,发现它们只有一个UserPrincipalName
属性,并将其作为结果CSV文件中的唯一列输出:要将值读回内存,请使用
Import-Csv
: