posted 18/08/10

PowerShell Twitter

By Fredrik Wall

I will start to twitter PowerShell stuff from a new twitter account today, @SteriaPosh. This will seperate my personal twitters from my Powershell Twitters.

No Comments
read more
posted 14/08/10

Create graphical programs with PowerShell

By Fredrik Wall

I wrote an article for Microsoft TechNet Sweden about making

Grapical Programs with PowerShell some time ago.

Now I have made a translation to English and It is available here.

 

Technorati Tags: ,,
7 Comments
read more
posted 25/07/10

Automated boot image management in MDT 2010 and WDS using PowerShell

By Fredrik "DXter" Jonsson

One of my favorite features in MDT 2010 is that everything you do in the GUI is executing a PowerShell command that is using the cmd-let’s that comes with the MDT 2010 PowerShell snapin. Smile

 

This gives excellent opportunities for scripting geeks such as Dalle and myself since we can automate and do exactly everything what the GUI does, since the GUI itself is using PowerShell behind the scenes. Winking smile

 

This weekend I upgraded my private MDT environment to MDT 2010 Update 1 which was a very smooth operation. I have a very simple MDT environment at home with a single WDS/MDT server. Since I wanted to have the new and cool background picture in Windows PE that comes with Update 1, I had to update the boot images and import them to the WDS server, which in my case was on the same machine.

 

Therefore I created this little PowerShell script that does that for me automatically. The script is using the PowerShell cmd-let Update-MDTDeploymentShare and PS-Drive provider that comes with MDT 2010 snaping. It is also using wdsutil which is a command line based tool for managing WDS.

 

The script does the following tasks:

1. Generates completely new and updated boot images for your deployment share.

2. Removes you previous LiteTouch boot images from your WDS server.

3. Imports the newly created LiteTouch boot images into your WDS server.

4. Set each boot image as default boot image for respective architecture.

 

 

image

I must say, it works really nice. Smile

 

 

image

“Do more with less…” – the PowerShell way. Winking smile

 

The script is defaulting to MDT default names, descriptions and file locations. If you have changed any of this, please update the script according to your environment. Some people may ask why I choose to use Remove-Image and Add-Image and not Replace-Image. Well, the answer is quite simple. If I have deleted the boot image in WDS, the script would not be able to execute since there is no image to replace. If we split it up in to two commands, we will always be able to recreate our boot image in WDS regardless if the boot image is present or not, since only the Remove-Image command will fail and not the Add-Image.

 

So right now I have scheduled this script to run on my WDS/MDT server each midnight. If I add any new storage or NIC drivers into MDT, they will be injected automatically into the boot images during the next scheduled generation of boot images during the night and I “never” have to open the WDS console manually again! Open-mouthed smile

 

Here is the script (don’t forget to modify it according to your installation):

 

Add-PSSnapIn Microsoft.BDD.PSSnapIn

New-PSDrive -Name "DS001" -PSProvider MDTProvider -Root "C:\DeploymentShare"

Update-MDTDeploymentShare -path "DS001:" -Force –Verbose

wdsutil /Remove-Image /Image:"Lite Touch Windows PE (x86)" /ImageType:Boot /Architecture:x86

wdsutil /Remove-Image /Image:"Lite Touch Windows PE (x64)" /ImageType:Boot /Architecture:x64

wdsutil /Verbose /Progress /Add-Image /ImageFile:C:\DeploymentShare\Boot\LiteTouchPE_x86.wim /ImageType:Boot

wdsutil /Verbose /Progress /Add-Image /ImageFile:C:\DeploymentShare\Boot\LiteTouchPE_x64.wim /ImageType:Boot

wdsutil /Verbose /Set-Server /BootImage:Boot\x86\images\LiteTouchPE_x86.wim /Architecture:x86

wdsutil /Verbose /Set-Server /BootImage:Boot\x64\images\LiteTouchPE_x64.wim /Architecture:x64

 

I must say, thank god for PowerShell! Red heart

 

// Fredrik “DXter” Jonsson

No Comments
read more
posted 10/07/10

PKI cleanup in AD with PS

By Fredrik "DXter" Jonsson

Yesterday I created this little script and I wanted to share it with you guys.

Now that PKI View is removed from KB889250, some people has asked me how to remove all references to old PKI structures in Active Directory in a easier way than just LDAP. Even though AD cleanup is a standard procedure regarding CA decommission, many people are not aware of that and some people seems to just remove the ADCS role and think “that’s it!”. Sad smile

 

So yesterday I created a little script to do this AD cleanup automatically. It is using the Active Directory PS-Drive and the Remove-ADObject cmd-let that is provided by the Active Directory PowerShell Module that comes with Windows Server 2008 R2. Since the Active Directory PowerShell Module is using the Active Directory Management Gateway Service, make sure that at least one of your DC’s have it installed or is running on Windows Server 2008 R2. The idea of the script is to use it after a decommission of a single Enterprise Root or if you want to make sure that no old PKI stuff exists in Active Directory before you install a new PKI structure.  This script removes ALL existing references to internal PKI’s and CA’s, so use it very carefully! I think that people should use it only after you have decommissioned your last CA or before you install your first.

 

 
1

The first screen is presenting what the script will do.

 

 

2

A final warning before continuing to delete stuff. Winking smile 
 

 

3

The script is prompting for credentials using the Get-Credential cmd-let.

 

 

4

The script is searching the Public Key Services container in the Configuration partition (for the current domain) for specific PKI related objects that has object classes such as “certificationAuthority”, “pKIEnrollmentService”, “msPKI-PrivateKeyRecoveryAgent”, etc…

 

 

5 
All objects that are found are presented and the person that is executing the script has a option to remove the objects that are being presented. The Remove-ADObject cmd-let is doing the deletion of the objects with the credentials that was provided earlier to the credential prompt in the beginning of the script. Smile

 

 

6

A simple way to verify that everything is deleted correctly is simply to run the script again. If all PKI related objects are gone, the script will say so. Smile

     
If you think this sounds cool and want to test this in your test environment, the script is available from the download section on http://poweradmin.se/blog/download/?did=4
 

// Fredrik “DXter” Jonsson

4 Comments
read more
posted 08/06/10

Skapa grafisk program med hjälp av PowerShell

By Fredrik Wall

Hej,

det var ett tag sedan jag skrev något här.

Dock har jag inte varit helt oproduktiv när det gäller skript och
PowerShell.

image

Min senaste artikel om PowerShell och att skapa grafiska program
med hjälp av PowerShell ligger nu ute på Microsoft TechNet Sverige.

Kommentera gärna vad du tycker om artikeln!

No Comments
read more
posted 21/04/10

Get-Scripting Podcast with Ed Wilson

By Fredrik Wall

In the latest episode Jonathan and Alan talks to
Ed Wilson (The Scripting Guy).

You can listen to it here.

It’s a 1.30 min podcast with lots of nice information.

1 Comment
read more
posted 07/04/10

1 year of blogging

By Fredrik Wall

#PowerShell and #PKI #Blogging

This blog have been active for one year now.
The stats goes back to 27/03/2009.

New-Year-Party-icon

Over 22 000 unique visitors in one year!

That’s great, thank you all readers and thank you
DXter, my fellow blogger for your great posts!

It seams like PowerShell and PKI is what people likes :)

 

Technorati Tags: ,,
No Comments
read more
posted 07/04/10

Clean-Temp

By Fredrik Wall

In my last post I showed you how to create 2000
files in the temp folder.

If you want to delete them fast you can use my
function Clean-Temp. I have been writing about it before.

And now It’s updated again.

The code can be found here.

I have added support for shutting down
Chrome and TweetDeck too.

 

Technorati Tags: ,
3 Comments
read more
posted 06/04/10

How to create 1 to 2000 or more temp files

By Fredrik Wall

This is a small how-to create 1 to how many
files you want automatically.

In PowerShell you can use 1..20 with foreach to
do stuff more then one time.

1..200 | foreach {
    Write-Host "test"
}

This will just write test 200 times.

To do some nice stuff with this we can use $_
$_ is a special pipeline variable. You can read more
about it here.

First of all we just add $_ instead of Write-Host test“.

1..200 | foreach {
    $_
}

Now we get 1 to 200:

1
2
3
4
5
6
7
8
9
10
..

190
191
192
193
194
195
196
197
198
199
200

The small code just count from 1 to 200.
If we add the code below we will get 01-09 instead of 1 to 9.
Zeros first for 1 to 9 are nicer.
1..200 | foreach {
    if ($_ -lt 10) {
        "0" + $_
    }
    else {
        $_
    }
}
It just look if the $_ is –lt (less then) 10.
And If we want to have zeros before 10 to 99 or before 100-999
(we want to create 2000 files in the end) we just add this:
1..2000 | foreach {
    if ($_ -lt 10) {
        $zeros = "000"
    }
    elseif ($_ -lt 100) {
        $zeros = "00"
    }
    elseif ($_ -lt 1000) {
        $zeros = "0"
    }
    else {
        $zeros = ""
    }
    $zeros + $_
}

I did some changes to make it better for the final code.

Now I’m using a variable ($zeros). It will be better later on
so we don’t need to write everything on each if, elseif or else.

It’s time for the final stage now.
To create files in the temp folder.

We can use $env:TEMP to find the temp folder.
And then add a new variable for the whole number thing,$numbers = $zeros + $_
So if we add this together we have something like this for thefilename and path.
$env:TEMP + "\tempfile" + $numbers + ".txt"
And the output will be like:

C:\Users\fredrik\AppData\Local\Temp\tempfile0233.txt
C:\Users\fredrik\AppData\Local\Temp\tempfile0234.txt
C:\Users\fredrik\AppData\Local\Temp\tempfile0235.txt
C:\Users\fredrik\AppData\Local\Temp\tempfile0236.txt
C:\Users\fredrik\AppData\Local\Temp\tempfile0237.txt
C:\Users\fredrik\AppData\Local\Temp\tempfile0238.txt
C:\Users\fredrik\AppData\Local\Temp\tempfile0239.txt

if we take the last code and add it to the variable $file anduse new-item we get this
    $file = $env:TEMP + "\tempfile" + $numbers + ".txt"

    New-Item $file -ItemType file  -ErrorAction SilentlyContinue

And if we add it to the rest we get a fully working code for
creating 2000 temp files.

1..2000 | foreach {
    if ($_ -lt 10) {
        $zeros = "000"
    }
    elseif ($_ -lt 100) {
        $zeros = "00"
    }
    elseif ($_ -lt 1000) {
        $zeros = "0"
    }
    else {
        $zeros = ""
    }

    $numbers = $zeros + $_

    $file = $env:TEMP + "\tempfile" + $numbers + ".txt"

    New-Item $file -ItemType file  -ErrorAction SilentlyContinue
}

Now we get an output for every file we create.

-a—    2010-04-06    22:41            0 tempfile0042.txt                         
-a—    2010-04-06    22:41            0 tempfile0043.txt                         
-a—    2010-04-06    22:41            0 tempfile0044.txt                         
-a—    2010-04-06    22:41            0 tempfile0045.txt                         
-a—    2010-04-06    22:41            0 tempfile0046.txt                         
-a—    2010-04-06    22:41            0 tempfile0047.txt                         
-a—    2010-04-06    22:41            0 tempfile0048.txt                         
-a—    2010-04-06    22:41            0 tempfile0049.txt                         
-a—    2010-04-06    22:41            0 tempfile0050.txt                         
-a—    2010-04-06    22:41            0 tempfile0051.txt

If we don’t want this we can add  | Out-Null

New-Item $file -ItemType file  -ErrorAction SilentlyContinue | Out-Null
 
Technorati Tags: ,,
 


 
 

3 Comments
read more
posted 26/03/10

Dalles summering av #TechDaysSE 2010

By Fredrik Wall

Då var TechDays 2010 i Örebro slut.

Måste säga att Microsoft hade fått till det riktigt bra.
Tack för att jag fick stå där och representera Scandinavian
PowerShell User Group.

Zimmergren och Dalle

En bild på mig ståendes i montern. Bilden är tagen av
Jan Viderén.

De två frågor som dök upp mest kring att jag stog på plats
och representerade gruppen var:

  • Är det många som registrerat sig?
  • Varför står du där?

Nä, vi fick inte massor med nya medlemmar, men vi fick folk
nyfikna och vi kommer att skicka ut mail med information
kring gruppen till dem och jag kommer även att skicka information
kring bra sidor till de som var intresserade av det.

Varför jag står på TechDays för andra året i rad är en enkel fråga.
Jag står där för att svara på frågor kring PowerShell, informera om
PowerShell, lyssna på åsikter kring PowerShell, nätverka
och träffa folk i branchen.

Några reflektioner och tankar som jag fick med mig efter detta är
att vi nog ska börja tänka på om det kanske ska vara lokala användargrupper
istället för en enda i Skandinavien.

Detta kan nog gynna spridningen av PowerShell.

Följ utvecklingen av användargruppen på http://powershellug.ning.com

 

Under TechDays så kunde de som var förbi i montern se en liten demonstration
av vad man kan göra med PowerShell och .net framework i form av en Twitter
Status klient i 100% PowerShell kod.

Dalles Twitterklient

Bild på min lilla PowerShell applikation “in action”. Bilden är tagen av
Jan Viderén.

 

Bild på montern dag två. Boken som Niklas Goude hade skrivit och
godiset jag bjöd på lockade en del folk.

045

Vi hade en dessutom en tävling där vi lottade ut boken.
Den vanns av Mats Hultgren på Täby Kommun, grattis Mats.

Då det var en utlottning för en PowerShell användargrupp så
löste jag utlottningen med hjälp av PowerGUI script Editor och
följande oneliner: Get-Random -Min 1 -Max 14.

Hade alla deltagare i en textfil som jag öppnade i PowerGUI script editor
och sedan körde jag onelinern i ett annat fönster och fick då siffran 3
som motsvarade Mats rad.

Enkelt och lite geekigt :)

Nu återstår det bara att få iväg boken till vinnaren.

För er som frågade om vart man får tag i boken så kan ni ta en titt på
http://www.powershell.se där det finns mer information om den.

047

Tack Niklas och Zipper för att vi fick lotta ut den.
Det var många som var intresserade.

 

043

Till sist måste jag bara säga att Henrik Shyfert var riktigt skoj att se på scenen.

 

Här nedan kommer alla bilder som ligger på Flickr och är taggade med TechDaysSE.

 

 

No Comments
read more