Active Directory Module

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 8 years and 4 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
tirwin@iot.in.gov
Posts: 40
Last visit: Tue Mar 14, 2017 9:54 am

Active Directory Module

Post by tirwin@iot.in.gov »

I have written a powershell script, an application that allow PC Refresh to set .Company, .DepartmentNumber, etc... On a ADOBject. In development everthing works fine. Obviously I have AD installed on my machine. I have compiled my app to a .exe and placed it on a network share where the techs will execute it from there as they start up a new computer or refresh from Windows 7 to Windows 10 mostly. The problem is the new pc will not have Active Directory installed at this point in time. I need to find a way to have my app import and run Active Directory as on start up of new or refreshed computers. How do I accomplish this? Below is some relivant code I use to import the module if it exist on the machine. Thanks
$RestoreForm_Load={
	# Load the ActiveDirectory module if it's available
	# Check if the ActiveDirectory module is installed
	if ((Get-Module -ListAvailable | where { $_.Name -eq 'ActiveDirectory' }) -eq $null)
	{
		$labelDialogRedRestore.Text += "You need to install the ActiveDirectory module!`n"
	}
	else
	{
		# Check if the ActiveDirectory module is allready Imported
		If ((Get-Module ActiveDirectory) -eq $null)
		{
			Import-Module ActiveDirectory -ErrorAction 'SilentlyContinue'
			$labelDialogGreenRestore.Text += "ActiveDirectory module imported`n"
		}
		else
		{
			$labelDialogGreenRestore.Text += "ActiveDirectory allready imported`n"
		}
	}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Active Directory Module

Post by jvierra »

You can't. You must install RSAT on every PC that needs to run your form.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Active Directory Module

Post by jvierra »

Note that, if you have remoting configured, you can use Invoke-Command to a DC to run the AD commands.
User avatar
jlawatts
Posts: 5
Last visit: Tue May 10, 2022 2:31 am

Re: Active Directory Module

Post by jlawatts »

Hi,
If you're just talking about updating the attributes of the AD object, have you thought about doing it without needing to use the ActiveDirectory module?
So for example, using ADSI just to update the description of a computer...

$Computer = [ADSI]"LDAP://CN=LNDT0002D,OU=Computers,OU=London,OU=EMEA,OU=Herbert Smith,DC=herbertsmith,DC=dev"
$Computer.Put("description","bob")
$Computer.SetInfo()

I know that in this example, you already know the distinguished name of the computer, but you could easily use ADSI to find and create the computer object, which you then update as above.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Active Directory Module

Post by jvierra »

While ADSI allows us to access all of AD it also requires that you are a very proficient programmer and very well trained in AD/LDAP.
Here is a form I wrote some years ago to use ADSI to update AD.

This first file shows how to set up and access AD from Form using ADSI: Demo-AddUserFrom.psf

This one shows how to do updates: Demo-ADUpdate.psf

This one shows how to navigate: Demo-ADSITreeView.psf

And finally here is how to remote a form: Demo-ADRemoteForm.psf
Attachments
Demo-ADRemoteForm.psf
And finally here is how to remote a form
(32.97 KiB) Downloaded 356 times
Demo-ADSITreeView.psf
This one shows how to navigate
(15.56 KiB) Downloaded 347 times
Demo-ADUpdateForm.psf
This one shows how to do updates
(27.23 KiB) Downloaded 347 times
Demo-ADAddUserForm.psf
This first file shows how to set up and access AD from Form using ADSI
(43.63 KiB) Downloaded 336 times
User avatar
hnoor0033
Posts: 1
Last visit: Tue Feb 02, 2016 9:25 pm

Re: Active Directory Module

Post by hnoor0033 »

If you're just talking about updating the attributes of the AD object, have you thought about doing it without needing to use the ActiveDirectory module?


______________
NOOR
User avatar
weiyen.tan@gmail.com
Posts: 55
Last visit: Fri Oct 27, 2023 10:59 pm

Re: Active Directory Module

Post by weiyen.tan@gmail.com »

An example of implicit remoting by using invoke-command can be found https://technet.microsoft.com/en-us/mag ... 20181.aspx .
This topic is 8 years and 4 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked