Solved

PowerShell GUI prompt for IP address to search for AD computers

Posted on 2016-10-03
4
266 Views
Last Modified: 2016-10-04
I am really new to PowerShell but learning. What I am wanting is a powershell script that when launched will create a GUI interface and prompt for a single IP address or allow the use of a wild card to search a range of IPs (ie. 10.0.0.*), then will use the IP address information to search AD for the machine(s) with that IP address.

 The command I am using in powershell command line is as follows:
get-adcomputer -filter * -properties ipv4address | where ipv4address -like "111.222.333.*" | select name, ipv4address, distinguishedname | Out-GridView

This command works in powershell but when I try to script it, it just sits there doing nothing. It doesn't error out, it just doesn't do anything at all.
Quite often I get notified about a machine needing some kind of attention and the only information I am given is an IP address and sometimes I'll get a username nothing else. So I have to type in the command and run it to find where the machine lives so I can do what needs to be done. I'd like to script it so that I can launch it, enter in the IP or range of IPs and then get as much details from that search as I can in as short amount of time as possible. And if there is a better command to use any suggestions are most welcome.

Thanks in advance,
RBennett
0
Comment
Question by:Ryan Bennett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41827188
Find the answer for similar question for example..
https://www.experts-exchange.com/questions/28214486/PowerShell-Creating-GUI-for-a-simple-search.html
In the code replace the $handler_Find_Click code block with
$handler_Find_Click= 
{
#TODO: Place custom script here
$Comp = get-adcomputer -filter * -properties ipv4address | ?{$_.ipv4address -like $textBox1.Text} |Select name,ipv4address,distinguishedname
 If ($Comp) {
 $richTextBox1.Text = $Comp | FL name,ipv4address,distinguishedname | Out-String
 }Else {
 $richTextBox1.Text = "Error in finding $($textBox1.Text)"
 }
}

Open in new window


Or use Read-Host for create simple prompt, to input IP address and get result using Out-GridView
Try code..
$Ip = Read-Host "Input IP Details"
Get-ADComputer -filter * -properties ipv4address | where ipv4address -like $Ip | select name, ipv4address, distinguishedname | Out-GridView

Open in new window

1
 

Author Comment

by:Ryan Bennett
ID: 41828089
Thanks Subsun for the quick replay.

I tried running the first script as you have it in powershell and from the command line but neither work. And yes I used -executionpolicy remotesigned in the command line but the window just flashed and the script ended. Even tried it on an elevated powershell and command prompt still no luck.

I was able to get the second script to work which is basically the same as I wrote mine a few days ago but mine would not run for whatever reason. So at least I have something working, but would really like a GUI if possible. Mostly for learning how to do it.

 Thanks again.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41828273
I have tested the GUI code and it's working for me...Post the GUI script which you are trying..
0
 

Author Closing Comment

by:Ryan Bennett
ID: 41828894
Sorry, I missed a step. I fixed it and now it is working fine. Thanks very much, I appreciate the 2 versions to work with.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question