DuPSUG Basics – Deux

Today was another great day with other PowerShell enthousiasts where I got to share some tricks of the trade.

During DuPSUG’s second Basics event, I was once again able to provide a session, this time about “Improving your Scripts”.

I had a blast and I hope others did too and as promised I’ve made my code available on GitHub on the general DuPSUG GitHub.

 

I’d like to thank all the people attending today’s session for your time and patience, all other speakers for sharing their time, code and tricks and of course @EJHeeres for arranging the event perfectly.

Hope to see you again soon and happy scripting! 🙂

Facebooktwittergoogle_plusredditpinterestlinkedinmail

You’ve got the Power!! plan….

Today I was playing around on some machines on which I noticed the Power Plans were set incorrect, Balanced on a server :'(

Now of course I can do this manually, or I can use PowerShell instead!

Tools not scripts

Since I want to use this more often and want to create my own “toolbelt” [aka module with common tools], I’ve decided to make the solution as advanced functions, not just scripts.

This means that if you simply copy/paste them, you will need to dot source them first in order to use them.
Dutch PowerShell MVP Jeff Wouters has a good article on this in case you want some more info on this.

Quick info:

to the directory in which you have the .ps1 files in case you have them saved seperately and dot source them using

The following functions are provided:

  • Get-AllPowerPlan
  • Get-ActivePowerPlan
  • Set-ActivePowerPlan

I’m guessing the names sort speak for themselves, but do take into account that the Set-ActivePowerPlan relies on the other functions to… well… function 🙂

The Code

 

Happy Scripting! 🙂

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Invoke-Command wrapper function

A quick post this time about something that might be helpful for others, something that saves me from typing too much 🙂

I’ve noticed over the last week that I’ve been doing various remoting commands through Invoke-Command to the same machines, which require additional credentials to access.

Why re-type something when you can automate it 🙂

Before

I used to have to do the following:

Where my SCCM servers are in another forest as my management machine and $CredStore is my personal Credential folder which contains credentials for various systems/domains, as I use these regularly and I’m lazy

After

After some tinkering around and a great tip found on Thomas Maurer’s site, I’ve narrowed it down to:

I’ve personally decided to keep the 2 variables in my $profile as I tend to use those for other functions as well, but otherwise I would recommend placing these in the begin {} block.

The magic here is the converting of a string to an actual scriptblock by the PowerShell engine, accomplished by the following piece of code:

The Code

 

Happy Scripting! 🙂

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail