Home » Powershell

Category: Powershell

SSH for Windows Powershell

This post is a short note on how to use SSH with Windows Powershell. I will quickly describe three ways: OpenSSH, Posh-SSH and Putty. I found a few blog posts about how to use SSH with Powershell and most of them are referring Posh-SSH. Posh-SSH is nice, but I think OpenSSH is much easier to use because it works the same way as the ssh command in linux.

Open SSH for Powershell

If chocolatey is not yet installed, you must at first install it. Run the Powershell as administrator and execute:

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

If chocolatey is already installed, run the Powershell as administrator and execute the following command to install OpenSSH, to reload the environment variables and to connect to a client:

choco install openssh                # installs open ssh
refreshenv                           # reloads the environment variables
ssh remoteClient -i "MyKeyPair.pem"  # connects to remoteClient via ssh

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

Working with Azure functions (part 1 – Powershell)

Azure functions, also called Azure function apps, are a great way to build simple components – functions – and run them in the cloud (also called “serverless computing” or FaaS). Those functions are triggered via timer, http trigger, webhooks and many others. The functions itself can be implemented in one of the following languages: C#, F#, JavaScript/Node.js, PHP, Powershell, Python, Batch, Bash.

It’s important to mention, that functions have a timeout of 5 minutes – so if you have an endless running job, then you should go for webjobs. The idea behind Azure functions is, that you execute just a small piece of code. That’s why there is this timeout. Running those small pieces is very cheap. The first 1.000.000 executions and the first 400.000 GB/s of execution are for free. 400.000 GB/s means: Let’s assume you have a memory size for your function app of 512 MB: 400.000*1024 / 512 = 800.000 seconds are for free. So you can execute your function 1 Mio times with an average execution time of 1.25 seconds and it’s still free.

I will use the Azure functions to build two “applications”/functions. One of them will read data from my RSS feed and write it to my table storage. The second one will read all my upcoming events from https://www.meetup.com/ and create an iCal file out of it so that I can add it to my calendar.

Read more

Powershell package management – NuGet, Chocolatey and Co

There is a new feature available for Powershell since the release of Windows 10. It’s a (open source) package management tool called OneGet. It allows o add different package managers (NuGet, chocolatey, …) and install packages from those sources.
That’s really awesome as we know the useful apt-get or as developers in the Microsoft area – the nice NuGet Package manager. Such package management is now available for Powershell! So let’s have a look on the basic features of it and let’s start with NuGet for Powershell.

Read more

Automatically set Azure app settings

The bigger your applications are, the more settings you’ll have in the web.config file. If you run your webapp in Azure and there are a lot of settings, then it’s annoying to set all the values manually. It would be much easier, if Azure would automatically show all app settings in the section in the azure portal and you just need to adapt them. Unfortunately there this doesn’t work out of the box and therefore the application settings will look like:
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