Contents tagged with PowerShell

  • Create group of users in PowerShell

    Hello everybody,

    today I want to share just simple script, with which you can create group of users according to some rules:

    $pw = "strangePassword" | ConvertTo-SecureString -AsPlainText -Force


    $i -le 320


           $userName = "repeatingUserName" + $i

       New-ADUser -Name $userName -GivenName $userName -AccountPassword $pw -ChangePasswordAtLogon $false -PasswordNeverExpires $true -Enabled $true

               #Remove-ADUser -Identity $userName -Confirm:$false



  • PowerShell formatting strings

    Hello everybody,

    today I want to write few words about formatting strings in PowerShell.

    Consider the following example:

    "Today is $(Get-Date). Enjoy your life"

    Output will be the following:

    Today is 08/23/2016 16:04:18. Enjoy your life

    So, if you want to call some PowerShell function, you can just put it into brackets, put $ in front of it and get the result.

    Conisder another example:

    "You own to me $(44 + 44* 0.15) dollars"

    It will give following output:

    You own to me 50.6 dollars

    Very cool stuf in PowerShell is about using formatting with templating and key -f.

    Take a look:

    $apples = 5

    $pomegranade = 22


    "I have {0} apples and {1} … more

  • How to make pause in powershell script execution

    Hello everybody,

    today I want to make short note about how to make pause untill user press a key in PowerShell execution.

    Here it is:

      Write-Host "Press any key to continue ..."

     $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

    Presented code will make a pause. more

  • PowerShell built in variables

    Hello everybody,

    today I want to write few words about PowerShell variables.

    So, let's start from the simplest or with statement what is true and what is false. 

    In PS it's really not philosophical question



    The first one stands for false, and the second one for true. It is intended for logical operations in PS.

    Very usefull is Users Home directory:


    Current directory:


    Information about users environment:


    If you ever need to discover which version of power shell, that you execute, you can use 


    Let's say that you write some kind of loop, and wonder where current item goes in, you have relieve, for this purpose you can use 

    $_ … more

  • PowerShell comparison

    Hello everybody,

    today I want to share another trick from PowerShell activities. 

    So, imagine, that you see following PowerShell code:

    "048" -eq 48

    48 -eq "048"

    What do you expect to see? True, True or True, False ....

    Here is the output:

    PS C:\sources> "048" -eq 48

    48 -eq "048"



    PowerShell has interesting behaviour in this case. It takes value on the right, and converts it to the value on the left. 

    For the first case PS will make following comparison:

    convert 48 to string, which will be "48". Compares "48" with "048" and produce False.