RSS

Tag Archives: Powershell

PowerShell – Book review of : Windows PowerShell Best Practices

Windows PowerShell Best Practices

Last week I completed PowerShell Deep Dives which got me excited again to read more about PowerShell. As such, I continued reading the next book on my reading list: Windows PowerShell Best Practices by Microsoft Scripting Guy Ed Wilson.

The book was released late January 2014 and is the most recent book about PowerShell that has been released to my knowledge. This means it includes PowerShell 4.0, Desired State Configuration DSC and references to Windows 8.1 and Windows Server 2012 R2.

In my opinion the book was very well written and contains a good mix of theory, sample scripts and “notes from the field” from many PowerShell specialists. The sample scripts are available for download at Technet Script Center.

The best practices that are described in the book are very recognizable and I had already adopted many of them based on the many great blog posts by the community. In the book they are all bundled and well explained including examples. Where the book really shines though in my opinion is that it describes how PowerShell is used in real-life, how it relates to many other processes within a company and what you need to consider.

I think this book is a must-have for anyone working with PowerShell. For those starting with PowerShell, I recommend first reading the books “Learn Windows PowerShell In A Month Of Lunches” and “Learn PowerShell Toolmaking In A Month Of Lunches” and then read this book.

Notes:

 
 

Tags: , , , , ,

PowerShell – Book review of : PowerShell Deep Dives

PowerShell_Deep_Dives

I’ve had the book PowerShell Deep Dives laying around since August 2013. I had read some parts of it because I follow many of the great PowerShell community members that contributed to it. But I hadn’t gotten to reading it completely yet until now.

The title of the book includes “deep dives” implies very deep technical content and I can assure you, this type of content is present in the book. some of the stuff I still need to wrap my head around to understand properly. On the other hand, other parts of the book are more simplistic which you might not expect from a deep dives book.

The book covers a very broad number of topics and technologies. What I liked is that the articles were written by professionals and community members that are specialized in or are very knowledgeable about this specific topic/technology.

As a result of having the broad number of topics and technologies, not all parts of the book might be relevant to you (especially as a deep dive). I found myself skimming over some parts later in the book since it is very unlikely it is or will become useful for me. This will differ from person to person though, so take a good look at the topics being covered in the table at the end of the article.

All in all it was a good read and I think I’ll use the book mainly as a reference for those times that I need the deep dive insights. The book can be ordered from by example Manning.com and all royalties go to charity: Save the Children

 

Part 1 PowerShell administration
1 Diagnosing and troubleshooting PowerShell remoting (Don Jones)
2 CIM sessions (Richard Siddaway)
3 Collecting and analyzing performance counter data (Arnaud Petitjean)
4 TCP port communications with PowerShell (Boe Prox)
5 Managing systems through a keyhole (Bartosz Bielawski)
6 Using PowerShell to audit user logon events (Mike F. Robbins)
7 Managing and administering a certification authority database with PowerShell (Cadims Podans)
8 Using PowerShell to reduce Active Directory token bloat (Ashley McGlone)
Part 2 PowerShell scripting
9 The 10 PowerShell scripting commandments (James O’Neill)
10 Avoiding the pipeline (Jeff Wouters)
11 A template for handling and reporting errors (Will Steele)
12 Tips and tricks for creating complex or advanced HTML reports with PowerShell (Jonathan Medd)
13 Using and “abusing” dynamic parameters (Bartosz Bielawski)
14 PowerShell type formatting (Adam Driscoll)
15 Scalable scripting for large data sets: pipeline and database techniques (Matthew Reynolds)
16 Building your own WMI-based cmdlets (Richard Siddaway)
17 Turning command-line tools into PowerShell tools (Jefferey Hicks)
Part 3 PowerShell for developers
18 Using Source Control Software with PowerShell (Trevor Sullivan)
19 Inline .NET code (Richard Siddaway)
20 PowerShell and XML: better together (Josh Gavant)
21 Adding automatic remoting to advanced functions and cmdlets (Karl Prosser)
22 Taming software builds (and other complicated processes) with psake (Jim Cristopher)
Part 4 PowerShell platforms
23 PowerShell and the SQL Server provider (Ben Miller)
24 Creating flexible subscriptions in SSRS (Donabel Santos)
25 Inventory database table statistics using PowerShell and SQL Server Management Objects (Robert C. Cain)
26 WSUS and PowerShell (Boe Prox)
27 Provisioning IIS web servers and sites with PowerShell (Jason Helmick)
28 Active Directory Group Management application (Chris Bellee)

 

 
1 Comment

Posted by on June 7, 2014 in Automation, ICT, Microsoft, Powershell, Windows

 

Tags: , , , ,

Introduction to PowerShell – Also relevant for NON Microsoft administrators

Today I had the privilege that many colleagues of mine from Open Line decided to sacrifice their free time and attend my session: “Introduction to PowerShell – Also relevant for NON Microsoft administrators”

The goal of this session was to:

  • Inform people of the advantages of scripting/automation in general.
  • Inform people of the advantages of PowerShell over CLIs and other scripting languages.
  • Inform people that PowerShell is not just for Microsoft administrators.
  • Teach people about the PowerShell basics.
  • Inform people about the many possibilities with PowerShell.
  • Provide people with a lot of practical resources to increase their knowledge and skill.

I really enjoyed the session and got a lot of interactivity and positive feedback. Next up is a follow-up session which will be more of a workshop style.

I’ve uploaded the presentation in PowerPoint and PDF format here:
https://bjornhouben-web.sharepoint.com/Lists/Files/DispForm.aspx?ID=22

Please share this so that others can benefit from it as well.

Notes:

  • I’ve included many useful resources as notes in the PowerPoint presentation, which makes the presentation also interesting to people who are not PowerShell beginners.
  • Also if anyone has suggestions to make the presentation better, please let me know.
 
 

Tags: , ,

PowerShell – Using PowerShell 5 to automate the installation of your favorite Windows applications

In this blog post I will explain why to automate installations of Windows applications and how you can do this.

Why automate the installation of applications?

But first, why is this useful? Well this depends on your situation and there are probably many good reasons. For me though, it basically boils down to this:

  1. I often reinstall my computers with new (preview) versions of Windows operating systems and having to install applications each time is a waste of time. Also sometimes you forget to install some things.
  2. On a regular basis, friends and family either want me to install or upgrade their PC and I want to provide them with a standard set of programs that most people need/want without having to spend a lot of time on it. By example virus scanner, burning program, media player, codecs, etc.
  3. I want to update existing installed applications to the latest (and hopefully more secure and feature packed) versions.
  4. When installing applications, there are often checkboxes enabled to install other applications (you generally don’t want to install). Automated solutions using packages generally prevent these additional unwanted applications from installing.

Which tools to use to automate the installation of applications?

Before PowerShell 5 preview was released, I used both Ninite and Chocolatey to perform to automate installations. They both have their advantages as described on this wiki page.

The PowerShell 5 preview version of OneGet installs and searches software from Chocolatey repositories, but support of additional repositories will come in subsequent versions.

How to automate the installation of applications using PowerShell 5 preview?

To automate the installation of applications a couple of things are required:

  1. You need to determine which applications you want to install automatically.
  2. You need to determine the package name that Chocolatey uses for this application. Options include:
    -Using a browser to browse the Chocolatey packages
    -Using PowerShell and a part of the name of the application you’re looking for. By example if you’re looking for Irfanview, use:
    Find-Package -Name “fan”
  3. Store the package names to install somewhere (e.g. in a .txt file on OneDrive for easy access). My .txt file by example includes:
    AdobeReader
    Directx
    ffdshow
    Flashplayerplugin
    GoogleChrome
    Imgburn
    IrfanView
    Javaruntime
    Keepassx
    Mp3tag
    mpc-hc
    PDFCreator
    Silverlight
    TeamViewer
    Totalcommander
    Winrar
    greenshot
  4. Use the Install-Package cmdlet to install all the packages whose name is in the file from step 3.
    Install-Package -Name (Get-Content C:\OneDrive\AppsToInstall.txt) -Confirm:$False
  5. Wait for the programs to install

My opinion

It’s great to be able to use PowerShell to install my list of favorite applications similar to like I did with Chocolatey and I’m also looking forward to see what benefits the additional repositories will bring in the future.

I did encounter some errors however while trying to install some applications like Firefox and dotnet3.5. But since it’s still a preview, this will probably be fixed.

For regular users, I think they are better off sticking to by example Ninite because they’re often afraid of anything that involves a CLI.

Blog posts by other people about OneGet

Some other people have also blogged about the OneGet module and have gone in more technical detail, so be sure to take a look at their posts as well:

More information about PowerShell 5 Preview including a download link

Windows Management Framework v5 preview, includes also Desired State Configuration (DSC) improvements and NetworkSwitch commandlets to manage network switches that pass the Certified for Windows Program. For more information including a download link, you can read the initial blog post. : Windows Management Framework V5 Preview

 

 

 

Tags: , , , , , , , ,

Powershell – Recording of ‘The Case for PowerShell: Why To Learn-PowerShell So You Needn’t Leave-Industry’

Last week Mark Minasi presented a webinar made possible by http://www.learnit.com called:
“The Case for PowerShell: Why To Learn-PowerShell So You Needn’t Leave-Industry”.
The recording can be found here.

In this webinar he explains why ICT administrators need to be(come) familiar with PowerShell. He also explains the basic principles of PowerShell to help lower the threshold for people that have been shying away from command line interfaces (CLI) and scripting in the past. He does this by explaining how PowerShell is different from by example the CLI and Visual Basic Scripting (VBS).

I share his opinion about the necessity to learn PowerShell and therefore I hope I can help spread the message.

You can keep track of Mark Minasi by following him at Twitter: https://twitter.com/mminasi (@mminasi).

 
Leave a comment

Posted by on September 11, 2013 in Uncategorized

 

Tags: , , , , , , , , , , , , , , , ,

LazyWinAdmin – a great powershell script for more efficient Windows management

The last couple of months I’ve been playing around a lot with PowerShell and I’ve also been trying to make some nice GUI versions for my script using PowerShell Studio 2012 from Sapien Technologies Inc. While looking for more information how to best use PowerShell Studio 2012 I came across LazyWinAdmin.

LazyWinAdmin is a great tool created by Francois-Xavier C that will save you a lot of time. It provides you with most of the commonly used tools and commands in a very structured and easy to access way. In the picture below you can see what I mean.

For more info on the tool, take a look at the website and be sure to download and test it yourself.

If you want to take a look at other useful tools I’ve found in the past, take a look at my applications list.

 
 

Tags: , , , , , , , , , , , ,

PowerShell – Reverse strings and reverse file names

With PowerShell it is relatively easy to reverse a string:
$str = “gnirtsdesrever”
$str[-1..-($str.length)] -join “”

Some of you might ask: Why would anyone want to do this ? Well, since the start of the year Usenet DMCA takedowns have begun to occur automatically, very quickly and very often. This means many movies and TV series on Usenet / News Groups are being taken offline very quickly.

Counter measures to prevent takedowns by uploaders include:

  • The use of encrypted links to NZB files.
  • The use file names that make it harder to find copyrighted files.

As you can probably guess, some just reverse the file names. The PowerShell script I’ve created will automate reversing the file names for files in the specified folder that match the specified file name filter.

I hope it is useful for you as well.

PS: Someone else on usenet had the same idea as me and created a VBS that will add a right-click menu option to explorer. I’ve added this in the same location as my PowerShell script as well.

 

Tags: , , , , , , ,

PowerShell – Cleaning folders containing temporary files

At the companies I’ve worked for , disk space on the system disk ran out on a regular basis for some systems and caused a lot of monitor calls. These kind of boring repetitive tasks are always the ones you want to automate.

So when I came across the great blog post “Weekend Scripter: Use PowerShell to Clean Out Temp Folders” on the “Hey, Scripting Guy! Blog”, I wanted to post it on my own blog as well. The blog post also describes the process of creating the script very well, which is very convenient for those who are relatively new to PowerShell to scripting and want to learn how to do it better.

If you want to take it even a step further, you could automate it even more. By example by automatically running the clean script when an event is generated that the disk is running out of space. You can configure this using by example:

Or you could use PowerShell remoting to do it on many systems at the same time. This could come in handy by example when after WSUS patching the content in “C:\Windows\SoftwareDistribution\Download” is not deleted automatically.

 

Tags: , , , , , , , , , , , , ,

PowerShell – Manage printers

At work a colleague of mine was looking to modify printer permissions on a Server 2008 R2 terminal server using PowerShell. And to be honest, it was more difficult to do than I had expected.

So naturally, I started looking if someone had already created a script for this same purpose and eventually I found this great script created by Vadims Podans:
PrinterUtils.ps1 / Functions for advanced printer management

By leveraging this script, permissions were easily modified by adding the following lines:
$name = “Printername”
Get-Printer “localhost” $name | Add-PrinterPermission “corp\Domain Users” 0 “print”
Get-Printer “localhost” $name | Remove-PrinterPermission “everyone”
Get-Printer “localhost” $name

My modified script can be found here: http://bjornhouben-web.sharepoint.com/Lists/Scripts/DispForm.aspx?ID=22

Be sure to check Vadims Podans website for other great resources: http://en-us.sysadmins.lv/

 

Tags: , , ,

 
Follow

Get every new post delivered to your Inbox.

Join 818 other followers

%d bloggers like this: