PowerShell Local Admin
Posted on 2014-10-29
Is there a way in the following section of script to add a confirmation to the users input and, if they enter no, allow them to re-enter their input? This is part of an AD join script and I am trying to avoid having admins re-run the entire thing if they mistype the user ID.
#Add local user account to the administrators group
$group = "Administrators"
$Host.UI.RawUI.ForegroundColor = "Blue"
$user = Read-Host "Enter the MSAD user ID you wish to grant administrator rights on this PC"
$pc = hostname
$objUser = [ADSI]("WinNT://msad/$user")
$objGroup = [ADSI]("WinNT://$pc/$group")