Skip to main content

Posts

Showing posts from 2014

PowerBus–Sending and receiving ServiceBus messages from powershell

I have been working on implementing ServiceBus using powershell. There is to my knowledge no modules/scripts available to communicate with ServiceBus from powershell. There is a Azure powershell module on Git that enables you to create/manage Queues/namespaces, however not to send/receive messages. Let’s just jump right in and test it. Requrements: Create a Queue on Azure and recceive the connection Information (connectionstring) ( http://azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-queues/ ) Download/clone the PowerBus repository on bitbucket ( https://bitbucket.org/torgro/powerbus/wiki/Home ) Unblock the downloaded zip file (unblock-file –path c:\temp\PowerBus.zip) Copy the module to one of your module paths Import-Module –Name PowerBus How to use After importing these commands will be available for you: Get-BusMessage and Send-BusMessage are used for receiving and sending messages to the Queue. These functions need to

Powershell - Get loaded assemblies

Sometimes you need to check if an assembly is loaded in your session. How can you check if an assembly is loaded in your current session? You can use this function I have created or roll you own command using [System.AppDomain] and the static method GetAssemblies(). Code: Cheers Tore

Powershell - List information about your WIFI networks

This is just a quick post about this new function I have created. Basically this is a text-output to powershell object output function that uses netsh to query the WIFI information. This illustrates the importance of changing the authentication level on your WIFI-network. No matter if you use WEP/WPA/WPA2 your password is available in clear text in your profile. Cheers Tore

How to undo an Powershell Desired State Configuration (DSC)

I saw a post on this on Stackexchange.com ( link ) asking about how you could undo/remove a configuration. I understand the question and logic behind it. I would love for DSC to have this functionally, however this is not how it works today. Perhaps some day in the future, however I would not bet on it. If you read this post, it will make perfect sense. The life of an Desired State Configuration (DSC) An configuration item/resource in DSC has to states it lives and cares about. Ensure equals PRESENT or ABSENT . The current state of the item and/or node (the target of the configuration) before the configuration is applied is not "stored" anywhere. It is just how the node is configured before the configuration is committed on the node. Furthermore any individual who has access to the node, may install/configure features that you are not aware of. That is of course if you do not create a configuration consisting of all possible combinations of a configuration state

Build your local powershell module repository - ProGet

So Windows Powershell Blog released a blog a couple of days ago ( link ). Not too long after, a discussion emerged about it being to complicated to setup. Even though the required software is open source (nugetgalleryserver), it looks like you need to have Visual Studio Installed to compile it. I looked into doing it without visual stuidio, however I have been unable to come up with a solution. I even tweeted about it since I am not an developer. Maybe someone how is familiar with “msbuild” could do a post on how to do it without VS. Anyhow one of my twitter-friends ( @ sstranger ) came to the rescue and pointed me in the direction of ProGet , hence the title of this post. ProGet comes in 2 different licensing modes Free (reduced functionality) Enterprise (paid version with extra features) The good news is that the free version supports hosting a local PowershellGet repository which was my intention anyway. So off we go and create a Configration that can install ProGet for us. T

ConfigMgr – Scripting with powershell module

I read David O’Brien’s post about automation with SCCM. He identified an issue with the SCCM-Powershell module that requires a manual “job” before you can start to automate with the module. You have to start Powershell from the SCCM-console to import the certificate that the module is signed with. Read all about it in his post. I am only providing a solution for you so you do not have to do regular “manual” labour (no pun intended). Above you will find an DSC script resource you can use in your configurations and a function you can use in your scripts. Look me up on Twitter if you have any questions or leave a comment. Cheers Tore

Toying with audio in powershell

Controlling mute/unmute and the volume on you computer with powershell. Add-Type -TypeDefinition @' using System.Runtime.InteropServices; [Guid("5CDF2C82-841E-4546-9722-0CF74078229A"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IAudioEndpointVolume { // f(), g(), ... are unused COM method slots. Define these if you care int f(); int g(); int h(); int i(); int SetMasterVolumeLevelScalar(float fLevel, System.Guid pguidEventContext); int j(); int GetMasterVolumeLevelScalar(out float pfLevel); int k(); int l(); int m(); int n(); int SetMute([MarshalAs(UnmanagedType.Bool)] bool bMute, System.Guid pguidEventContext); int GetMute(out bool pbMute); } [Guid("D666063F-1587-4E43-81F1-B948E807363F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IMMDevice { int Activate(ref System.Guid id, int clsCtx, int activationParams, out IAudioEndpointVolume aev); } [Guid("A95664D2-9614-4F35-A746-DE8DB63617E6"), Inte

Powershell MSI - Productcode and ProductName

Working with msi files can be a challenge if you are not used to packaging applications and have access to tools that provide information about them. Then there comes a time when you need to do some automation with an MSI-package and you sure would like to have a tool to access 2 of the core properties of an msi; ProductCode and ProductName .  Here is something I have built and it is based upon the DSC resource Package that got updated in wave 3.  Sourcecode is on bitbucket: Cheers Tore

Desired State Configuration - ConfigurationData

Update 12.10.2016 - More functions added to repro some while ago This module has been laying dormant in my BitBucket repro. Looks like people are realizing that DSC is about to become a thing. Need some feedback if this is a way of handling your Configuration data in DSC. I will publish it to the PowershellGallery if people find it useful. Should probably do a code review as well since this was written over 2 years ago :-0. Update 19.04.2014 - Module (beta) added to bitbucket here When you start to work with DSC, you quickly realize that separating the infrastructure from the configuration is a huge benefit and somewhat of a curse. You start to read blogs and webposts explaining how you can specify the configurationdata to you configuration, however for the people that does not speak powershell (yes they are out there) and/or still don’t like it, it looks kind of “untidy”. Example: Yes, Beelzebub has joined the party, pure evil. Just to explain ConfigurationData in Desired

Desired state configuration – xComputer domain join

Here we go again. This is just a short post on how to use the resource to join a computer to the domain. Steps we will perform: Download the resource from here . Follow the instructions to add it to the modules folder on you target computer. Create configuration data Build a very short configuration Here is the configuration data we will use: $ConfigData = @{ AllNodes = @( @{ NodeName = "*" PSDscAllowPlainTextPassword = $true } @{ NodeName = "localhost" } ); NonNodeData = @{           domainName = "try.local"       } } A few points to note here: We have a node called “*”. It is kind of a “wildcard”, however wildcards are not supported in DSC. All key/values you specify in this node, will get inherited by all nodes. That is why I do not need to specify the PSDscAllowPlainTextPassword for my node localhost. Ther

Powershell – Get-EvntLog

Today we are doing 2 things, or actually 3 things: Building a custom Get-EvntLog function built upon the standard Get-WinEvent cmdlet Using DefaultDisplayProperties Using an embedded function in an function (why, because why not, we can?) Main reasons for doing this: Bug in .net and/or Get-WinEvent for any other culture than en-us (I use no-nb), The message property is returned as $null if I use Get-WinEvent Speed – Get-Eventlog is fine, however I want speed like we get with Get-WinEvent I can work around the bug in Get-WinEvent by temporarily switching to the culture en-us. When I have used Get-WinEvent and processed the results, I reset the culture to the original state. No harm done. A few words about the custom object function (Create-CustomObject). It takes 2 parameters; Properties ([string[]]) and DefaultDisplayProps([string[]]). At the end it spits out a new object (PSobject) with the DefaultDisplayPropertySet’ configured. To demonstrate: Okay, so

Hybrid cloud - Missing automation link Part 2

If you read my previous post ( part 1 ), I kind of concluded that you had 2 choices. Of course the answer is somewhere less binary and perhaps in between the two options. This post is another discussion about where we are headed in an non-technical way, I hope.   "Reflecting on my future" - A scenario " So you are sitting there enjoying your coffee and analyzing what has happened in your datacenter the last couple of years. You have "virtualized" the network and the load balancers (you do use Citrix Netscalers right). Your Netscalers are happily living their life as virtual appliances on your hypervisor along with the rest of the windows/linux servers. Your clients are being served by System Center Configuration Manager. The users can deploy their new laptops from SCCM and use the Software Catalog to install the software packages they need. Your servers and SNMP network devices are monitored by System Center Operations Manager and you have implemented Syst

Hybrid cloud – the missing automation link?

Fair warning: I am probably off on a rant here about the cloud and how “everything is connected” in terms of automation. This post is going to discuss the recent offensive from Microsoft and their vision about a Hybrid Cloud. I will not do a deep dive into any technical aspects, however do a more overall discussion about the vision and how recent changes brought to us by Windows Server 2012 R2 (and windows management framework 4) can affect us going forward. Background – What do we have and what has happened? From “nowhere” Azure as a PaaS was born. A while before that people started talking about “The Cloud” and things started to move about in terms of Public (The Cloud) and Private Cloud (“On-Premises or On-Prem as it is called nowadays) . Moving forward a bit Microsoft started to launch their vision about Hybrid Cloud, a nice mix of the “best” of the Public and Private cloud. This was even supported with the release of the System Center 2012 suite and together with Windows S

Powershell – The DSC book

Don Jones (@concentrateddon) is writing this awesome book about DSC. Please help him review the contents and make suggestions. You may leave feedback on the Powershell.org/FAQ web page (just create a new post there). I have been working as an consultant in IT since 1999, I have done a lot of strange “things” (work related that is). I have done my fair share of vb-scripting and small GUIs or console application development using vb.net etc. I have even created an automation solution/"framework" with powershell and .net (.net Forms). I have been using powershell since exchange 2007, however the last 2 years I have been a “heavy” user writing advanced scripts/functions, dot-sourcing, creating small modules etc. Full disclosure; I am not exaggerating when I say I am super excited about DSC. My comments (in random order, when I say you/your I target Mr Jones, I think :-)) DSC resources – As you mention Microsoft has released 2 waves of additional resources for DSC. Wh

Powershell – Another windows registry “module” with a little remote trick

Well it is time for another pure powershell post. This time I have been working with the registry. Feels like I have been living in different hives no matter what area I have been working in in the last 15 years. It has become rather pleasant if I could say so compared to the old VBSCRIPT days and before that reg.exe and ini files. Fist a little history and a discussion. You have a couple of options in regards to reading and/or editing settings in the registry Use the built-in PS-drives (gives you access to HKLM and HKCU) Codeplex module (search on codeplex or in your favorite searchengine – most used and referenced: http://psrr.codeplex.com/ ) Use the .Net class (normally [microsoft.win32.registrykey]). This gives you access to all the hives in the registry Powershell Desired State Configuration (There is a built-in resource to access the registry) WMI/CIM Which one you pick depends upon your current needs and what you want to accomplish. If you are also in a hu