Public/Get-GraphOauthCookie.ps1
function Get-GraphOauthCookie { param ( [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [Alias('URL')] [string]$BaseURL = 'https://teams-stag.appvity.com/login?returnCookie=1' ) Process { Write-Verbose "URL: '$BaseURL'" $Params = @{ TypeName = 'System.Windows.Forms.Form' Property = @{ Width = 440 Height = 640 } } $Form = New-Object @Params $Params = @{ TypeName = 'System.Windows.Forms.WebBrowser' Property = @{ Width = 420 Height = 600 Url = $BaseURL } } $Web = New-Object @Params $DocumentCompleted_Script = { #Write-Host '-------------Url.AbsoluteUri------------------' #Write-Host $web.Url.AbsoluteUri if ($web.Url.AbsoluteUri -match "error=[^&]*|c=[^&]*"){ $form.Close() } } # ScriptErrorsSuppressed must be $false or AD FS tenants will fail on Windows Integrated Authentication pages $web.ScriptErrorsSuppressed = $false $web.Add_DocumentCompleted($DocumentCompleted_Script) $form.Controls.Add($web) $form.Add_Shown({ $form.Activate() }) [void]$form.ShowDialog() $QueryOutput = $web.Url.Query #[System.Web.HttpUtility]::ParseQueryString($web.Url.Query)# $QueryOutput = $QueryOutput.replace("?c=","")#graphNodeCookie= [void]$form.Close() [void]$Web.Dispose() [void]$Form.Dispose() return $QueryOutput } } |