I've gotta be missing something obvious, right?

Copper Contributor

Hello community!

 

Was directed here for assistance.  Trying to create a simple onlineMeeting using either Application (or Delegated) authorized runBook.  The modules work with other runBooks - but this one is struggling!

$env:PNPPOWERSHELL_UPDATECHECK = "OFF"
$env:PNPLEGACYMESSAGE = "false"
$env:ProgressPreference = "silentlyContinue"
$env:ErrorActionPreference = "Stop"
function RESETLOOP {
    $global:stopLOOP = $false
    $global:loopCOUNT = 1
}
function HANDLEERROR {
    $global:errorMSG = $_
    [int]$errorCODE = $errorMSG.exception.response.statuscode
    if ($loopCOUNT -gt 2) {
        write-output "Halting program!  Error'd command JSON below:"
        write-output ($errorMSG.invocationinfo|convertto-json)
        $wriOU = "Error message ---(> [ "+$errorMSG.exception.message+" ]"
        write-output $wriOU
        $wriOU = "Error'd on command ---(> [ "+$errorMSG.invocationinfo.line+" ]"
        write-output $wriOU
        $wriOU = "Last configured URL ---(> [ "+$URL+" ]"
        write-output $wriOU
        $wriOU = "Line in program ---(> [ "+$errorMSG.invocationinfo.scriptlinenumber+" ]"
        write-output $wriOU
        throw "Failed!"
        break
        return $null
    } else {
        $wriOU = "Error count: [ "+$loopCOUNT+" ]"
        write-output $wriOU
        start-sleep -seconds 3
        $global:loopCOUNT = $loopCOUNT+1
        $global:stopLOOP = $true
    }
}
$tenantDATA = get-automationvariable -name "DATA"
$tenantDATA = $tenantDATA.split("?")
$clientID = $tenantDATA[2]
$tenantID = $tenantDATA[3]
$clientSECRET = $tenantDATA[4]
$contentTYPE = "application/x-www-form-urlencoded"
$betaGRAPH = "https://graph.microsoft.com/beta"
$startDateTIME = [datetime]::utcnow.addhours(1).tostring("yyyy-MM-ddThh:mm:00.000-7:00")
$endDateTIME = [datetime]::utcnow.addhours(2).tostring("yyyy-MM-ddThh:mm:00.000-7:00")
$eventSTART = $startDateTIME
$eventEND = $endDateTIME
$eventTITLE = "This here is my live event title name!"
$scriptVERSION = "1.0.3"
$wriOU = "Script Version: [ "+$scriptVERSION+" ]"
write-output $wriOU
RESETLOOP ; do {
    try {
        $a_BODY = @{
            client_id = $clientID
            client_secret = $clientSECRET
            grant_type = "client_credentials"
            scope = "https://graph.microsoft.com/.default"
        }
        $URL = "https://login.microsoftonline.com/"+$tenantID+"/oauth2/v2.0/token"
        $buildTOKEN = invoke-webrequest -uri $URL -contenttype $contentTYPE -body $a_BODY -method post -usebasicparsing
        $accessTOKEN = ( $buildTOKEN.content|convertfrom-json )
        $a_TOKEN = $accessTOKEN.access_token
        $a_HEAD = @{
            "authorization" = "bearer "+$a_TOKEN
            "content-type" = "application/json"
        }
        $stopLOOP = $false
    } catch { HANDLEERROR }
} while ( $stopLOOP -eq $true )
RESETLOOP ; do {
    try {
        $meetingBODY = @{
            "startDateTime" = $eventSTART
            "endDateTime" = $eventEND
            "subject" = $eventTITLE
        }|convertto-json
        $URL = $betaGRAPH+"/me/onlineMeetings"
        $onLineMEETING = invoke-restmethod -uri $URL -body $meetingBODY -head $a_HEAD -method post
        write-output ( $onLineMEETING|convertto-json )
        $stopLOOP = $false
    } catch { HANDLEERROR }
} while ( $stopLOOP -eq $true )

Gives me:

Screen Shot 2022-09-06 at 11.16.18 AM.png

 

https://docs.microsoft.com/en-us/graph/api/application-post-onlinemeetings?view=graph-rest-beta&tabs...

 

Any guidance would be ever so amazing!!

TIA

~WM

0 Replies