I wanted to quickly share some of the cool Profile tips I’ve started using. Some of these are one’s I’ve come across online, so I can’t take credit for them all! A lot of them are driven by the fact that I have one profile I use on all my machines – so the script needs to be flexible.
Snap-In Loader
Add this little bit to load all the Snap-ins you regularly use. It will only try to install one’s that are installed, so if you have different sets available on each machine there won’t be any error messages.
$snapins = “PowerGadgets”,”PowerPad”, “ZachsCmdlets”
$snapins | ForEach-Object { if ( Get-PSSnapin -Registered $_ -ErrorAction SilentlyContinue ) { Add-PSSnapin $_ -ErrorAction SilentlyContinue } }
BootStrap Folder
I wanted to have a folder that I could organize all my “Random Functions” into that would still get loaded into the PowerShell session (the Profile document gets too large to manage otherwise!).
The File location:
$myscripts = “C:/somelocation/scripts/bootstrap/”
ls $myscripts |% { &”$myscripts /$_” }
*Important NOTE: Inside the bootstrap files, any function or variable you want available in the session needs to be declared using the “global” moniker:
E.g.: $global:myvar
E.g.: global:myFunction(){ return “foo” }
Recursive Lookup
Want to filter files recursively? Use this FF function (it’s sort of my own shout-out to my previous favorite bash):
function global:ff ([string] $glob) { get-childitem -recurse -include $glob }