0

I am trying to create PowerShell script that allows me to input the username and or group name and send it to our server for permissions.

Is there a way to prompt with just a text box of those 2 fields instead of inserting the names into the script each time?

$group = [ADSI]"WinNT://win2016-sfd-02/GROUP_NAME,group"
$group.Add("WinNT://win2016-sfd-02/DOMAIN/USER_NAME,user")
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
Tinkinc
  • 449
  • 2
  • 8
  • 21
  • Very tempting dup of http://stackoverflow.com/questions/8184167/prompt-for-user-input-in-powershell – Matt Feb 09 '17 at 16:56
  • If you wanted a single form with two boxes you will have to make that yourself I think. – Matt Feb 09 '17 at 17:01

1 Answers1

2

Read-Host is what you're after:

$Username = Read-Host "Please enter Username"
$GroupName = Read-Host "Please enter Groupname"

$group = [ADSI]"WinNT://win2016-sfd-02/$GroupName,group"
$group.Add("WinNT://win2016-sfd-02/DOMAIN/$Username,user")
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • Thanks James. That works perfectly. Is there a way to just run it with 1 click and then get the prompt text box? – Tinkinc Feb 09 '17 at 17:25
  • http://www.sciosoft.com/blogs/post/2011/10/04/Launch-PowerShell-Script-from-Shortcut.aspx this works well – Tinkinc Feb 09 '17 at 17:58