I have the computer name because that’s what I’m using to start this project
Asking the customer what the PC# is then I pull several items from that PC
I’d just rather script an OU move then have the techs go through ADUC.
Remember my goal is to list the OUs in a context menu so if they are wrong, the techs can right click a label(OU they are presently in) and the list of OUs I want to listed are present so on the click event, they are moved to the correct OU
Listing specific OUs for context menu
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.
- StillLearning
- Posts: 39
- Last visit: Tue Apr 10, 2018 9:39 pm
Re: Listing specific OUs for context menu
Like I noted above. You need a clear use case and workflow. What you are posting is just bits with little definition. I cannot understand what you are trying to do. First you ask for computers from some OUs then you ask for OUs and finally add something about getting things from a PC.
Start small and write the first pieces of your code. Ask each new question as you arrive at it. This will help you avoid ambiguous questions.
Start small and write the first pieces of your code. Ask each new question as you arrive at it. This will help you avoid ambiguous questions.
Re: Listing specific OUs for context menu
Here is an old example of how to use ADSI from a form or a script:
- Attachments
-
- Demo-ADSITreeView.psf
- (25.77 KiB) Downloaded 117 times
- StillLearning
- Posts: 39
- Last visit: Tue Apr 10, 2018 9:39 pm
Re: Listing specific OUs for context menu
My use case:
Help techs identify computers that are in the wrong OU. They are aware that if a PC is not in East Coast or West Coast it’s wrong. Why not just move them automatically? It’s less of a hassle on the end user being met with new changes when I can have my techs explain to them while my script is running.
My workflow is this:
Techs type in PC name and a label displays what OU it’s currently in, if it’s wrong I want the techs to right click on that label and choose the correct OU,upon doing so, the PC is moved to the correct OU, GPUpdate is ran and the PC is restarted.
Help techs identify computers that are in the wrong OU. They are aware that if a PC is not in East Coast or West Coast it’s wrong. Why not just move them automatically? It’s less of a hassle on the end user being met with new changes when I can have my techs explain to them while my script is running.
My workflow is this:
Techs type in PC name and a label displays what OU it’s currently in, if it’s wrong I want the techs to right click on that label and choose the correct OU,upon doing so, the PC is moved to the correct OU, GPUpdate is ran and the PC is restarted.
Re: Listing specific OUs for context menu
Great. Now where is you code that collects the PC names and looks up the OU?
Code: Select all
$computersam = $name + '$'
$parentOU = ([adsisearcher]"SamAccountName=$computersam").FindOne().GetDirectoryEntry().Parent
# test for correct OU
- StillLearning
- Posts: 39
- Last visit: Tue Apr 10, 2018 9:39 pm
- StillLearning
- Posts: 39
- Last visit: Tue Apr 10, 2018 9:39 pm
Re: Listing specific OUs for context menu
Since there has been 3 downloads, I don't want to confuse anyone.. Everything works beside dynamically populating the OUs I want in the context menu
I just thought I would share a run down
I just thought I would share a run down
- $contextmenustrip1_Opening=[System.ComponentModel.CancelEventHandler]{
- #Event Argument: $_ = [System.ComponentModel.CancelEventArgs]
- #TODO: Place custom script here
- #This is where I think the ADSI code would go to find the OUs since it's on the opening.
- }
- $eastCoastToolStripMenuItem_Click={
- #TODO: Place custom script here
- $wshell = New-Object -ComObject Wscript.Shell
- $wshell.Popup("Moving To East Coast OU", 0, "Done", 0x1)
- #script to move the PC to the OU
- $wshell = New-Object -ComObject Wscript.Shell
- $wshell.Popup("Updating GP on PC", 0, "Done", 0x1)
- #invoke-command to run GPUPdate /force /boot
- $wshell = New-Object -ComObject Wscript.Shell
- $wshell.Popup("Restarting PC", 0, "Done", 0x1)
- }
- $textbox1_TextChanged={
- #TODO: Place custom script here
- #if the PC matches a naming convention we'll do $computer = $textbox1.text
- $labelWindows10.Text = (gwmi -ComputerName $computer -Class Win32_OperatingSystem).caption
- $labelMiami.Text = #I have the script on my other PC but it pulls the parent of the current PC so it will only show Miami or Las Vegas, etc...
- }
Re: Listing specific OUs for context menu
That is just a dummy that assume nothing. How do you envision this working? What is your first question.
Look at the form I posted to se how to navigate and use ADSI.
Look at the form I posted to se how to navigate and use ADSI.
- StillLearning
- Posts: 39
- Last visit: Tue Apr 10, 2018 9:39 pm
Re: Listing specific OUs for context menu
That's beautiful.
-----
This is how I know what OU the PC is in
$pc = 'PC123456'
(([adsisearcher]"samaccountname=$PC$").FindOne().Properties['adspath']).split(",")[1] -replace ('OU=')
It will return this.
East Coast
All PCs reside in these 5 OUs.
LDAP://OU=EastCoast,OU=Org,OU=Workstations,DC=orgname,DC=net
LDAP://OU=Test,OU=Org,=Workstations,DC=orgname,DC=net
LDAP://OU=WestCoast,OU=Org,OU=Workstations,DC=orgname,DC=net
LDAP://OU=Miami,OU=Org,OU=Workstations,DC=orgname,DC=net
LDAP://OU=LasVegas,OU=Org,OU=Workstations,DC=orgname,DC=net
I want to be able to filter out Miami, Las Vegas, Test and any others ( through a external text file)
Load my contextmenu with the remaining results ( East Coast, West Coast)
Like so I don't know how to populate the contextmenu items dynamically with the correct results.
-----
This is how I know what OU the PC is in
$pc = 'PC123456'
(([adsisearcher]"samaccountname=$PC$").FindOne().Properties['adspath']).split(",")[1] -replace ('OU=')
It will return this.
East Coast
All PCs reside in these 5 OUs.
LDAP://OU=EastCoast,OU=Org,OU=Workstations,DC=orgname,DC=net
LDAP://OU=Test,OU=Org,=Workstations,DC=orgname,DC=net
LDAP://OU=WestCoast,OU=Org,OU=Workstations,DC=orgname,DC=net
LDAP://OU=Miami,OU=Org,OU=Workstations,DC=orgname,DC=net
LDAP://OU=LasVegas,OU=Org,OU=Workstations,DC=orgname,DC=net
I want to be able to filter out Miami, Las Vegas, Test and any others ( through a external text file)
Load my contextmenu with the remaining results ( East Coast, West Coast)
Like so I don't know how to populate the contextmenu items dynamically with the correct results.