PSReadLine is one of the module I've been using for a while now and I can't work without it anymore!!!!
Showing posts with label Tip. Show all posts
Showing posts with label Tip. Show all posts
2015/01/06
PowerShell Tip - PSReadLine shortcuts
PSReadLine is one of the module I've been using for a while now and I can't work without it anymore!!!!
2014/09/28
PowerShell Tip - Escape Regex MetaCharacters

Last week I worked on a Scorch PowerShell script that is looking for duplicate Incident Requests inside SCSM by checking new incoming request and existing ticket already in the system.
One of the script step is to look for a match between two strings, something similar to the following:
$String1 = "Title:[PowerShell Rocks!]" $String2 = "Title:[PowerShell Rocks!]" $String1 -match $String2
Straight forward you would think! And at first I was surprised to see the result $FALSE ... yep...to "ass-u-me"...
2014/01/26
PowerShell Tip - Adding Help in the PARAM statement
It’s always a good idea to include help within your functions ! You never know who might benefit from it.
With PowerShell adding help to your script, function and module is a really easy thing to do.
A very cool way to add some help to your script parameters is to add comments within the PARAM statement block. With this method you do not need to write a .PARAMETER directive for each paremeters. However you are required to write at least one directive in the Comment Based Help block (.SYNOPSIS or .DESCRIPTION) to be able to use it.
Example:
Then use Get-Help against your function/script
This command will only return the Parameters information with the help we added in the PARAM statement
Even if this tip is pretty cool, I would still recommend to use the Comment Based Help block to have a centralized place to put all the help !
Thanks for reading! If you have any questions, leave a comment or send me an email at fxcat@lazywinadmin.com. I invite you to follow me on Twitter @lazywinadm / Google+ / LinkedIn. You can also follow the LazyWinAdmin Blog on Facebook Page and Google+ Page.
With PowerShell adding help to your script, function and module is a really easy thing to do.
Help in the PARAM statements
A very cool way to add some help to your script parameters is to add comments within the PARAM statement block. With this method you do not need to write a .PARAMETER directive for each paremeters. However you are required to write at least one directive in the Comment Based Help block (.SYNOPSIS or .DESCRIPTION) to be able to use it.
Example:
<# .SYNOPSIS This function will get some cool stuff #> PARAM( # Specifies the computer name $ComputerName, # Specifies the Log directory Path $Logs = C:\lazywinadmin\logs )#PARAM
Then use Get-Help against your function/script
Get-Help Get-Something -Parameter *
This command will only return the Parameters information with the help we added in the PARAM statement
-ComputerNameSpecifies the ComputerName Required? true Position? named Default value Accept pipeline input? false Accept wildcard characters? false -Logs Specifies the Log directory Path Required? false Position? named Default value c:\lazywinadmin\logs Accept pipeline input? false Accept wildcard characters? false
Even if this tip is pretty cool, I would still recommend to use the Comment Based Help block to have a centralized place to put all the help !
Thanks for reading! If you have any questions, leave a comment or send me an email at fxcat@lazywinadmin.com. I invite you to follow me on Twitter @lazywinadm / Google+ / LinkedIn. You can also follow the LazyWinAdmin Blog on Facebook Page and Google+ Page.
2014/01/25
PowerShell ISE Tip - Navigate between curly brackets
While playing with PowerShell ISE today, I just found out about this little nice trick to navigate between brackets !!! I did not know about this! Pretty cool stuff ! :-)
By positioning your cursor on one of the brackets, you can navigate to its opening/closing one by pressing CTRL + ]
Update: Looks like you can actually do the same thing with SAPIEN PowerShell Studio 2012
Update#2: The matching actually works for anything the ISE recognizes as a matched pair, for example, () and [] in addition to {}. Unfortunately matching doesn't seem to work inside herestrings and other comments. (Thanks Greg Wojan)
That's just Awesome !!! :-)
Here is an example using SAPIEN PowerShell Studio 2012
Thanks for reading! If you have any questions, leave a comment or send me an email at fxcat@lazywinadmin.com. I invite you to follow me on Twitter @lazywinadm / Google+ / LinkedIn. You can also follow the LazyWinAdmin Blog on Facebook Page and Google+ Page.
By positioning your cursor on one of the brackets, you can navigate to its opening/closing one by pressing CTRL + ]
Update: Looks like you can actually do the same thing with SAPIEN PowerShell Studio 2012
Update#2: The matching actually works for anything the ISE recognizes as a matched pair, for example, () and [] in addition to {}. Unfortunately matching doesn't seem to work inside herestrings and other comments. (Thanks Greg Wojan)
![]() |
PowerShell ISE - Navigate between brackets using CTRL + } |
That's just Awesome !!! :-)
Here is an example using SAPIEN PowerShell Studio 2012
Thanks for reading! If you have any questions, leave a comment or send me an email at fxcat@lazywinadmin.com. I invite you to follow me on Twitter @lazywinadm / Google+ / LinkedIn. You can also follow the LazyWinAdmin Blog on Facebook Page and Google+ Page.
Subscribe to:
Posts (Atom)