Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Check a PowerShell script line against a txt file containing computer names

$
0
0

I need to check the following code against a txt file with computer names, so if the computer name exist in the file, it'll be copied to the shadow group.

Powershell
$OU="OU=Computers,DC=mylab,DC=local"$ShadowGroup="CN=SelectPCs,OU=Groups,DC=mylab,DC=local"Get-ADComputerSearchBase$OUSearchScopeOneLevelLDAPFilter"(!memberOf=$ShadowGroup)"|ForEach-Object{Add-ADPrincipalGroupMembershipIdentity$_MemberOf$ShadowGroup}

I tried a pipe and 'Where', but couldn't make it work:

Powershell
$OU="OU=Computers,DC=mylab,DC=local"$ShadowGroup="CN=SelectPCs,OU=Groups,DC=mylab,DC=local"$PCList=c:\scripts\computernames.txtGet-ADComputerSearchBase$OUSearchScopeOneLevelLDAPFilter"(!memberOf=$ShadowGroup)"**|Where-Object{$_.NameMatch$PCList}**|ForEach-Object{Add-ADPrincipalGroupMembershipIdentity$_MemberOf...

Viewing all articles
Browse latest Browse all 15370

Trending Articles



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