需搭配 Connect-AzAccount with Saved Encryped Credential in Powershell 實現自動化
Param (
[String]$VMName = ''
);
if ($VMName -eq '') {
exit;
};
Set-Location -Path ('C:\ChangeVMPublicIP');
if (Test-Path -Path (($VMName) + '.Lock')) {
if ((Get-Date) -lt (Get-Item -Path (($VMName) + '.Lock')).LastWriteTime.AddMinutes(5)) {
write-Host 'VM Locked';
exit;
};
};
$VMName | Out-File (($VMName) + '.Lock');
$CredentailFileName = 'AzCredential.txt';
$AzSubscriptionID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';