#Converting the crednetials provided by the run as profile to a secure string so that they can be used to login.
$UserPassword = ConvertTo-SecureString -String $UserPassword -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential($UserCredential, $UserPassword)
$Service = Connect-AzureAD -Credential $Credential
#Initializing error checking
$Error.Clear()
$AllSKUs=@() #initialize so .Count property exists
$AcctSku=@() #initialize so .Count property exists
#Checking that we can pull the O365 SKU
$AllSKUs = Get-AzureADSubscribedSku
If (($Error) -or ($AllSKUs.Count -eq 0)) {
$api.LogScriptEvent('HealthService',55,2,"Problem getting O365 SKUs. $Error")
Exit
}
Else{
$AcctSku = ($AllSKUs | where {$_.SkuPartNumber -eq ($SkuType)})
If (($Error) -or ($AcctSku.Count -eq 0)) {
$api.LogScriptEvent('HealthService',55,2,"Problem getting O365 SKU. $Error")
Exit
}
}
#Checking to see how many licenses are consumed.
$ConUnits = $Acctsku.ConsumedUnits
#Adding Available units to property bag
$bag.AddValue('Consumed Units',"$Conunits")