Home » Scripts

Category: Scripts

Azure Invoice API – download all invoices

Since end of April 2017, there is the new Azure Invoice API available. This API allows to download the Azure invoices for a subscription as PDF file. This does currently not work for Enterprise Agreements, but according to the blog post (https://azure.microsoft.com/en-us/blog/azure-billing-reader-role-and-preview-of-invoice-api/) it is planned.
The downloaded PDF is the invoice itself. The API does currently only support to create and download invoice pdfs. It does not support to access specific costs (e.g. per resources), because this is part of the billing API. I already blogged about the billing API here: Use the Azure Billing API and calculate the costs
Read more

Microsoft Cognitive Services – Translation API

If you want to programmatically translate text from one language to another, then the Translation service (translation api) is the right one for you. The Microsoft Translation Service just requires an authentication and then you can easily translate text from one language to another. It sounds simple…and it is simple! In this blog post, I’ll quickly describe how to create the translation service and how to use it with C#, Powershell and Node.js.

Create the translation service in Azure

The translation service is part of the cognitive services and can therefore be found as cognitive service in the Azure portal:

Read more

Chocolatey – Package management for Windows

I already blogged about the package management module of the Powershell and how great and awesome it is (Powershell package management – NuGet, Chocolatey and Co). It just can happen, that the installation of some modules from chocolatey do not work as expected. I had this e.g. for Firefox or Chrome. In such cases, it’s better to directly use chocolatey (choco.exe).

Fastest way to install and run it is to open Powershell as administrator and execute the following script:

Set-ExecutionPolicy Unrestricted
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

This installs chocolatey and adds it to the path. After that, you should be able to run chocolatey:

choco install firefox -x86
choco install notepadplusplus -x86 # 64 bit version does not have all plugins

Read more

Export Azure Resources via Powershell to CSV

This post shows a Powershell script that connects to Azure and exports all resources from multiple subscriptions to a CSV file. It also shows how this script can be used inside of a scheduled task which creates the CSV file on a daily base.

Exporting all the resources can be achieved with the following commandlets:

Add-AzureRmAccount                                  # login to your azure account
Set-AzureRmContext -SubscriptionID $subscriptionId  # set/change the subscription
Get-AzureRmResource | Export-CSV "c:\temp\data.csv" # get the resources and export it to CSV file

This script just exports the data of one subscription and simply writes it to a csv file. If we want to have a reusable script which exports the data of all of my subscriptions, then we should extend it:

Read more

Invoke WebRequests via Powershell

It’s quite simple to invoke WebRequests via Powershell if you have Powershell Version 3.0 or higher:

Invoke-WebRequest "https://codehollow.com"

If you have Powershell Version 2.0 or 1.0 , you’ll receive the following error:

invoke-webrequest : The term ‘invoke-webrequest’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:18
+ invoke-webrequest <<<< “http://www.codehollow.com”
+ CategoryInfo : ObjectNotFound: (invoke-webrequest:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Because you need the Powershell Version 3.0 or higher as described here: https://technet.microsoft.com/en-us/library/hh849901.aspx

There are two ways how to solve this. Read more