Create Lync Account - Using Custom Menu/Trigger

Create Lync Account - Using Custom Menu/Trigger

So our procedure and policies changed on creating lync accounts.  This led me to create a powershell script to make this quick and easy, so I decided to share a powershell script I wrote.

I hope this helps some people out there.  Not promising any support though =D

  1. # ------------------ Start Script ------------------

  2. # Store request data passed to script - this must be first element in script 
  3. param (
  4.     $json = "none"
  5. )

  6. $jsondata = Get-Content $json -Encoding UTF8   #Encode if necessary
  7. $requestdata = ConvertFrom-Json $jsondata
  8.   
  9. #########################      LYNC INPUT    ############################

  10. $un=""                     #username for service account
  11. $pwi=""                    #password for service account
  12. $laddy=""                  #Lync server address
  13. $rp=""                     #RegistrarPool for lync
  14. $lp=""                     #Lync Policy to grant

  15. #########################        SDP INPUT      #########################

  16. $sdphost = ""              #SDP HOST 
  17. $techkey = ""              #SDP API Key
  18. $apifield = ""             #SDP Field containing the lync identity

  19. #########################    End Input needed   #########################

  20. # Extract required request data passed to script
  21. $requestid = $requestdata.request.WORKORDERID ##Ticket number for updating ticket later
  22. $lyncname = $requestdata.request.$apifield ##User's serves as the identity



  23. # Set API module URL and operation
  24. $url = $sdphost + "sdpapi/request/" + $requestid + "/notes"
  25. $method = "POST"
  26. $operation = "ADD_NOTE"

  27. # Create secure credentials
  28. $pw = convertto-securestring -AsPlainText -Force -String $pwi
  29. $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $un,$pw

  30. # Create Secure Session
  31. $s=new-pssession –connectionuri https://$laddy/ocspowershell -credential $cred

  32. # Import Powershell Session from Server
  33. Import-PsSession $s

  34. #Just an FYI, not fault tollerant
  35. #To proceed an e-mail account must be created if it has not already been created

  36. #enable the account
  37. Enable-CsUser -Identity $lyncname -RegistrarPool $rp -SipAddressType EmailAddress

  38. #grant correct client policy
  39. Grant-CsClientPolicy -Identity $lyncname -PolicyName $lp

  40. # Configure input data for add note operation in JSON format
  41. $inputdata = @"
  42. {
  43.     "operation": {
  44.         "details": {
  45.             "notes": {
  46.                 "note": {
  47.                     "ispublic": "false",
  48.                     "notestext": "Created Lync Account - $lyncname"
  49.                 }
  50.             }
  51.         }
  52.     }
  53. }
  54. "@

  55. # Configure paramaters for web API call
  56. $params = @{INPUT_DATA=$inputdata;OPERATION_NAME=$operation;TECHNICIAN_KEY=$techkey;format='json'}

  57. # Make web API call and record result
  58. $response = Invoke-WebRequest -Uri $url -Method POST -Body $params -UseBasicParsing
  59. #
  60. # ------------------ End Script ------------------

                  New to ADSelfService Plus?