Hi,
This is my setup
Active Directory server Name: dc01
Client: Win 8
Domain Name: cyquent.ae
I have created a FORM to create Active Directory users in my Domain.
When I open my FORM in the Domain server locally it works perfectly well. (User is getting created without any issues)
Question: -
I want to use the invoke-command so that I can run the form on a remote PC, So that I can use this FORM to create Domain Users from a remote PC as well.
I have attached my FORM screenshot to get an idea about my FORM.
These are the steps I used to follow to create users: -
1. Fill the fields with user details
2. Click "CREATE" Button
3. Once you click the CREATE button you should be able to see the user details on the "STATUS" and user should be created in the AD as well
Command I have given in the "CREATE" button:-
$theOU = $comboboxOU.Text
$myOU = Invoke-Expression "(Get-ADOrganizationalUnit -LDAPfilter '(Name=$theOU)' -SearchBase 'OU=Users,OU=LabOU,DC=cyquent,DC=ae').DistinguishedName"
if ($checkboxEnabled.Checked -eq $true)
{
New-ADUser -Path $myOU -DisplayName $txtBoxDisplayName.Text -GivenName $txtBoxGivenname.Text -City $comboboxOffice.Text -Country $comboboxCountry.Text -Description $txtBoxDescription.Text -Surname $txtBoxSurname.Text -Name $txtBoxDisplayName.Text -SamAccountName $txtBoxLoginName.Text -UserPrincipalName $txtBoxLoginName.Text -AccountPassword (ConvertTo-SecureString $txtBoxPassword.Text -AsPlainText -Force) -ChangePasswordAtLogon:$true -Enabled:$true
}
else
{
New-ADUser -Path $myOU -DisplayName $txtBoxDisplayName.Text -GivenName $txtBoxGivenname.Text -City $comboboxOffice.Text -Country $comboboxCountry.Text -Description $txtBoxDescription.Text -Surname $txtBoxSurname.Text -Name $txtBoxDisplayName.Text -SamAccountName $txtBoxLoginName.Text -UserPrincipalName $txtBoxLoginName.Text -AccountPassword (ConvertTo-SecureString $txtBoxPassword.Text -AsPlainText -Force) -ChangePasswordAtLogon:$true -Enabled:$false
}
Note: -
In the FORM load section I have imported the Active Directory module and it works fine.
I think problem is happening with the "-Path $myOU" section.
Please help me on this.
Hope this is clear.
Thanks,
Shamir
PS Studio - Create Active Directory Users from a remote PC
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
PS Studio - Create Active Directory Users from a remote PC
- Attachments
-
- Interface.jpg (151.43 KiB) Viewed 4529 times
- SAPIEN Support Forums
- Posts: 945
- Last visit: Thu Oct 22, 2015 1:10 pm
PS Studio - Create Active Directory Users from a remote PC
This is an automated post. A real person will respond soon.
Thank you for posting, shamir_79.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
Anticipate follow-up questions!
Did you remember to include the following?
*** Make sure you do not post any licensing information ***
Thank you for posting, shamir_79.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
- - Scripting question? For questions about Windows PowerShell or other scripting languages, use Scripting Answers.
- Software question? For questions about PowerShell Studio, PrimalScript, or other SAPIEN products, use Product Support Forums for Registered Customers.
- Trial question? For questions about trial versions of any SAPIEN product, use Trial Software Questions.
Anticipate follow-up questions!
Did you remember to include the following?
- 1. Product, version and build
2. 32 or 64 bit product
3. Operating system, e.g. Windows 7 64 bit.
4. Attach a screenshot, if applicable
5. Attach logs, crash reports, etc., in a ZIP file
*** Make sure you do not post any licensing information ***
Re: PS Studio - Create Active Directory Users from a remote
Isn't this the same question you asked before?
http://www.sapien.com/forums/viewtopic. ... 821#p44821
I already showed you how to do that so why are you asking the same quesion with a picture?
http://www.sapien.com/forums/viewtopic. ... 821#p44821
I already showed you how to do that so why are you asking the same quesion with a picture?
Re: PS Studio - Create Active Directory Users from a remote
Here is how to structure the New-AdUser Cmdlety loading correctly.
YOu cannot us eInvoke-Expression at all. iIT is not intended to be used as you are using it.
PowerShell Code
Double-click the code block to select all.$userprops=@{ Path=$comboboxOU.SelectedItem.DistinguishedName DisplayName=$txtBoxDisplayName.Text GivenName=$txtBoxGivenname.Text City=$comboboxOffice.Text Country=$comboboxCountry.Text Description=$txtBoxDescription.Text Surname=$txtBoxSurname.Text Name=$txtBoxDisplayName.Text SamAccountName=$txtBoxLoginName.Text UserPrincipalName=$txtBoxLoginName.Text AccountPassword=(ConvertTo-SecureString $txtBoxPassword.Text -AsPlainText -Force) ChangePasswordAtLogon=$true Enabled=$checkboxEnabled.Checked } New-ADUser @userpropsYou would be better off installing RSAT. If you insist on remoting then you are going to have to learn more about how to use PowerShell remoting from th ecommandline before attempting it in a form. In remoting we can "Import" the session to make this work. If you onlly use Invoke-Command it wil be very slow and cause you to have to write a lot of extra code.
YOu cannot us eInvoke-Expression at all. iIT is not intended to be used as you are using it.
Re: PS Studio - Create Active Directory Users from a remote
Here is an example of how to statically import a session. The attached method will work in a forms script and not just in PowerShell Studio.
Of course you can also set PowerShell Studio to do the remoting and it will be incorporated into a script or EXE.
Of course you can also set PowerShell Studio to do the remoting and it will be incorporated into a script or EXE.
- Attachments
-
- Demo-RemoteForm.psf
- (27.68 KiB) Downloaded 195 times
Re: PS Studio - Create Active Directory Users from a remote
Hi,
From my remote PC I tried using below command to create users in AD. But in the "-path" section I am getting an error. Please help me to resolve this.
-----------------------------------------------
$theOU = "HR"
#status = success
$myOU = Invoke-Command -ComputerName dc01 -ScriptBlock {"(Get-ADOrganizationalUnit -LDAPfilter '(Name=$theOU)' -SearchBase 'OU=Users,OU=LabOU,DC=cyquent,DC=ae').DistinguishedName" }
#status = success
Invoke-Command -ComputerName dc01 -ScriptBlock {New-ADUser -DisplayName peter -Path $myOU -GivenName peter -City Houston -Country US -Description Accountant -Surname jason -Name peter -SamAccountName peter -UserPrincipalName peter -AccountPassword (ConvertTo-SecureString password@123 -AsPlainText -Force) -ChangePasswordAtLogon:$true -Enabled:$true}
#status = Error
Error: Cannot validate argument on parameter 'Path'. The argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.
----------------------------------------------------------
Note:- If I type -path as -PATH 'OU=HR,OU=Users,OU=LabOU,DC=cyquent,DC=ae' I am able to create the user successfully.
But I need to use it through a variable as I was trying.
Note: - "HR" is the Organization Unit name where I am trying to create the user.
plz help me.
Thanks,
Shamir
From my remote PC I tried using below command to create users in AD. But in the "-path" section I am getting an error. Please help me to resolve this.
-----------------------------------------------
$theOU = "HR"
#status = success
$myOU = Invoke-Command -ComputerName dc01 -ScriptBlock {"(Get-ADOrganizationalUnit -LDAPfilter '(Name=$theOU)' -SearchBase 'OU=Users,OU=LabOU,DC=cyquent,DC=ae').DistinguishedName" }
#status = success
Invoke-Command -ComputerName dc01 -ScriptBlock {New-ADUser -DisplayName peter -Path $myOU -GivenName peter -City Houston -Country US -Description Accountant -Surname jason -Name peter -SamAccountName peter -UserPrincipalName peter -AccountPassword (ConvertTo-SecureString password@123 -AsPlainText -Force) -ChangePasswordAtLogon:$true -Enabled:$true}
#status = Error
Error: Cannot validate argument on parameter 'Path'. The argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.
----------------------------------------------------------
Note:- If I type -path as -PATH 'OU=HR,OU=Users,OU=LabOU,DC=cyquent,DC=ae' I am able to create the user successfully.
But I need to use it through a variable as I was trying.
Note: - "HR" is the Organization Unit name where I am trying to create the user.
plz help me.
Thanks,
Shamir
Re: PS Studio - Create Active Directory Users from a remote
Okay...
Could you please help me to use "ArgumentList" paramter for this example as I am putting lots of efforts to get this thing done.?
For last 03 days I am struggling with this
Could you please help me to use "ArgumentList" paramter for this example as I am putting lots of efforts to get this thing done.?
For last 03 days I am struggling with this