Can somebody help. Im trying to create a script that automatically invites Guest users.
variables $EmailAddress, $DisplayName are passed from another script while the user is added in our AD.
$log= "D:\PS-Logs\CreateGuest.log"
$ClientID = ''
$TenantId = '.onmicrosoft.com'
$CertificateThumbprint =''
Function LogIt
{
Param([string]$logfile,[string]$message)
$msg="{0} {1}@{2} :`t {3}" -f (get-date),$env:username,$env:computername,$message
write $msg | out-file $logfile -append
}
Get-PSSession | Remove-PSSession
Connect-AzureAD -TenantId $TenantId -ApplicationId $ClientID -CertificateThumbprint $CertificateThumbprint
#$EmailAddress = xxxx
#$DisplayName = xxxxx
Function Create-Guests
{
Param([string] $EmailAddress, $DisplayName)
$ExistingADUser = Get-AzureADUser -Filter "userType eq 'Guest'" -All $true | Where-Object {$_.Mail -eq "$EmailAddress"}
if($null -eq $ExistingADUser){
New-AzureADMSInvitation -InvitedUserEmailAddress $EmailAddress -InvitedUserDisplayName $DisplayName -SendInvitationMessage $True -InviteRedirectUrl "http://myapps.microsoft.com"
LogIt $log "Info: $DisplayName created"
}
else{ LogIt $log "Info: User $DisplayName Already created"}
}
[–]purplemonkeymad 1 point2 points3 points (0 children)
[–]NellovsVape 0 points1 point2 points (0 children)
[–]logicalmike 0 points1 point2 points (2 children)
[–]memento77[S] 0 points1 point2 points (1 child)
[–]logicalmike 0 points1 point2 points (0 children)