I am trying to set up a powershell script to automatically run a command to get a list of all user accounts that have "Remotepowershellenabled" $True then take that list and compare it to 2 admin groups. After that I want it to set all of the user accounts that are not a part of the 2 admin accounts to then set that option to $false. When I get to this part of my script the new variable is not populating with anything. I know for a fact that there are users listed in the variable $UserswithRemotePS that are not in the $DomainAdmin variable.
$UsersNotDA = $UserswithRemotePS | where {$_.samaccountname -inotin $DomainAdmin}
I put this script together by looking at a couple of other similar scripts so I clearly missed something. Any help would be greatly appreciated.
$DomainAdmins = (Get-ADGroupMember -Identity "Domain Admins").samaccountname|out-string
$Exchangeadmins = (Get-ADGroupMember -Identity "ExchangeAdmins").samaccountname|out-string
Get-PSSession|Remove-PSSession
$ExchangePSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ExchangeServer/PowerShell/ -Authentication Kerberos
$UserswithRemotePS = (Invoke-Command -Session (Get-PSSession) {Get-User -ResultSize Unlimited -Filter 'RemotePowerShellEnabled -eq $true'}).samaccountname|out-string
$UsersNotDA = $UserswithRemotePS | where {$_.samaccountname -notin $DomainAdmin}