PowerShell Goodies

Hi

I wanted to share with you some powershell goodies I use for my day-to-day work

The idea is to have a few files to get you started with scripting fast, while creating a standardization when writing scripts

All the scripts can be found in my Powershell Gallery page as well as on my Powershell GitHub repo

You can find most data and explanations inside the scripts themselves. I want to highlight some of them and provide a brief overview to get you started easily

Functions

If you’re unfamiliar with powershell functions, their close to scripts. The key difference is that, once you run the function, it loads into memory. Then, it’s available for usage by calling it. So, it’s like having a small script inside your script. More on functions can be found here

Array-Action-with-filter

This function will take a .CSV file and run a command against specific items in the array.

Simply put, I import a .CSV file which creates an array object. Then I filter it according to a condition (which you can modify to your needs). Then I will run a set of code against those specific objects.

Import-XX-Module

A function to import modules. Nothing fancy here, just a simple shortcut to different modules I use and a quick way to import them without remembering their exact name, etc.

Write-Log

This is not my own, but one I downloaded online. Credit to Jason Wasser @wasserja. This function will give you a simple logging capability in your script. Look at the function help for exact usage

 

Scripts

Add-TrustedHost

This is useful when you wish to connect to a remote computer that is in a different domain (or workgroup) than you’re in. This will add the remote computer as a trusted host on your device (while retaining the current list!) and then connect to it using credentials you provide

Microsoft.PowerShellISE_profile

My PS profile. A PS profile loads every time you start Powershell ISE and saves you the time from executing a bunch of commands to get started

Mine simply loads a bunch of functions (mentioned above) into memory so I can use them and also opens a template PS script file that I then copy-paste to a new script to start writing scripts quickly

Script_Template

A template PS profile with a bunch of examples and a standard structure to start writing scripts quickly and efficiently.

It incorporates a lot of the above including logging capability, array creation, etc.

Nested Script with Parameters Example

I once encountered a scenario when I needed to call a script from within a script and also pass parameters to the child script. This shows how to do it, in case you need to.

Make sure to check my repos on Github & Powershell Gallery as I will update in the future once I have more to share

 

Do you have any goodies you wish to share? Post in the comments!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s