Darien Posted May 28, 2018 Posted May 28, 2018 Hi, I can not use the net localgroup command with names longer than 20 characters due to this limitation: https://support.microsoft.com/pt-br/help/324639/net-exe-add-command-does-not-support-names-longer-than-20-characters Would there be a script that would replace net localgroup?
Moderators JLogan3o13 Posted May 28, 2018 Moderators Posted May 28, 2018 You can always go the old WinNT route, works on Win7 and Win10: Local $oGroup = ObjGet("WinNT://" & @ComputerName & "/Administrators") If IsObj($oGroup) Then $oGroup.Add("WinNT://" & @ComputerName & "/MyReallyCoolSuperLongYoureNotGoingToBelieveHowAwesomeThisGroupIs Group") Else ConsoleWrite("Could not obtain object." & @CRLF) EndIf "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Darien Posted May 29, 2018 Author Posted May 29, 2018 JLogan3o13, Sorry for my ignorance, but what does the above script do? I performed it and saw no result whatsoever. How could I replace the commands below? net localgroup <local group> /add <domain\domain group> net localgroup <local group> /delete <domain\domain group>
Subz Posted May 29, 2018 Posted May 29, 2018 Make sure you add #RequireAdmin to the top of the script otherwise it will error, but basically it will add a user to the local group another example, adding "Authenticated Users" to "Power Users" group. #RequireAdmin Local $oGroup = ObjGet("WinNT://" & @ComputerName & "/Power Users") If IsObj($oGroup) Then $oGroup.Add("WinNT://" & @ComputerName & "/Authenticated Users") Else ConsoleWrite("Could not obtain object." & @CRLF) EndIf
Darien Posted May 29, 2018 Author Posted May 29, 2018 Subz, I ran the above script to add the domain group "TRT2R\RDP" to the local group "Administradores", but I got the error below: But by the net localgroup I can do the same action.:
Subz Posted May 29, 2018 Posted May 29, 2018 It should have been: #RequireAdmin Local $oGroup = ObjGet("WinNT://" & @ComputerName & "/Administradores") If IsObj($oGroup) Then $oGroup.Add("WinNT://TRT2R/RDP") Else ConsoleWrite("Could not obtain object." & @CRLF) EndIf
Darien Posted May 29, 2018 Author Posted May 29, 2018 Now it worked. But how do I prevent the script from being aborted when an error occurs (if the group is already added or not able to communicate with the domain server, for example)?
Moderators JLogan3o13 Posted May 29, 2018 Moderators Posted May 29, 2018 We call it Error Checking. Look at @error in the help file, or search on the forum. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Moderators JLogan3o13 Posted May 29, 2018 Moderators Posted May 29, 2018 Well, if to add it you need to do $oGroup.Add What might you think you would need to do to remove? This forum is dedicated to helping, not spoon-feeding it to you; you have to show at least some level of effort. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Darien Posted May 29, 2018 Author Posted May 29, 2018 I tried with del, delete and remove and it did not work.
AdamUL Posted May 29, 2018 Posted May 29, 2018 Have a look at the Local Account UDF. Look through the thread for additional functions. Adam
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now