[ PowerShell ] how to Get Selected AD Object?
-
sexta-feira, 21 de janeiro de 2011 15:05
Hello Everybody!
I found a VBScribt, which gets the selected User from the AD.
But somehow i wast able to figure out how to do the same task in PowerShell!
All what i could found was something like "PowerShell hasn't got a function like this".
So please it would be realy nice to get some help.
Here the VBScript:
Dim objEmployeeID Dim objSelectedUser Dim strNewEmployeeID Set objEmployeeID = Wscript.Arguments Set objSelectedUser = GetObject(objEmployeeID(0)) strNewEmployeeID = InputBox(“Employee ID: ” & objSelectedUser.employeeID & vbCRLF _ & vbCRLF _ & “To enter a new Employee ID number,” _ & ” type it into the text box” _ & ” below and click OK.”) if strNewEmployeeID <> “” Then objSelectedUser.Put “employeeID”,strNewEmployeeID end if objSelectedUser.SetInfo WScript.Quit
Todas as Respostas
-
sexta-feira, 21 de janeiro de 2011 18:37
soyou only want to change an employeeID? or more? because in the above script i somehow miss a "little" bit ;)
you can do this in different ways:
windows 2003:
-using ADSI in powershell (http://powershell.com/cs/blogs/ebook/archive/2009/04/10/chapter-19-user-management.aspx)
- using quest-cmdlets (quest.com)windows2008r2
-native ad-cmdlets (import-module activedirectory) -
quarta-feira, 26 de janeiro de 2011 08:04
Thank You for this two sites! they are very usefull =)
But actually it isnt realy about the change.
its just about the function which gets the selected Item.
and use it further in the script.
an example:
-i added the EmployeeID to the contextmenue.
-then i like to klick it and THEN my power shell script starts and get the selected user (on which i did a right klick).
=)
-
quarta-feira, 2 de fevereiro de 2011 22:01
an example:
-i added the EmployeeID to the contextmenue.
-then i like to klick it and THEN my power shell script starts and get the selected user (on which i did a right klick).
=)
sory i don´t understand the last sentence.
where did you add the employeid to? to which contextmenu where you rightclick? can you describe it a bit better, because from what i read, i have no clue ^^if you speak german, that might help me ;)
-
terça-feira, 26 de junho de 2012 11:07
Hello Evereybody,
I think he did the following to add an entry to the contextmenue of an AD Users's Object.
- Open ADSIEdit
- Right click "ADSI Edit" at the Top of the Console an select "Connect to"
- Choose "Select a well known Naming context" an select "Configuration"
- Navigate through the Tree: ADSI Edit -> Configuration -> CN=Configuration,DC=contoso,DC=com -> CN=DisplaySpecifiers -> CN=<Language ID>
- Double click "CN=user-Display"
- Select Attribute "adminContextMenu" and click Edit
- Now you can set a Link to a representative Script. For Example your "Change Employee ID Script"
I guess when you right click an AD User and choose "Change Employee ID Script" from the contextmenu an AD User Object is passed to the Script and so what he probably needs is the PowerShell Command for the VBS Command.
Maybe you try the following:
VBS: WScript.Arguments.Item(0) ==> PS: $args[0]
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null $ADUserObject = $args[0] $OldEmployeeID = (Get-ADUser -Identity $ADUserObject -Properties EmployeeID).EmployeeID $NewEmployeeID = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the new Employee ID", "Change Employee ID", "$OldEmployeeID") Set-ADUser $ADUserObject -Replace @{employeeid=$NewEmployeeID}Please test this first in a test Environment.
Hope this helps
//ABurger
- Editado ABurger terça-feira, 26 de junho de 2012 11:11
- Sugerido como Resposta Raimund AndréeMicrosoft Employee quarta-feira, 27 de junho de 2012 15:45
- Marcado como Resposta Denniver ReiningMVP, Moderator sexta-feira, 29 de junho de 2012 10:04

