PS – CleanUp HDD

Hello together,

today i want to show you a simple but effective method to cleanup your HDD. This will also remove the installation data of previous installations and may prompt therefore for authorization. Run it with admin rights.

CleanUp.png

More information here

Set-Location 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\'

foreach ($item in $(Get-ChildItem).PSPath)
{
    if (-not (Get-ItemProperty -Path $item -Name 'StateFlags1234'))
    {
        New-ItemProperty -Path $item -Name 'StateFlags1234' -Value 2
    }
}

cleanmgr.exe /sagerun:1234 

Greetings,

David

Advertisement

How to become a Powershell Pro?

PowershellPro

Hello together,

today i want to share my experiences of the last months with you where i worked nearly every day hours over hours on my Powershell skills. I have read a lot of books, watched douzens webinars, written many blog and forum posts and also thousands of lines powershell code. But not every material or action was reasonable at some learning point.

So i worked out – somewhat like – a learning plan. I will list up the best material  you should work on at a specific learning point. (as for my own personal opinion)
But keep in mind – this could vary for you. Persons are different as also their learning types. Some persons need to hear and see the things to capture the input better. Others learn best by reading and some need to interact as by writing.
But one thing is for sure – you will need a lot of practice and you will need to write scripts by yourself!

Continue reading

PS – RegEx and parsing log files – the nice way

Hello together,

today i want to show you a nice grab of the usage of Regular Expressions. Many people do not like Regex. Je – at the beginning these statements look like hieroglyphs but it will get better with the time.

First i will start with some trivial explanations how RegEx can be used in Powershell and will dive then deeper into more complex structures and lastly parsing log files giving us a nicely looking hash table with really nice features.

Continue reading

Client – Repairing Win 10 Apps with PS

Hello together,

today i want to share with you just two Powershell commands to reinstall Cortana or the Windows App Store if you are facing some problems with these:

Cortana:

Get-AppXPackage -Name Microsoft.Windows.Cortana | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register “$($_.InstallLocation)\AppXManifest.xml”}

Windows App Store:

Get-AppXPackage *WindowsStore* -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}

Greetings,

David

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