Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Where am I going wrong? Simple 'Delete User' script with menu

$
0
0

Like the title suggests, the below script refuses to work despite trying many iterations.

When running the script, after typing in the username and pushing enter it displays the details of every single user on the Lync server. What I want to do is just confirm that a user is there by showing the details echoed back from the server with the SIP address and then say 'Yes please delete' or 'No try again'

Your help, as always, is hugely appreciated and valued.

Forever learning, Alex

### Please note that this is being run after importing all modules and connecting to Lync server. There are no issues with accessing cmds ###

function removelync
{

$title = "Remove user from Lync"
""
$lycnuser = Read-host "Please enter the username of the account to be disabled"
""
get-csuser -identity $lyncuser | ft displayname,sipaddress
""

 $message = "Do you want to remove this user from Lync?"
  ""
  ""
  ""
 $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Remove User"
 $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Nope"
 $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)

 $result = $host.ui.PromptForChoice($title, $message, $options, 0)

 while ($result -eq 0)
 {
 disable-csuser -identity $lyncuser -whatif
 }
 
 while ($result -eq 1)
 {
 write-host "Start again"
 }
}



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>