So, I installed the Az.Accounts module and tried this script on ISE Editor on Adaxes server, working fine.
As soon as I try same code within Adaxes PS Editor I get error:
Error Message
Entry point was not found. Could not find tenant id for provided tenant domain 'yyy'. Please ensure that the provided service principal 'xxx' is found in the provided tenant domain. Stack trace: at <ScriptBlock>, <No file>: line 20
Line 20 is Connect-AzAccount
command
Import-Module Az.Accounts
$vmName = "%cn%"
$Context.LogMessage("vmName $vmName", "Information")
$v = $PSVersionTable.PSVersion.major
$Context.LogMessage("$v", "Information")
# Define your Azure credentials
$clientId = "xxx"
$tenantId = "yyy"
$clientSecret = "zzz"
# Sign in to Azure using the service principal
try {
$creds = [System.Management.Automation.PSCredential]::new($clientId, (ConvertTo-SecureString $clientSecret -AsPlainText -Force))
$con = Connect-AzAccount -Tenant $tenantId -Credential $creds -ServicePrincipal
$Context.LogMessage("Connect-AzAccount", "Information")
# Set the context to the desired subscription
try {
$sub = Select-AzSubscription -SubscriptionId $subscriptionId -ErrorAction Stop
$Context.LogMessage("Select-AzSubscription", "Information")
try {
$resourceGroup = (Get-AzVM -Name $vmName).ResourceGroupName
$Context.LogMessage("ResourceGroupName $resourceGroup", "Information")
try {
#$action = Start-AzVM -ResourceGroupName $resourceGroup -Name $vmName -ErrorAction Stop
$action = Stop-AzVM -ResourceGroupName $resourceGroup -Name $vmName -ErrorAction Stop -Force
$Context.LogMessage("Starting machine", "Information")
} catch {
$Context.LogMessage("Starting machine failed due to `r`n$($_.Exception.Message)", "Error")
}
} catch {
$Context.LogMessage("ResourceGroupName failed due to `r`n$($_.Exception.Message)", "Error")
}
} catch {
$Context.LogMessage("Select-AzSubscription failed due to `r`n$($_.Exception.Message)", "Error")
}
# Disconnect from Azure
$dis = Disconnect-AzAccount
} catch {
$Context.LogMessage("Connect-AzAccount failed due to `r`n$($_.Exception.Message)", "Error")
}