RSS

Category Archives: Automation

#PowerShell – Anybox module to easily create GUIs by @dm3ll3n

#PowerShell – Anybox module to easily create GUIs by @dm3ll3n

In my previous post #PowerShell – Create a simple GUI form in seconds I wrote about a script I made to easily create a GUI.

After posting it, a colleague of mine said he had seen a great solution for creating GUIs on Reddit called Anybox.

Anybox is created by Donald Mellenbruch (@dm3ll3n) and is available from the PowerShell Gallery. Unfortunately however there is no proper built-in help yet. He does have a great post on his website though with example GUIs and the code needed to create them:
https://www.donaldmellenbruch.com/post/introducing-the-anybox/

Be sure to check out his website and thank him if you like it.

Advertisement
 

Tags: , , ,

#PowerShell – Create a simple GUI form in seconds

As a PowerShell person I’m personally not a big fan of creating a GUI for PowerShell scripts. This is however something that is asked a lot when PowerShell scripts are created for by example provisioning new users.

I’ve seen many different approaches to this. Most worked around it either by using Read-Host or creating a GUI inside their function. In some cases these approaches also meant that the function could not handle pipeline input, multiple inputs, etc. So basically they automated one thing, but prevented further automation by implementing the GUI in a stupid way.

Personally I prefer to keep my functions without a GUI. If it is desired or required, the GUI code will be written outside of the function and will result in the calling of the function with the values specified in the GUI. This way the GUI part will not pollute the function and users have more choice and flexibility to achieve their goal. You could compare it to how you normally handle output. You output objects and let users handle the formatting instead of providing them with by example the output in Format-Table.

Now the approach is clear, the GUI still needs to be created. There are multiple ways to go about this. You could by example create the GUI by looking up what exactly you need to code to get the desired result or you could use (paid) 3rd party tools / services. You could by example use the free web-based service POSHGUI to visually create your form and then have it output your needed code. There are however also (paid) editors like Visual Studio or PowerShell Studio. Another very simple method in some cases is using Out-Gridview with -PassThru. For more info, see also my previous blog post Summary of 2nd Dutch PowerShell User Group – DuPSUG meeting with additional resources

In my case I created my initial GUI form with POSHGUI. Even though you can do many more advanced GUI forms, I soon realized that I was always creating the same type of GUI form that consisted of a couple of text boxes and a submit button. Creating these manually become an annoyance very quickly. That’s why I decided to create a function to dynamically create such a GUI based on my input.

The result is this:

The code itself can be found on my GitHub: https://github.com/bjornhouben/PowerShell/blob/master/General/GUI/New-SimpleGUIForm.ps1

I hope you like it and find it useful.

 
5 Comments

Posted by on June 1, 2018 in Automation, ICT, Microsoft, Powershell

 

Tags: , , , , , ,

PowerShell – Getting started with Visual Studio Code and GitHub

In the past years I’ve been creating scripts and storing them on my personal OneDrive that is connected to multiple desktops and laptops I use. Additionally, my Synology NAS syncs with OneDrive and backups the files to ChrashPlan.

Even though this works, it has some disadvantages:

  1. OneDrive provides basic version history, but it is limited to just the file at a point in time. When modifying scripts I would need to create a new version and file to ensure I would be able to go back to a previously working version. In the past, especially when I just got started with PowerShell I screwed up code that was working before and that cost me a lot of time to get working again.
  2. The file is only available to me and the people I explicitly share it with. Therefore a lot of general use scripts I’ve created will not be findable and usable by others and I cannot benefit from suggestions/improvements from others which would also help me create better code.

These are the things I plan to solve by using GitHub with Visual Studio Code.

These are the steps I did to get started:

  1. First thing I did, was install Visual Studio Code 1.23.1 (even though I love PowerShell ISE especially with ISE Steroids and will probably still use in parallel). Then I configured it as a replacement for the PowerShell ISE as described by Mike F Robbins in his blog post “How to install Visual Studio Code and configure it as a replacement for the PowerShell ISE”.
  2. Then I created an account on GitHub and followed the Hello World guide to get better acquainted with GitHub and its concepts. At the bottom of this page additional training was offered as a tip: GuidesYouTube Channel and On-Demand Training , but I decided to check this out later.
  3. I then configured Git for Windows and Visual Studio Code by following the blog post Use Git with Visual Studio Code by Brandon Lee.

Everything worked correctly from home and I started following examples shown in “Git Version Control in VS Code”.

When I got at work it did not work anymore however and after some time I got an error in Visual Studio Code stating:
Git: fatal: unable to access ‘https://github.com/bjornhouben/PowerShell.git/’: Failed to connect to github.com port 443: Timed out

Since we use a proxy at work, I quickly figured this would be the most probable cause. So first I determined the proxy server by checking our WPAD file using http://wpad.domain.local/wpad.dat. Then I went on to determine how to configure Visual Studio Code to use the proxy server and came across the articles “Network Connections in Visual Studio Code” and “User and Workspace Settings” , but both did not solve my problem even after restarting Visual Studio Code. Then it hit me that Git For Windows was being used to connect to GitHub. I then quickly found out that I had to run GIT Cmd and configure the proxy using: git config –global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 and after restarting Visual Studio Code it worked correctly again. When I’m working from home without VPN I simply unset the proxy configuration using GIT Cmd using: git config –global –unset http.proxy and restart Visual Studio Code.

 
3 Comments

Posted by on May 28, 2018 in Automation, ICT, Microsoft, Powershell

 

Tags: , , , , , , , ,

PowerShell – WMF5 (including PowerShell) 5 can be deployed using WSUS again, but there is a catch …

A couple of weeks ago I was thinking that I should blog that it’s a pity that Windows Management Framework (including PowerShell) could be not distributed through WSUS anymore. In the past it was available on through WSUS, but it was removed (expired) at some point due to some issues.

This meant to deploy PowerShell you could not deploy it through regular WSUS, but you had to either:

  • Include it in your base image
  • Install it manually
  • Install it using scripting
  • Install it using GPO
  • Install it using WSUS add-on solutions to deploy 3rd party packages. Example solutions include, but are not limited to Local Update Publisher (LUP), WSUS package publisher, SolarWinds patch manager.
  • Install it using enterprise systems management software. Example solutions include, but are not limited to System Center Configuration Manager (SCCM), Altiris, Landesk Management Suite, Tivoli Endpoint Manager (BigFix)
  • Install it using Intune

At many customers of ours this meant that PowerShell was left at version 2.0 for older operating systems unfortunately. For newer operating systems luckily version 3.0 was shipped by default. Still the version would never be updated in most cases.

Apparently the PowerShell team also thought something had to be done about that, because they made the Windows Management Framework (WMF) 5.0 RTM available via the Microsoft Update Catalog. Since it is published to the Microsoft Update Catalog, you have to manually import it to your WSUS environment. Also as the blog post states, before installing ensure you have reviewed known product incompatibilities (Exchange, SharePoint and System Center Virtual Machine Manager) and that the prerequisites are met.

I hope this will mean I will be seeing more up-to-date versions of PowerShell on systems of customers from now on.

One of the disadvantages however is that for operating systems before Windows 8.1/2012, a prerequisite is that WMF4 is installed, which cannot easily be deployed using WSUS unfortunately.

 

 

 

 

 

 

 

 
 

Tags: , , , ,

PowerShell – Get-EnumValue function to get possible values of properties / attributes

PowerShell – Get-EnumValue function to get possible values of properties / attributes

In my previous blog post I blogged about how to get the possible values of an attribute or property like by example the service starttype using enumerators.

For future use I’ve created this function called Get-EnumValue. The function (and any updated future versions) can be found on ScriptCenter: https://gallery.technet.microsoft.com/scriptcenter/Determine-possible-values-eaf48782

But for those that don’t want to click and just want to see the current version, here it is:

Function Get-EnumValue

{

    <#

    .SYNOPSIS

        Determine possible values of a property / attribute of the [system.enum] type

        By example the possible values of startup type of a service.

    .DESCRIPTION

        Determine possible values of a property / attribute of the [system.enum] type

        By example the possible values of startup type of a service

 

        In some cases this can easily be determined if there is a “set-” version of the cmdlet.

        By example with Get-Service, there is also a Set-Service where the StartUpType values can be determined using “Get-Help Set-Service -Full” or by simply typing: Set-Service -StartupType and using auto completion.

 

        In some cases this is however not possible and this function can be used.

    .PARAMETER EnumProperty

        Input a property of the [System.enum] type. By example: (Get-Date)[0].DayOfWeek or (Get-Service)[0].StartType’)    

    .EXAMPLE

        $FormatEnumerationLimit=-1

        $Property1 = (Get-Date)[0].DayOfWeek

        $Property2 = (Get-Service)[0].StartType

        Get-EnumValue -EnumProperty $Property1,$Property2

            

        Description

    

        ———–

    

        Set $FormatEnumerationLimit to -1 to prevent cutoff of the results.

        Store 2 properties in variables and use the Get-EnumValue function with the named parameter -EnumProperty to enumerate their values.

    .EXAMPLE

        $FormatEnumerationLimit=-1

        Get-EnumValue -EnumProperty (Get-Date)[0].DayOfWeek,(Get-Service)[0].StartType

            

        Description

    

        ———–

    

        Set $FormatEnumerationLimit to -1 to prevent cutoff of the results.

        Use the Get-EnumValue function with the named parameter -EnumProperty to enumerate their values without first storing them in variables.

    .EXAMPLE

        $FormatEnumerationLimit=-1

        $Properties = @((Get-Date)[0].DayOfWeek,(Get-Service)[0].StartType)

        Get-EnumValue -EnumProperty $Properties

            

        Description

    

        ———–

    

        Set $FormatEnumerationLimit to -1 to prevent cutoff of the results.

        Store 2 properties in a single array and use the Get-EnumValue function with the named parameter -EnumProperty to enumerate the values of the properties in the array.

    .EXAMPLE

        $FormatEnumerationLimit=-1

        (Get-Date)[0].DayOfWeek,(Get-Service)[0].StartType | Get-EnumValue | Format-Table    

    

        Description

    

        ———–

    

        Set $FormatEnumerationLimit to -1 to prevent cutoff of the results.

        Put 2 properties in the pipeline and pipe them to Get-EnumValue to get their values.

    .NOTES

        1) By default, the EnumValues are truncated like this for format-list, format-table, etc:

 

        For Format-List:

 

        TypeName   : System.DayOfWeek

        EnumValues : {Sunday, Monday, Tuesday, Wednesday…}

 

        TypeName   : System.ServiceProcess.ServiceStartMode

        EnumValues : {Boot, System, Automatic, Manual…}

 

        For Format-Table:

 

        TypeName                               EnumValues                            

        ——–                               ———-                            

        System.DayOfWeek                       {Sunday, Monday, Tuesday, Wednesday…}

        System.ServiceProcess.ServiceStartMode {Boot, System, Automatic, Manual…}

 

        By setting $FormatEnumerationLimit to -1 all values will be shown (https://blogs.technet.microsoft.com/heyscriptingguy/2011/11/20/change-a-powershell-preference-variable-to-reveal-hidden-data/):

        $FormatEnumerationLimit=-1

 

        2) This example uses [Enum]::GetValues but it can easily be modified to use [Enum]::GetNames

 

        3) Additional information and resources:

        http://social.technet.microsoft.com/wiki/contents/articles/26436.how-to-create-and-use-enums-in-powershell.aspx#UsingEnumsWiithFunction

        https://msdn.microsoft.com/en-us/library/system.enum.getnames(v=vs.110).aspx

        https://msdn.microsoft.com/en-us/library/system.enum.getvalues(v=vs.110).aspx

#>

    [CmdletBinding()] #Provides advanced functionality. For more details see “What does PowerShell’s [CmdletBinding()] Do?” : http://www.windowsitpro.com/blog/powershell-with-a-purpose-blog-36/windows-powershell/powershells-%5Bcmdletbinding%5D-142114

    Param

    (

        [Parameter(Mandatory=$true, #Parameter is mandatory.

                   ValueFromPipeline=$True, #Allows pipeline input.

                   Position=0, #Allows function to be called without explicitly specifying parameters, but instead using positional parameters in the correct order

                   HelpMessage=‘Input an object of the [System.enum] type. By example: (Get-Date)[0].DayOfWeek or (Get-Service)[0].StartType’)] #Enter a help message to be shown when no parameter value is provided.

        [ValidateNotNullOrEmpty()] #Validate the input is not NULL or empty

        [ValidateScript({$_ -is [System.Enum]})] #Validate whether or not the input is actually of the [System.enum] type.

        [System.enum[]]$EnumProperty

    )

    BEGIN

    {

    }

    PROCESS

    {

        $Output = @()

        Foreach($object in $EnumProperty)

        {

            TRY

            {

                $TypeName = ($object | Get-Member)[0].TypeName

                $EnumValues = [Enum]::GetValues($TypeName) #Pre-PowerShell 3.0

                $ObjectEnumResult = New-Object PSCustomObject -Property @{

                ‘TypeName’ = $TypeName

                ‘EnumValues’ = $EnumValues

                }

                $Output += $ObjectEnumResult

            }

            CATCH

            {

                Write-Verbose “Error occurred processing $object

            }

            FINALLY

            {

            }

        }

 

        #Send output to the pipeline

        $Output

    }

    END

    {

    }

}

 

 
1 Comment

Posted by on March 11, 2016 in Automation, ICT, Microsoft, Powershell

 

Tags: , , , , , , , , , , , , , ,

Microsoft Ignite 2015 : huge collection of information enhanced with more detailed resources to get you up-to-date with less time and effort

As some of you might know already, the Microsoft Ignite 2015 conference has started where Microsoft talks about where they’re going and what they’re doing. I watched the keynote, took many notes and added other relevant information which I’m sharing with you. Since so much was told and shown it’s certain I’ve missed stuff. As time goes by I will update the information in this post so it can be used as a reference.

I hope it’s useful. If you find any errors or have other useful resources or feedback, please leave a comment.

Update log:

-05-05-2015: Created Initial version including the keynote and additional information.

 

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Free PowerShell Desired State Configuration (DSC) training on February 25th and 26th

Microsoft Virtual Academy (MVA) is hosting 2 PowerShell Desired State Configuration (DSC) training classes on February 25th and February 26th:

  1. Getting Started with PowerShell Desired State Configuration (DSC)
  2. Advanced PowerShell Desired State Configuration (DSC) and Custom Resources

The links above provide include a course outline and a link to register for the Jump Start. And even if you can’t join live, the recordings will always be made available at a later time so you can watch whenever it suits you better.

PowerShell DSC is becoming increasingly important and I personally also still need to learn more about it and look forward to it.

I hope it’s useful to you as well.

 

Tags: , , , , , , , , , , , , ,

PowerShell – Book review of : Windows PowerShell Best Practices

Windows PowerShell Best Practices

Last week I completed PowerShell Deep Dives which got me excited again to read more about PowerShell. As such, I continued reading the next book on my reading list: Windows PowerShell Best Practices by Microsoft Scripting Guy Ed Wilson.

The book was released late January 2014 and is the most recent book about PowerShell that has been released to my knowledge. This means it includes PowerShell 4.0, Desired State Configuration DSC and references to Windows 8.1 and Windows Server 2012 R2.

In my opinion the book was very well written and contains a good mix of theory, sample scripts and “notes from the field” from many PowerShell specialists. The sample scripts are available for download at Technet Script Center.

The best practices that are described in the book are very recognizable and I had already adopted many of them based on the many great blog posts by the community. In the book they are all bundled and well explained including examples. Where the book really shines though in my opinion is that it describes how PowerShell is used in real-life, how it relates to many other processes within a company and what you need to consider.

I think this book is a must-have for anyone working with PowerShell. For those starting with PowerShell, I recommend first reading the books “Learn Windows PowerShell In A Month Of Lunches” and “Learn PowerShell Toolmaking In A Month Of Lunches” and then read this book.

Notes:

 
 

Tags: , , , , ,

PowerShell – Book review of : PowerShell Deep Dives

PowerShell_Deep_Dives

I’ve had the book PowerShell Deep Dives laying around since August 2013. I had read some parts of it because I follow many of the great PowerShell community members that contributed to it. But I hadn’t gotten to reading it completely yet until now.

The title of the book includes “deep dives” implies very deep technical content and I can assure you, this type of content is present in the book. some of the stuff I still need to wrap my head around to understand properly. On the other hand, other parts of the book are more simplistic which you might not expect from a deep dives book.

The book covers a very broad number of topics and technologies. What I liked is that the articles were written by professionals and community members that are specialized in or are very knowledgeable about this specific topic/technology.

As a result of having the broad number of topics and technologies, not all parts of the book might be relevant to you (especially as a deep dive). I found myself skimming over some parts later in the book since it is very unlikely it is or will become useful for me. This will differ from person to person though, so take a good look at the topics being covered in the table at the end of the article.

All in all it was a good read and I think I’ll use the book mainly as a reference for those times that I need the deep dive insights. The book can be ordered from by example Manning.com and all royalties go to charity: Save the Children

 

Part 1 PowerShell administration
1 Diagnosing and troubleshooting PowerShell remoting (Don Jones)
2 CIM sessions (Richard Siddaway)
3 Collecting and analyzing performance counter data (Arnaud Petitjean)
4 TCP port communications with PowerShell (Boe Prox)
5 Managing systems through a keyhole (Bartosz Bielawski)
6 Using PowerShell to audit user logon events (Mike F. Robbins)
7 Managing and administering a certification authority database with PowerShell (Cadims Podans)
8 Using PowerShell to reduce Active Directory token bloat (Ashley McGlone)
Part 2 PowerShell scripting
9 The 10 PowerShell scripting commandments (James O’Neill)
10 Avoiding the pipeline (Jeff Wouters)
11 A template for handling and reporting errors (Will Steele)
12 Tips and tricks for creating complex or advanced HTML reports with PowerShell (Jonathan Medd)
13 Using and “abusing” dynamic parameters (Bartosz Bielawski)
14 PowerShell type formatting (Adam Driscoll)
15 Scalable scripting for large data sets: pipeline and database techniques (Matthew Reynolds)
16 Building your own WMI-based cmdlets (Richard Siddaway)
17 Turning command-line tools into PowerShell tools (Jefferey Hicks)
Part 3 PowerShell for developers
18 Using Source Control Software with PowerShell (Trevor Sullivan)
19 Inline .NET code (Richard Siddaway)
20 PowerShell and XML: better together (Josh Gavant)
21 Adding automatic remoting to advanced functions and cmdlets (Karl Prosser)
22 Taming software builds (and other complicated processes) with psake (Jim Cristopher)
Part 4 PowerShell platforms
23 PowerShell and the SQL Server provider (Ben Miller)
24 Creating flexible subscriptions in SSRS (Donabel Santos)
25 Inventory database table statistics using PowerShell and SQL Server Management Objects (Robert C. Cain)
26 WSUS and PowerShell (Boe Prox)
27 Provisioning IIS web servers and sites with PowerShell (Jason Helmick)
28 Active Directory Group Management application (Chris Bellee)

 

 
1 Comment

Posted by on June 7, 2014 in Automation, ICT, Microsoft, Powershell, Windows

 

Tags: , , , ,

Introduction to PowerShell – Also relevant for NON Microsoft administrators

Today I had the privilege that many colleagues of mine from Open Line decided to sacrifice their free time and attend my session: “Introduction to PowerShell – Also relevant for NON Microsoft administrators”

The goal of this session was to:

  • Inform people of the advantages of scripting/automation in general.
  • Inform people of the advantages of PowerShell over CLIs and other scripting languages.
  • Inform people that PowerShell is not just for Microsoft administrators.
  • Teach people about the PowerShell basics.
  • Inform people about the many possibilities with PowerShell.
  • Provide people with a lot of practical resources to increase their knowledge and skill.

I really enjoyed the session and got a lot of interactivity and positive feedback. Next up is a follow-up session which will be more of a workshop style.

I’ve uploaded the presentation in PowerPoint and PDF format here:
https://bjornhouben-web.sharepoint.com/Lists/Files/DispForm.aspx?ID=22

Please share this so that others can benefit from it as well.

Notes:

  • I’ve included many useful resources as notes in the PowerPoint presentation, which makes the presentation also interesting to people who are not PowerShell beginners.
  • Also if anyone has suggestions to make the presentation better, please let me know.
 
 

Tags: , ,

 
%d bloggers like this: