function New-PPTAuth { begin { Write-Host "[ Info ] " -ForegroundColor Green -nonewline Write-host "Creating authentication profile" -ForegroundColor Cyan #Start-Process -FilePath $Global:pptConfig.pacPath & $Global:pptConfig.pacPath auth clear | ForEach-Object { Write-Host "[ Info ] " -ForegroundColor Green -nonewline Write-host "$_" -ForegroundColor Cyan } } process { $isAuth = $false & $Global:pptConfig.pacPath auth create --cloud UsGov --deviceCode | ForEach-Object { if ($_ -match 'To sign in, use a web browser to open the page') { Write-Host "[ Info ] " -ForegroundColor Green -nonewline Write-host "$_" -ForegroundColor Cyan Set-Clipboard -Value "$(($_ -split "To sign in, use a web browser to open the page | and enter the code | to authenticate.")[2])" Start-Process microsoft-edge:https://microsoft.com/devicelogin -OutVariable procout } else { if ($_ -match 'authenticated successfully') { $isAuth = $true } Write-Host "[ Info ] " -ForegroundColor Green -nonewline Write-host "$_" -ForegroundColor Cyan } } } end { if($isAuth) { Write-Host "[ Info ] " -ForegroundColor Green -nonewline Write-host "Authentication complete" -ForegroundColor Cyan return $true } else { Write-Host "[ Error ] " -ForegroundColor Yellow -nonewline Write-Host "No profiles were found on this computer" -ForegroundColor Yellow return $false } } } New-Alias -Name auth -Value New-PPTAuth -Description 'posh-PowerPlatformToolkit - New-PPTAuth alias' -Force