Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

There is nothing that can’t be done with PowerShell


Basically, what makes PowerShell a so much better command line shell and scripting language than its competitors, is that you can do anything and everything. If you want to create scripts, you must give yourself permission to do so (shown here). In addition, if you are using Windows 7 or later, you must start PowerShell as an administrator to be able to give yourself permission to run scripts.

The secrets behind the versatility of PowerShell is the power of the syntax, excellent type management, and access to both COM components and the .NET Framework. My twitter example is really just an example of accessing the .NET Framework from PowerShell. I could just as well have shown how to convert a JPG image to PNG, which by the way could be done like this:

#Load the Drawing library (no Enter strokes here):
[System.Reflection.Assembly]::Load("System.Drawing, Version=, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

#Load a JPG.
$img=New-Object System.Drawing.Bitmap("C:\Anders\mypicture.jpg")

#Save the desiered format in a variable.

#Save as PNG.
$img.Save("C:\Anders\converted.png", $format)

#Delete the object.

So, let’s say that you want to access a COM object from PowerShell. You would still use the New-Object, but you append the -ComObject argument. This gives me a handle to Excel (if you have it installed):

$xl=New-Object -ComObject Excel.Application

Now, you have state of the art spread sheet automation at your fingertips. You can display it like so:


How about that!?

Categories: PowerShell

Tags: PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *

En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!


Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   |   |   |   Filmtips