PS OpenFileDialog

Hello together,

here a simple smart function to show an open file dialog:

function Show-OpenFileDialog
{
    <#
            .SYNOPSIS
            Shows up an open file dialog.
            .EXAMPLE
            Show-OpenFileDialog
    #>
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$false, Position=0)]
        [System.String]
        $Title = 'Windows PowerShell',
        
        [Parameter(Mandatory=$false, Position=1)]
        [Object]
        $InitialDirectory = "$Home\Documents",
        
        [Parameter(Mandatory=$false, Position=2)]
        [System.String]
        $Filter = 'PowerShell-files|*.ps1|Everything|*.*'
    )
    
    Add-Type -AssemblyName PresentationFramework
    
    $dialog = New-Object -TypeName Microsoft.Win32.OpenFileDialog
    $dialog.Title = $Title
    $dialog.InitialDirectory = $InitialDirectory
    $dialog.Filter = $Filter
    if ($dialog.ShowDialog())
    {
        $dialog.FileName
    }
    else
    {
        Throw 'Nothing selected.'    
    }
}

Show-OpenFileDialog

Have fun with it!

Greetings,

David

PS – DynamicParam

Hello together,

in this post i want to show you a very rare function attribute. It is called dynamicparam and as the name says it adds some features to create parameters dynamically when the user writes the execution function:



function Test-DynamicParam 
{
    [CmdletBinding()]
    param( 
        [Parameter(ValueFromPipeline=$true)]
        $Count 
    )
    
    
    dynamicparam
    {
        $paramDictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary
        foreach ($Property in (1..$Count))
        {
            $attributes = New-Object System.Management.Automation.ParameterAttribute
            $attributes.ParameterSetName = '__AllParameterSets'
            $attributes.Mandatory = $false
            $attributeCollection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]
            $attributeCollection.Add($attributes)
            $Name = &quot;DynamicParam_$Property&quot;
            $dynParam = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($Name,
            [int32], $attributeCollection)
            $paramDictionary.Add($Name, $dynParam)
        }
            
        $paramDictionary
    }
    
    
    begin
    {}
    
    process
    {    &quot;Entered: $Count&quot;
    }
    
    end
    {}
}

Test-DynamicParam -Count 5 

In this example the user enters the function name and the parameter $count. As you can see in the dynamicparam block now additional parameters are created. If you enter for example the number 5 – 5 additional parameters show up and can be given to the function.

DynamicParam.png

So you can add or remove parameters depending on the parameters which the user entered which can be very powerful if you write very complex functions.

Give it a look

Greetings,

David

PowerTheShell – ISESteroids! PSConfEU!

Hello together,

i have arrived today from a very good Powershell Training with Dr. Tobias Weltner, MVP. I have learned plenty new stuff and will blog lots of the new knowledge in the upcoming weeks.

1

The first thing i have to tell you – get a damn ISESteroids license! I did try it previously and liked it very much but had some scepsis to invest the money. After investigating 3 days the functions which all come along with the Steroids i have to say – its just amazing and a must have. Here are just some of them:

  • WPF Dialog creator
  • Variable Monitor
  • Snippet Manager
  • Creating executable files (.exe)
  • Creating functions and modules withing a click
  • Build-in signing and – much – more

Try it by yourself and get a trial. Just take a look at http://www.powertheshell.com/ 

If you want to create good Powershell scripts this tool is just a must have at the moment.


 

Also a very important information for all powershell fanatics – take a look at the upcoming event Powershell Conference EU 2016 http://www.psconf.eu/

There will be some interesting speakers! Trust me!

Greetings,

David

SolutionCenter v1.02 german

Hello together,

this time i want to present you my own creation – the SolutionCenter, (first in my native language – german) If the resonance is good i could easily translate it to english.

It is a tool which can be perfectly used in small to larger teams like support desks and so on. It shows buttons which can be sorted in different tabs to easily open programs, web links with defined browsers, files like ppt, pdf, txt etc. and also locations in the explorer like public shares. It can also work with the windows cache to integrate the cache in the execution.

For an user this could possibly look like this – and the color scheme can also be modified:

SCUserExperience

Continue reading

Client – WMI-Repair

Hello together,

most of you which worked in a servicedesk or with many computers will know WMI-errors. Sometimes the WMI of a computer gets corrupted and depending products like the SCCM-agent stops working properly. Herefore try to use the following script which repairs and rebuilds the WMI of the computer. But see this procedure as last line of defense – if you do not have any other options, try this one and restart twice.
Herefore just copy the whole script into a batch file and execute it as administrator.

winmgmt /resyncperf
winmgmt /salvagerepository
winmgmt /resetrepository
sc config winmgmt start= disabled
net stop winmgmt /y
net stop ccmexec /y
%systemdrive%
cd %windir%\system32\wbem
For /f %%s in ('dir /b *.dll') do regsvr32 /s %%s
::regsvr32 wmisvc.dll
net start winmgmt
net start ccmexec
for /f %%s in ('dir /b *.mof *.mfl') do mofcomp %%s

Good look on reparing the clients.

~ David