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*"'
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
}
did you add the * after the desktop1
try this small change
$AllPC=Get-ADComputer -Filter 'SamAccountName -like "desktop*"'- farismalaebJan 21, 2021Iron Contributor
Its Powershell and everything is doable, but first, you need to think about it,
Logically what is the common thing between this computer object and build the filter based on that.
I would suggest updating a computer object attrib or custom attrib then exclude these object with these attrib from the query.
- Surfer10Jan 21, 2021Copper Contributor
Now tht the script works is there also a way to exclude some names with DESKTOPNR?
I would like to run this command every week so that computers which are not a member of the testgroup will be added as member but there are 10 computers with the name dekstop111, desktop112,desktop250 and so 10 total.
Is it possible to exclude these, these 10 computers must be added to another group: prodgroup.
- Surfer10Jan 21, 2021Copper Contributor
Hi, do you know whcih version i need for the other commands to work is that powershell version 7?
- Surfer10Jan 21, 2021Copper Contributor
Yes thank you now it works! farismalaeb