I am using this script to export groups and users in a SP group. I am having trouble exporting to csv, how can I do it?
$siteUrl = "SiteCollection"
$web = Get-SPWeb $siteUrl
$site = Get-SPSite $URL
if (Get-SPWeb($url).HasUniqueRoleAssignments -eq $true)
{
$Web=Get-SPWeb($url)
}
else
{
$web= $site.RootWeb
}
#Get all Groups and Iterate through
foreach ($group in $Web.sitegroups)
{
write-host " Group Name: "$group.name "`n---------------------------`n"
#Iterate through Each User in the group
foreach ($user in $group.users)
{
write-host $user.name "`t" $user.LoginName "`t" $user.Email | FT
}
write-host "==================================" #Group Separator
}