Jump to content

Recommended Posts

Posted (edited)

Hi,

I want to use the AD UDF to add a group from the domain into a local group of my pc. 

I want to use _AD_AddGroupToGroup($sTarget, $sObject) for this.

I am not sure how to feed this function.

$sObject should be the name of the group from the domain I think and $sTarget my local group on the pc. 

$sObject = "DN=nameofaspecialpc,OU=specialpcs,DC=xxx,DC=yyy,DC=de"

nameofaspecialpc is a group.

How to handle the target? FQDN input for my local pc which is member of a domain?

Who can help me with a small example for $sTarget, let's say the local Administrator group of the pc.

Thank you

Edited by blumi
Posted

Something like this?

The title of the thread is misleading. The code adds a group.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

I know the net local group etc. 

I thought the AD UDF will do this, so I don't have to use the net local group or the WinNT commands?

Does the UDF handle this or not? 

Edited by blumi
Posted

No, the AD UDF only handles AD objects.

But what is wrong with the WMI approach?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

I tried it different times but did not get it to work. 

But then I will try it again and post my code here if it will not work. 

 

Posted

Or check this thread (they add a user but should work for groups as well):

Make sure to add a COM error handler to get better error information!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

  • 3 months later...
Posted

I did some more tries and found some nice powershell cmdlets

https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/exploring-local-account-management-cmdlets

My goal first is to add a local user "test" to the local user group "Administratoren" (German Windows) 

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/add-localgroupmember?view=powershell-5.1

Here I created a local user "test" an my system and tried in the powershell comannd the following lines. (Not in AutoScript)

Add-LocalGroupMember -Group "Administratoren" -Member "test"
Add-LocalGroupMember -Group 'Administratoren' -Member 'test'

Both work so next step was to try to handle this via autoit script. 

$ScriptName = "test"
$success = RunWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Add-LocalGroupMember -Group 'Administratoren' -Member 'test' ")
MsgBox(64, $ScriptName, "success: " & $success & @CRLF & "Error: " & @error)

The error is 0 but no user was added to the group "Administratoren".

Of course I have removed the added user before testing. 

Who can help? 

Thank you

 

Posted

I use the following code to grab the Powershell output from Stdout and Stderr (this was a Q&D solution so the code could be optimized):

$sCMD = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file " & @ScriptDir & "\PS-Command-to-Execute.ps1"
    $pid = Run($sCMD, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
    ; End Powershell
    StdinWrite($pid, @CRLF)
    StdinWrite($pid)
    ; Process Stdout
    $sSTDOUT = ""
    While 1
        $sOutput = StdoutRead($pid)
        If @error Then ExitLoop
        If $sOutput <> "" Then $sSTDOUT = $sSTDOUT & @CRLF & $sOutput ; Only process non-empty lines
    WEnd
    ConsoleWrite("STDOUT:" & @CRLF & $sSTDOUT & @CRLF)
    ; Process Stderr
    $sSTDERR = ""
    While 1
        $sOutput = StderrRead($pid)
        If @error Then ExitLoop
        If $sOutput <> "" Then $sSTDERR = $sSTDERR & @CRLF & $sOutput ; Only process non-empty lines
    WEnd
    ConsoleWrite("STDERR:" & @CRLF & $sSTDERR & @CRLF)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted
On 3/19/2021 at 5:42 PM, water said:

I use the following code to grab the Powershell output from Stdout and Stderr (this was a Q&D solution so the code could be optimized):

$sCMD = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file " & @ScriptDir & "\PS-Command-to-Execute.ps1"
    $pid = Run($sCMD, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
    ; End Powershell
    StdinWrite($pid, @CRLF)
    StdinWrite($pid)
    ; Process Stdout
    $sSTDOUT = ""
    While 1
        $sOutput = StdoutRead($pid)
        If @error Then ExitLoop
        If $sOutput <> "" Then $sSTDOUT = $sSTDOUT & @CRLF & $sOutput ; Only process non-empty lines
    WEnd
    ConsoleWrite("STDOUT:" & @CRLF & $sSTDOUT & @CRLF)
    ; Process Stderr
    $sSTDERR = ""
    While 1
        $sOutput = StderrRead($pid)
        If @error Then ExitLoop
        If $sOutput <> "" Then $sSTDERR = $sSTDERR & @CRLF & $sOutput ; Only process non-empty lines
    WEnd
    ConsoleWrite("STDERR:" & @CRLF & $sSTDERR & @CRLF)

Thanks for the code, it was a permission problem. I forgot #requireAdmin, now it works and adds a local user. 

Next step, I want to add a domain group (not user) to the local group Administratoren. 

I am not sure about the syntax with the domain. 

I tried "domainname\Lokale Administratoren\groupname"

$sCMD = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command Add-LocalGroupMember -Group 'Administratoren' -Member 'Domain\Lokale Administratoren\groupname'"
    $pid = Run($sCMD, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
    ; End Powershell
    StdinWrite($pid, @CRLF)
    StdinWrite($pid)
    ; Process Stdout
    $sSTDOUT = ""
    While 1
        $sOutput = StdoutRead($pid)
        If @error Then ExitLoop
        If $sOutput <> "" Then $sSTDOUT = $sSTDOUT & @CRLF & $sOutput ; Only process non-empty lines
    WEnd
    ConsoleWrite("STDOUT:" & @CRLF & $sSTDOUT & @CRLF)
    ; Process Stderr
    $sSTDERR = ""
    While 1
        $sOutput = StderrRead($pid)
        If @error Then ExitLoop
        If $sOutput <> "" Then $sSTDERR = $sSTDERR & @CRLF & $sOutput ; Only process non-empty lines
    WEnd
    ConsoleWrite("STDERR:" & @CRLF & $sSTDERR & @CRLF)

Sadly the group was not found, I think I use the wrong syntax. 

This what I have copied from the console

 Add-LocalGroupMember : Der Prinzipal Domain\Lokale Administratoren\groupname wurde nicht gefunden.

Domain and groupname I have changed, don't want to post it here. 

 

On 3/19/2021 at 5:42 PM, water said:

 

 

Posted

Unfortunately I have never worked with local groups.
But the forum has some threads discussing the subject. Example:

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

These is the "old" WinNT syntax, looks completeley different to the powershell syntax to me. 

I will try to get more infos about the powershell syntax. 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...