RSS

Tag Archives: Microsoft

#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.

Advertisement
 
5 Comments

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

 

Tags: , , , , , ,

Last week to buy Microsoft Certification Booster Pack promotion for your exam

Microsoft Certification Booster Packs are sold for $200-$225 depending on the package and your country. This basically means that:
For $200 you can choose between “1 Exam + 30 days access to online practice test” or “1 exam and up to 4 free retakes of that same exam”
For $225 you get “1 exam and up to 4 free retakes of that same exam AND 30 days access to online practice test”.

It seemed like the Microsoft Certification Booster Packs promotion would end 31-08-2016, but they extended it to 30-09-2016, making this week the last week you’ll be able to purchase it.
After purchase, you’ll have 6 months to use your booster pack(s).

For more information, see my previous blogpost https://blog.bjornhouben.com/2016/04/19/certification-my-thoughts-on-microsoft-certification-booster-packs/ or the Microsoft website https://www.microsoft.com/en-us/learning/offers.aspx

 
Leave a comment

Posted by on September 26, 2016 in Learning, Microsoft

 

Tags: , , ,

Certification – My thoughts on Microsoft Certification Booster packs

Since March 7th, Microsoft is selling booster packs which can be bought until August 31. The exams can be taken up until six months after your purchase.

The following boosters packs are available:

  1. Practice Test + exam for $200
  2. Exam + 4 free retakes for $200
  3. Practice Test + exam + 4 free retakes for $225

As always there are pros and cons to this offering. These are things that have gone through my mind about these booster packs:

  • First of all, the retakes are not free because a regular exam costs $150 if you book it at Pearson Vue. Even though it is not free, it’s still a very good deal. If you would fail only once, you have saved money.
  • I would never choose option 1, I would always go for either option 2 or 3.
  • It can be good that people can get an exam with cheap retakes.
    • It might prevent (some) people from using exam dumps, because additional certification costs for a failure are not an issue anymore. This is especially true for people who have to pay for their own certification or for small companies with limited budgets.
    • It might help people that have the knowledge, but fail because their not used  to the way it is tested with Microsoft Certification Exams.
  • It might lower the value of certification
    • With that many cheap retakes the chance that you’ll pass (by chance) increases.
      • Especially since the number of exam questions is very limited, after a few retakes you could know most of the questions.
        • Which makes it easier for people to create exam dumps.
      • Without booster packs, the certification costs could become an issue.
        • This only affects people/companies where certification is an issue.
        • This could lead to people using exam dumps.

As with most things, when used for good it is a good thing. It will however be abused by some. Still this has always been the case and I feel it does not really matter. What I do believe however is that this large number of almost free retakes stresses again the need for a larger pool of Microsoft exam questions. But this has been a problem for a long time already and I doubt Microsoft will change this anytime soon unfortunately.

I wonder what other people think about this, so please leave a comment.

For more information on the booster packs see:
https://borntolearn.mslearn.net/b/weblog/archive/2016/03/07/introducing-new-microsoft-certification-booster-pack-offer

 

Tags: , , , , , ,

PowerShell – easily posting scripts to a website while maintaining syntax highlighting by copying as HTML

PowerShell – easily posting scripts to a website while maintaining syntax highlighting by copying as HTML

 

 

 

When sharing PowerShell scripts on the Internet there are a couple of options:

  1. Simply post it as plain text, which means syntax highlighting will not be included.
  2. Use available syntax highlighting for the platform you use. Sample platforms include:
    Microsoft ScriptCenter and a syntax highlighting example from a script of mine: https://gallery.technet.microsoft.com/scriptcenter/Determine-possible-values-eaf48782
    Wordpress : https://en.support.wordpress.com/code/posting-source-code/
  3. Copy code to HTML including syntax highlighting.

Option 2 and 3 are preferred, especially sharing to Microsoft ScriptCenter because others can then more easily find and use your scripts and maybe even improve them or give you tips on how to make better script.

Option 2 however requires that you have to accept whatever the platform provider has chosen with regards to syntax highlighting, which might differ between platforms. With option 3 you have more freedom with regards to the output and you are in control. Basically it means copying code to HTML including syntax highlighting. The solution I use mostly for this is the Windows PowerShell V3 ISE: Copy As HTML Add-On which adds a simple “Copy As HTML” option in the menu and which can also be used using the shortcut CTRL+SHIFT+C.

I don’t have experience with it, but you could take a look at the script that Lee Holmes from the PowerShell team provided: http://www.leeholmes.com/blog/2009/02/03/more-powershell-syntax-highlighting/
In the comments someone apparently also implemented it as a PowerGUI add-on.

For more PowerShell ISE Add-ons be sure to visit: http://social.technet.microsoft.com/wiki/contents/articles/2969.windows-powershell-ise-add-on-tools.aspx

 
Leave a comment

Posted by on March 14, 2016 in ICT, Microsoft, Powershell

 

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: , , , , , , , , , , , , , ,

PowerShell – Determine possible values for an attribute

While working on a script for XenApp 6.5 I wanted to perform actions based on the session state. To me however, the possible state values were not clear.

Without knowing these states, I would have to make assumptions which could lead to unexpected behavior and results.

Generic example

Since not everyone is using Citrix, here’s a more generic sample using Get-EventLog to determine the possible values for attribute EntryType

1. Get-EventLog -LogName System | Select EntryType -First 1 | Get-Member

This resulted in:

   TypeName: Selected.System.Diagnostics.EventLogEntry

Name        MemberType   Definition
—-        ———-   ———-
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
EntryType   NoteProperty System.Diagnostics.EventLogEntryType EntryType=Information

2.  Enumerate the values using:
[Enum]::GetValues(‘System.Diagnostics.EventLogEntryType‘)

This results in the following possible values:

Error
Warning
Information
SuccessAudit
FailureAudit

XenApp 6.5 example

To determine the possible states, I did the following:

1. Get-XASession | Select State | Get-Member

This resulted in:

TypeName: Selected.Citrix.XenApp.Commands.XASession

        Name        MemberType   Definition
—-        ———-   ———-
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
State       NoteProperty Citrix.XenApp.Commands.SessionConnectionState State=Disconnected

2.  Enumerate the values using:
[Enum]::GetValues(‘Citrix.XenApp.Commands.SessionConnectionState‘)

This results in the following possible values:

Unknown
Active
Connected
Connecting
Shadowing
Disconnected
Idle
Listening
Resetting
Down
Initializing
Stale
Licensed
Unlicensed
Reconnected

Alternative method for PowerShell 3.0 / .NET Framework 4.0 and later

After writing this blog post I came across this post http://www.powershellmagazine.com/2013/03/15/pstip-getting-enum-values-in-powershell-3-0/ explaining an alternative method that is available for PowerShell 3.0 / .NET Framework 4.0 and later :

[System.Diagnostics.EventLogEntryType ].GetEnumValues()

[System.Diagnostics.EventLogEntryType].GetEnumNames()

 

 

 
2 Comments

Posted by on March 9, 2016 in Citrix, Microsoft, Powershell, XenApp

 

Tags: , , , , ,

Get Windows 8 MCSA certified between February 15th and May 31st and get a free Windows 10 exam

Microsoft has started a new campaign offering people that get Windows 8 MCSA certified between February 15th and May 31st  to get a free Windows 10 exam (697) when it is released. For more information about the offer see: https://borntolearn.mslearn.net/b/weblog/archive/2015/02/19/how-to-get-a-windows-10-exam-for-free

Based on the comments on the born to learn website it seems that this offer does not extend to people that are Windows 8 MCSA certified before February 15th … but I might be wrong. An alternative is to try to get access to free Microsoft Beta Exams by signing up as a Subject Matter Expert (SME) as described here: https://blog.bjornhouben.com/2012/09/17/how-to-get-access-to-free-microsoft-beta-exams/

 
Leave a comment

Posted by on February 24, 2015 in ICT, Learning, Microsoft, Windows

 

Tags: , , , , , ,

Dropbox users get another 100GB of extra Microsoft OneDrive storage for free for 1 year

For those looking to get 100GB of extra Microsoft OneDrive (prevously named Skydrive) storage for 1 year, click the following link:
https://preview.onedrive.com/bonus

For those who missed it, you can also get an additional 100GB for 2 years. To see how, read my previous blog post.

 

 
Leave a comment

Posted by on February 22, 2015 in Cloud, ICT, Microsoft, Public Cloud

 

Tags: , , , , ,

Get 100GB of extra Microsoft OneDrive storage for 2 years

For those looking to get 100GB of extra Microsoft OneDrive (prevously named Skydrive) storage for 2 years, click the following link:

https://login.live.com/oauth20_authorize.srf?client_id=000000004C12B387&scope=wl.signin%20wl.basic%20wl.emails%20wl.skydrive%20wl.onedrive_provision_quota&response_type=code&redirect_uri=https://preview.onedrive.com/callback.aspx

Previously I though this was only working for the United States (or from somewhere else using a proxy), but this worked fine for me from within the Netherlands.

Enjoy your extra cloud storage.

 

 
1 Comment

Posted by on February 13, 2015 in Cloud, ICT, Microsoft, Public Cloud

 

Tags: , , , ,

Microsoft – Passed the free exam 74-409 Server Virtualization with Windows Server Hyper-V and System Center

As I mentioned earlier, Microsoft is offering free exam vouchers for the new exam “74-409 Server Virtualization with Windows Server Hyper-V and System Center”. For more information, take a look here.

I took the exam today and passed after having studied very hard for over a week (including pulling an all nighter today). I’m happy to have my first certification for the year 2014 already though 🙂

In my opinion the exam contained too many repeating (easy) questions on specific subjects, but there were also some very difficult questions about really specific situations. I personally would’ve preferred more “medium difficulty” questions.

All in all I learned a lot from preparing for the exam and I’m very happy with all the new things Microsoft has added to their new products.

If you are looking to take the exam as well, take a look at my previous post that contains the resources I used for preparation.

Good luck and enjoy. I’ll be going for some well earned sleep now 🙂

 

Tags: , , , , , , , , ,

 
%d bloggers like this: