Running Azure Powershell Inline Script - azure

I have a powershell script in order to make a backup of a SQL Database. I run the script locally, i run the script on TFS release phase with Powershell Script (not the azure powershell task), and everything went well.
Now, i want it to run it with the Azure PowerShell script: InlineScript because i want to remove the login part from my powershell. I saved the username \ password in the variables in order to login and i want to get rid of that
This is the script :
Please notice that i put the Login-AzureRmAccount because of the error. After this, i'm still getting it.
Error message:
[error]Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
[error]Run Login-AzureRmAccount to login.

As mentioned above please change the dropdown to "Azure Resource Manager" because in Azure classic this command will translate to Start-AzureSqlDatabaseCopy which does not have all the options available
https://learn.microsoft.com/en-us/powershell/module/servicemanagement/azure/start-azuresqldatabasecopy?view=azuresmps-4.0.0

Related

Azure PowerShell Runbook - Error output details column empty

I have an Azure PowerShell 7.1 runbook in an automation account that is executing as expected. The only issue I have is that my Error Output within the running job screen is always missing the details column. This means I have to click on each record to see what is in it, which is very tedious.
Note: I am using the Write-Error command to generate these messages inside a try/catch
You can see what I mean in the following picture:
Any help would be greatly appreciated.
Only the graphical PowerShell runbook type allows you to see the details column. After trying a workaround, I found a solution using a graphical PowerShell runbook.
I created a graphical PowerShell runbook and added my PowerShell onto the canvas. It was successfully executed and the following output with job details were displayed:
Aside from the runbook messages, you can also add Input and Output, as shown in the image below.
I've just executed a sample write-error command.
Write-Error "Hi"
Automation Account -> Runbook (type:Graphical Powershell Runbook):
Output:

How to Delete WEBSITE_TIME_ZONE application setting in Azure. Clicking DELETE does not remove it

I added a variable to the configuration settings area of my application and I need to delete it now because I do not need it or want that setting anymore. It's called WEBSITE_TIME_ZONE. I would like to get rid of the setting but I can't.
I have clicked on the delete button but it does not work. As soon as I refresh the page or log back in, the setting/variable (WEBSITE_TIME_ZONE) is there once again.
I have tried multiple browsers and clearing cache but none of that works.
I have clicked on Advanced Edit and tried to delete it from there as well but that does not work either. It just comes back after refreshing the page, (after saving the changes).
I have tried to edited the name and the value to bogus data which I then try and delete but that does not work either. I can't even actually edit the name of the setting, WEBSITE_TIME_ZONE. After an edit I save it and as soon as I come back to the page, the variable name WEBSITE_TIME_ZONE is there again.
I have stopped the app and tried to delete the entry and then start the app again but still does not work.
I tried running this command in command prompt on the SCM back end and that does not work either. It says 'az' is not recognized as an internal or external command, operable program or batch file.
az webapp config appsettings delete --name MyWebApp --resource-group MyResourceGroup --setting-names {setting-names}
I read about typing that in the Azure CLI by using the Azure Cloud Shell, but that seems to not be included in the subscription($200 USD / month) I am already paying for see image below. I thought this would work with PowerShell or the CMD on the KUDU console SCM area but I guess not. Looks like it has to be with Azure Cloud Shell which you have have to pay for on top of the normal costs...
Is there any way to delete this app setting without having to pay for yet another service? I have searched everywhere on the internet for this and every post that I see ends in the same, "I can't delete it".
Any suggestions?
Thank you!
I am able to delete the AppSetting WEBSITE_TIME_ZONE from Application Settings without any issues.
After refreshing, I can see the AppSetting is deleted.
I thought this would work with PowerShell or the CMD on the KUDU console SCM area but I guess not.
This command has to be run from Cloud Shell.
Open the Cloud Shell.
Tried to delete with the below command in Azure cloushell - Bash.
az webapp config appsettings delete --name YourWebAppName --resource-group YourRGName --setting-names {WEBSITE_TIME_ZONE}
It says 'az' is not recognized as an internal or external command, operable program or batch file.
As you are running the cloud shell for the first, you will get this error.
We need to set the Subscription and create storage account to run commands in Cloud shell.
Follow the steps mentioned in the MSDOC - Quickstart for Bash in Azure Cloud Shell
az account list
az account set --subscription 'YourSubscriptionName'

Azure Automation: Run PowerShell after AD user added

I'm reviewing Azure Automation, but I couldn't find out if it is possible to run a PowerShell script whenever a new user is added to Active Directory? The scenario I'm researching is whenever a new Office365 account is added through admin.microsoft.com then I want to configure some email preferences for this user. I have my PowerShell script tested already (so these preferences should be set correctly), but now I'm trying to find out how exactly this script should be executed right after account is added.
Thanks,
You can inspect the Azure AD Audit logs for new user creation. You can export the Diagnostic Settings (logs) to Azure Monitor (see doc).
The following is an idea but I never tried it myself:
In Azure Monitor -> Logs you can find for example this query:
Modify it according to your needs and create an alert rule. In the alert rule, you can set up an action group that triggers your automation account with the PowerShell script.

Azure powershell runbook don't show any output

I have a simple Azure PowerShell runbook script
workflow CheckIdentityColumns
{
Write-Output "Test Output"
}
When I am trying to test it I don't see any output.
Why?
This is because your flow is Powershell runbook not Powershell Workflow runbook .
In Powershell runbook, you don't need to use
workflow CheckIdentityColumns{}
declaration. This is the main reason why it doesn't work.
I tried your scenario and it worked for me. You can view the details below.
This happened to me in different scenario. The answer I got from Microsoft support was that the Runbook in the cache is still the older one, i.e. an empty Runbook in your case. All you need to do is:
Publish the Runbook and edit and test again
If it still doesn't work then clear the cache and restart your browser
Test Runbook:
Output:

Minimal required privileges to run a PowerShell script from a Scheduled Task as a Service Account

I'm trying to run a SharePoint Warm-up PowerShell script (spbestwarmup) from a Scheduled Task under/as a certain service account (also run when user is not logged on). This script tries to get elevated rights and outputs some logging to the Windows 'Application' Event Log.
I already tried everything mentioned in this SO answer here: How to run a PowerShell script from a batch file
The only way I got it to work was by pointing the scheduled task to a .bat file with the following content:
powershell -command "& 'D:\SPBestWarmUp.ps1' "
which triggers the PowerShell script file. AND I had to add the service account to the local built-in 'Administrators' user group on my SharePoint server.
This last action, adding the user to the 'Administrators' group isn't allowed in my customers IT infrastructure, because of security reasons. They use, rightfully off-course, the law of least privilege. So my question is:
What MINIMAL rights/privileges/policies etc. does a service account need in this case? So I don't need to assign local Administrator rights to it.

Resources