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 } } } } }