- Hands-On Cloud Solutions with Azure
- Greg Leonardo
- 131字
- 2021-06-10 19:44:40
Deploy-AzureResourceGroup.ps1
In this PowerShell script, we are going to check to see if you are logged in. If you are not logged in, the script will run a validation on your script, create a storage area, upload files to the storage, assign a 4-hour access key, and then run the deployment. The majority of PowerShell is generated when you select an Azure Resource Manager in Visual Studio, but I did add the following login function to help ensure that I am logged in to the right tenant:
function Check-Login
{
$needLogin = $true
Try
{
$content = Get-AzureRmContext
if ($content)
{
$needLogin = ([string]::IsNullOrEmpty($content.Account))
}
}
Catch
{
if ($_ -like "*Login-AzureRmAccount to login*")
{
$needLogin = $true
}
else
{
throw
}
}
if ($needLogin)
{
Login-AzureRmAccount
}
}
Check-Login