I need some help on the ordering/removal of csv file and its data. The output file looks like this:
@{[email protected]}
@{[email protected]}
@{[email protected]}
however what I like to get is the following:
'[email protected]', '[email protected]', '[email protected]'
I tried it with replace, trim and other commands however no success so far. Here my AAD scripts which I use to get the users.
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
Thanks for any help.
Simply replace the last line:
With:
Export-Csvwill inspect the properties on the input objects, find that they only have aUserPrincipalNameproperty, and output that as the only column in the resulting CSV file:To read the values back into memory, use
Import-Csv: