Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell: Searching AD for computers that are not members of multiple groups

$
0
0

I'm trying to write a Powershell script that searches AD for computers that are NOT a member of a group.  Basically, this is a maintenance task that will output a list of computers that were added to the domain incorrectly.  When I paste the below line by line into powershell I get the output expected.  When I try to launch it from a .ps1 file the Export-csv is created with 0 bytes.  Any help would be appreciated.

#import-module ActiveDirectory
Get-ADComputer -LDAPFilter "
(&(!
(memberof='WSUS1')
))
(&(!
(memberof='WSUS2')
))
(&(!
(memberof='WSUS3')
))
(&(!
(memberof='WSUS4')
))
(&(!
(memberof='WSUS5')
))
(&(!
(memberof='WSUS6')
))
(&(!
(memberof='WSUS7')
))
(&(!
(memberof='WSUS8')
))
(&(!
(memberof='WSUS9')
))
(&(!
(memberof='WSUS10')
))
(&(!
(memberof='WSUS11')
))
(&(!
(memberof='WSUS12')
))
(&(!
(memberof='WSUS13')
))
(&(!
(memberof='WSUS14')
))
(&(!
(memberof='WSUS15')
))
(&(!
(memberof='WSUS16')
))
(&(!
(memberof='WSUS17')
))" | Select Name | Export-csv "D:\temp\Wsus_computers $(get-date -f yyyy-MM-DD).csv"



Dmox


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>