Forum Discussion
add computers to security group automatically
- Jan 21, 2021
did you add the * after the desktop1
try this small change
$AllPC=Get-ADComputer -Filter 'SamAccountName -like "desktop*"'
it seems that you are using an old version of Powershell
Try this
$AllPC=Get-ADComputer -Filter 'Name -like "Desktop*"' -properties displayname
foreach($SinglePC in $AllPC){
add-adgroupmember -identity "MyADGROUP" -Members $SinglePC.SamAccountName
}
I think it is version on a WIndows Server 2012 en the version on my WIndows 10 client is 5 i believe, which comes standard with Windows 10.
On both Powershell versions the last is also not working, it gives no error but it does nothing, i hope you have some more suggetions:
$AllPC=Get-ADComputer -Filter 'Name -like "desktop1"' -properties displayname
foreach($SinglePC in $AllPC){
add-adgroupmember -identity "testgroup" -Members $SinglePC.SamAccountName
}
- farismalaebJan 21, 2021Steel Contributor
did you add the * after the desktop1
try this small change
$AllPC=Get-ADComputer -Filter 'SamAccountName -like "desktop*"'- Surfer10Jan 21, 2021Copper Contributor
Yes thank you now it works! farismalaeb
- Surfer10Jan 21, 2021Copper Contributor
Hi, do you know whcih version i need for the other commands to work is that powershell version 7?