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
- # ------------------ Start Script ------------------
- # Store request data passed to script - this must be first element in script
- param (
- $json = "none"
- )
- $jsondata = Get-Content $json -Encoding UTF8 #Encode if necessary
- $requestdata = ConvertFrom-Json $jsondata
-
- ######################### LYNC INPUT ############################
- $un="" #username for service account
- $pwi="" #password for service account
- $laddy="" #Lync server address
- $rp="" #RegistrarPool for lync
- $lp="" #Lync Policy to grant
- ######################### SDP INPUT #########################
- $sdphost = "" #SDP HOST
- $techkey = "" #SDP API Key
- $apifield = "" #SDP Field containing the lync identity
- ######################### End Input needed #########################
- # Extract required request data passed to script
- $requestid = $requestdata.request.WORKORDERID ##Ticket number for updating ticket later
- $lyncname = $requestdata.request.$apifield ##User's serves as the identity
- # Set API module URL and operation
- $url = $sdphost + "sdpapi/request/" + $requestid + "/notes"
- $method = "POST"
- $operation = "ADD_NOTE"
- # Create secure credentials
- $pw = convertto-securestring -AsPlainText -Force -String $pwi
- $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $un,$pw
- # Create Secure Session
- $s=new-pssession –connectionuri https://$laddy/ocspowershell -credential $cred
- # Import Powershell Session from Server
- Import-PsSession $s
- #Just an FYI, not fault tollerant
- #To proceed an e-mail account must be created if it has not already been created
- #enable the account
- Enable-CsUser -Identity $lyncname -RegistrarPool $rp -SipAddressType EmailAddress
- #grant correct client policy
- Grant-CsClientPolicy -Identity $lyncname -PolicyName $lp
- # Configure input data for add note operation in JSON format
- $inputdata = @"
- {
- "operation": {
- "details": {
- "notes": {
- "note": {
- "ispublic": "false",
- "notestext": "Created Lync Account - $lyncname"
- }
- }
- }
- }
- }
- "@
- # Configure paramaters for web API call
- $params = @{INPUT_DATA=$inputdata;OPERATION_NAME=$operation;TECHNICIAN_KEY=$techkey;format='json'}
- # Make web API call and record result
- $response = Invoke-WebRequest -Uri $url -Method POST -Body $params -UseBasicParsing
- #
- # ------------------ End Script ------------------
New to ADSelfService Plus?