Public/User/Add-PopuliUserAccess.ps1
function Add-PopuliUserAccess { [alias("Get-PopuliStudent")] [CmdletBinding(DefaultParametersetName='PersonId', PositionalBinding=$true)] param ( [Parameter(ParameterSetName='PersonId', Mandatory=$true)][string]$PersonId, [Parameter(Mandatory=$false)][string]$NewUsername, [Parameter(Mandatory=$false)][bool]$SendWelcomeEmail = $true, [Parameter(Mandatory=$false)][ValidateLength(200,999)][string]$PopuliToken = $env:PopuliToken, [Parameter(Mandatory=$false)][ValidatePattern('^(?i)https:\/\/\S+\.populiweb\.com\/?$')][string]$BaseUrl = $env:PopuliBaseUrl ) try { if ($BaseUrl -match '\/$') { $BaseUrl = $BaseUrl -replace '\/$' } $header = @{ Authorization = $PopuliToken } $body = @{ task = 'addUser' person_id = $PersonId send_welcome_email = $SendWelcomeEmail } if ($PSBoundParameters.Keys -contains 'NewUserName') { $body += @{username = $NewUsername} } $response = Invoke-RestMethod -Uri "$BaseUrl/api/" -Method POST -ContentType 'application/x-www-form-urlencoded' -Body $body -Headers $header Write-Log "Adding User access to ""$PersonId"". Result: $($response.response.result)" -PersonId $PersonId return $response.response.result } catch { Write-Log "Error getting tags" -LogType: error -ErrorObject $_ -PersonId $PersonId Write-Error $_ return $null } } |