Functions - output function 2 who is used in function 1 shows too late

Hi,

I’m busy with a full admin tool to manage office365 easy and quickly. I made many functions and two of them i translate all so there could be a typo.

The function create_user asks the input from the keyboard by read-host and put this in a var. After the read-host accountname i will show the function show_license with the output from the command: write-host -f red “All licences in the tenant” and
Get-MsolAccountSku. The first write-host works fine but Get-MsolAccountSku shows the output after confirmation question.

Is there someone who can show me in example / explain why this goes wrong?

function create_user{ write-host -f Magenta " --- create user"
$firstname= Read-Host "Firstname" $lastname = Read-Host "Lastname" $Displayname = Read-Host "Displayname" $Accountname = Read-Host "Accountname (j.jansen@domein.nl)" . show_license
$LicenseAssignment = Read-Host "Which license should be used for this user?" $userPassword = Read-Host "Password" $usagelocation = Read-Host "Usagelocation"
$confirmation = Read-Host "Are you sure to create $Displayname ? Y/N" if ($confirmation -eq 'y') { try { if ($LicenseAssignment -eq "") { New-MsolUser -DisplayName $Displayname -FirstName $firstname -LastName $lastname -UserPrincipalName $Accountname -Password $userPassword -UsageLocation $usagelocation -ErrorAction Stop } else{New-MsolUser -DisplayName $Displayname -FirstName $firstname -LastName $lastname -UserPrincipalName $Accountname -LicenseAssignment $LicenseAssignment -UsageLocation $usagelocation -Password $userPassword -ErrorAction Stop }Write-Host -f Green $Accountname "-> Succesfully added." } catch { Write-Host -f Red $Accountname "-> FAILED $($error[0])" }
}
}
function show_license($user){ if ($user -eq $null){ write-host -f red "All licences in the tenant" Get-MsolAccountSku } else{ write-host -f Magenta "Show license from $user" $licensePlanList = Get-AzureADSubscribedSku $userList = Get-AzureADUser -ObjectID $user | Select -ExpandProperty AssignedLicenses | Select SkuID $userList | ForEach { $sku=$_.SkuId ; $licensePlanList | ForEach { If ( $sku -eq $_.ObjectId.substring($_.ObjectId.length - 36, 36) ) { Write-Host $_.SkuPartNumber } } } } }

Gerard, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

When you post code, error messages, sample data or console output format it as code, please.
In the “Text” view you can use the code tags “PRE”, in the “Visual” view you can use the format template “Preformatted”. You can go back edit your post and fix the formatting - you don’t have to create a new one.
Thanks in advance.

You may show the “confirmation question” you get (formated as code please). Please keep in mind - we cannot see your screen and we cannot read your mind.