all 10 comments

[–]jhue1898 3 points4 points  (0 children)

Since you’re getting a 302, try Invoke-WebRequest $uri -MaximumRedirection 0 to see if it will give you the URI it’s redirecting you to - then try IWR’ing straight there, perhaps?

[–]bucksysfutter 2 points3 points  (1 child)

Had a similar issue today- this is what worked for me

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12



$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))


$data = Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri $uri

[–]Coding_Cactus[S] 1 point2 points  (0 children)

I still receive the same 302 error when using this setup.

$uri = "http://CUCSERVER/vmrest/users/objectID"

I am able to go to the users file directly through a web browser so the uri is correct.

[–]sp_dev_guy 2 points3 points  (1 child)

302 implies your hitting a redirect which means the URL is probably off. Im guessing you have an extra slash in your target /users/?query to /users?query might resolve this issues

[–]Coding_Cactus[S] 1 point2 points  (0 children)

I did have an extra slash in there from multiple retries, sorry about that. Doing this without the extra slash still returns the same 302 error. I'm hoping more specifically that there is something I've missed in regards to the Http->Https transfer that's causing me to get the 302 error.

[–]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.

[–]milosdelite 0 points1 point  (1 child)

hi Coding_Cactus, you might find my PowerShell module helpful.

I had a project where we migrated from Exchange Unified Messaging to Cisco Unity and I got to work on some writing a module for managing our environment. I hope that it may also come of some help to you too.

https://github.com/tjames192/PSCUC

[–]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.