The following working as expected except the format. It appears the record of value $r and $s variable are display in the same column field. How i can make display in different column field? or when i open the csv document with Excel. Thank you
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$timestamp = $(get-date -f MM-dd-yyyy_HH_mm_ss)
$Output=$timestamp + "_" + "SAPRoles.csv";
$wa = Get-SPWebApplication;
$site = Get-SPSite $wa.Url;
$serviceContext = Get-SPServiceContext -Site $site
#Instantiate User Profile Manager
$userProfileConfigManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);
#Get All User Profiles
$profiles = $userProfileConfigManager.GetEnumerator();
#Loop through all user profiles and display account name and role
foreach($profile in $profiles)
{
$s= $profile.get_Item("AccountName")
$r= $profile.get_Item("DataRoles")
$test= $s + $r | Out-File -Encoding Default -Append -FilePath $Output;
}