Get Windows Azure subscription id using Powershell

Open Powershell prompt, & type the command to login…


PS C:\WINDOWS\system32> Login-AzureRmAccount

A pop-window appears, enter your credentials then the subscription id is displayed in the powershell console like this:


PS C:\WINDOWS\system32> Login-AzureRmAccount
Environment : AzureCloud
Account : youraccount@test.com
TenantId : 12345678-1234-abcd-1234-1234567890ab
SubscriptionId : 12345678-abcd-1234-abcd-1234567890ab
SubscriptionName : Pay-As-You-Go
CurrentStorageAccount :

Getting the cost of Azure Function

Currently (July 2017) the first 400,000 GB/s of execution and 1,000,000 executions are free. It is possible to use “armclient” to calculate the cost of running an Azure Function..

[armclient https://github.com/projectkudu/ARMClient can be installed using chocolatey]

PS C:\WINDOWS\system32>$apiVersion = "2016-06-01"
PS C:\WINDOWS\system32>$filter = "(name.value eq 'FunctionExecutionUnits') and timeGrain eq  duration'PT1M' and startTime eq 2017-07-25T13:50:00Z and endTime eq 2017-07-25T13:55:00Z and (aggregationType eq 'Total')"
PS C:\WINDOWS\system32>armclient GET /subscriptions/YOURSUBSCRIPTION/resourcegroups/YOURRESOURCEGROUP/providers/Microsoft.Web/sites/APPSERVICENAME/providers/microsoft.insights/metrics?`$filter=${filter}"&"api-version=${apiVersion}

Execute the above (changing date parameters, subscription key etc) & it will return values in MB-miliseconds so you must divide by 1024000 to get GB/secs (according to this link)

The output is something similar to this:

{
  "value": [
    {
      "data": [
        {
          "timeStamp": "2017-07-25T13:50:00Z",
          "total": 0.0
        },
        {
          "timeStamp": "2017-07-25T13:51:00Z",
          "total": 132736.0
        },
        {
          "timeStamp": "2017-07-25T13:52:00Z",
          "total": 0.0
        },
        {
          "timeStamp": "2017-07-25T13:53:00Z",
          "total": 0.0
        },
        {
          "timeStamp": "2017-07-25T13:54:00Z",
          "total": 0.0
        }
      ],
      "id": "/subscriptions/XXXXXXX/resourcegroups/.../.../providers/Microsoft.Insights/metrics/FunctionExecutionUnits",
      "name": {
        "value": "FunctionExecutionUnits",
        "localizedValue": "Function Execution Units"
      },
      "type": "Microsoft.Insights/metrics",
      "unit": "0"
    }
  ]
}

In this example the value would be:

132736 / 1024000 = 0.129 GB/s per execution (as the above results were for one execution)

The number of executions in 400000 GB/s = 400000 / 0.129 = 3 million approx. (But there is a cap of 1 million per month for free) Therefore, the function should be able to be invoked 1 million times per month for free (by my reckoning).

[

Create and test a user for a SQL Azure database

Create the user in SQL

One method to create a new database user is :

  • Open SQL Management Studio and connect to the SQL Azure instance (eg. XXX.database.windows.net).  You will need to allow connection from your IP address
  • From Management Studio, open a new query against the master database and create the user:
-- run this in the master database

CREATE USER dave WITH password='passwordhere!'
  •  Open a new query against the user database:
-- run this in the user database

CREATE USER dave FROM LOGIN dave

GO

EXEC sp_addrolemember 'db_owner', 'dave'

GO

-- grant execute to stored procs
GRANT EXECUTE TO dave
GO

To test connection from your Windows PC

You cannot connect to the database using the new login from SQL Management Studio because the new user does not have permission in the master database, and you are not able to set the user’s default database.

To work around this, try the following steps.

Create an new empty text file in a folder on your pc – the file may have any name but must have a .udl extension.

From Windows Explorer, double-click the file and your are presented with the Data Link Properties dialog.

On the provider tab select “Microsoft OLE DB Provider for SQL Server”.

On the Connection tab:

  • enter the name of your SQL Azure server (eg.  XXX.database.windows.net)
  • enter the user name and password
  • type in the name of the database (note that you will not be able to use the drop down list, you must type the name)
  • click the Test Connection button

 

To test execution permissions from your Windows PC

Download linqpad (https://www.linqpad.net/)

Enter your  connection details then you can run select statements, execute stored  procedures etc against your database.