I wrote a code and have a problem to export it to csv. So the code is comparing the list of AD users to a Distribution Groups or number of Distribution Groups and it works perfectly. I only cannot export it to .csv.
Get-ADUser -filter {Enabled -eq $true} -SearchBase "OU=Location" |% { $_.samAccountName } | out-file "C:\users.txt"
Get-ADGroupMember -Identity "Company" |% { $_.samAccountName } | out-file "C:\Members.txt"
$List = Get-Content ("C:\Members.txt")
$ListOfUsers = Get-Content ("C:\users.txt")
$compare = Compare-Object -ReferenceObject $ListOfUsers -DifferenceObject $List -IncludeEqual
foreach($Inp in $compare)
{
$notice = $Inp.InputObject
If ($Inp.SideIndicator -eq "==")
{
"$notice User is avaiable in Distribution List"
}
elseIf ($Inp.SideIndicator -eq "<=")
{
"$notice User is not available in Distribution List "
}
}
If I add at the end of the line export-csv it giving me something like this:
My question is: how to export it correctly to receive InputObject as a Name, SideIndicator as a Notice and Comparison Operators as information if the user is inside the Distribution Group or not?
