We have a very specific file that comes once a week during a 1 hour window. We’ve been using Azure SFTP as a cost effective solution, earlier this year they changed up the billing so we’ve had to manually turn it on/off each week to avoid the $240+ costs of running 24/7. We’d like to automate this so that it enables and disables once a week.
I’ve been trying to figure out a way to automate the enable/disable of the blob feature but haven’t been able to find any way to do it with power automate or azure automation. I can’t be the only one looking to do this… is possible to run Azure CLI powershell in azure automation? I can’t find a definite answer in MSFT docs. Has anyone else found a way to do this?
Ideally i’d be able to run an az command like so in an azure automation powershell runbook.
az storage account update -g $resourceGroupName -n $stoAccountName --enable-sftp=true
And then run the false an hour later, but it doesn’t seem to execute.
There’s an excellent write up on CLI for SFTP by Jorge, with all the commands.
https://www.jorgebernhardt.com/azure-storage-blobs-enable-sftp-support/
Not sure where to go from here.
2
Answers
Yes, you can use Azure CLI commands in a PowerShell runbook.
Create an Azure Automation account.
Create a runbook and give commands to enable sftp and then disable after an hour .
So that this runbook can be scheduled once in every week.
commands:
Link schedule to schedule the time.
Give it required time
and schedule
Reference : Manage schedules in Azure Automation | Microsoft Learn
I tried following the @kavyaS answer but also ran into the same "socket operation encountered a dead network" errors as OP.
I got a bit further by allowing my managed identity to access other resources:
I changed
Connect-AzAccount
toConnect-AzAccount -Identity
and that succeeded, but theaz
commands were failing. I replaced them withSet-AzStorageAccount -EnableSftp $true
but this was failing due to my version of Powershell being 5.1. I deleted my runbook and made a new one in version 7.2 and got it working.Here is what I did:
and then did a similar one for switching the SFTP off.