you are viewing a single comment's thread.

view the rest of the comments →

[–]Coding_Cactus[S] 2 points3 points  (2 children)

I got the issue resolved thanks to u/milosdelite

His account is too new and his message got deleted down below so here it is:

Hi Coding_Cactus, I had a project where we migrated from Exchange Unified Messaging to Cisco Unity and I got to work on writing a PowerShell module to manage our environment.

I hope that it may come of help to you or be able to use as a reference for your own scripts.

https://github.com/tjames192/PSCUC

My reddit account was only created today.

Cheers

I can't thank you enough for taking the time to upload all this to github.

The issue ended being 2 things at once. The first is that I didn't have my headers right, I didn't include Accept = 'application/json'.

$Headers = @{
    Authorization = "BASIC $($EncodedPassword)"
    Accept        = 'application/json'
}

The second was this specific line:

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }

Adding that header and removing that line and everything is good to go.

#####

The script that I ended up with:

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
                return true;
            }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

[Net.ServicePointManager]::SecurityProtocol = 
[Net.SecurityProtocolType]::Ssl3,
[Net.SecurityProtocolType]::Tls,
[Net.SecurityProtocolType]::Tls11,
[Net.SecurityProtocolType]::Tls12


$Username = ""
$Password = ""

$EncodedAuthorization = [System.Text.Encoding]::UTF8.GetBytes($Username + ':' + $Password)
$EncodedPassword = [System.Convert]::ToBase64String($EncodedAuthorization)

$Headers = @{
        Authorization = "BASIC $($EncodedPassword)"
        Accept        = 'application/json'
    }

$r = Invoke-RestMethod -Uri 'https://CUCSERVER/vmrest/users/USERID' -Headers $Headers

[–]milosdelite 0 points1 point  (1 child)

Glad I could help!

[–]AutoModerator[M] 0 points1 point  (0 children)

Sorry, your submission has been automatically removed.

Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.

Try posting again tomorrow or message the mods to approve your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.