Parenthesis in PowerShell
I was asked recently to clarify the different uses of parenthesis in PowerShell: I struggle with $myvar.foo vs. ($myvar).foo vs. ($myvar).foo() vs. $myvar.foo(); vs. $myvar.foo(1), etc., etc. How do I know which one to use for which case? And then how to put this output into a write-output statement? There are basically three ways of [...]
I wanted to start my best-practices series…
I was trying to write the first real post for that series today, but I got really distracted, and instead … Created a Virtual Launch Party for Lee Holmes’ 2nd Edition Windows PowerShell Cookbook Updated my SharpSsh Module (which I wrote about ages ago in Scriptable SSH From PowerShell) to accept PSCredential objects or passwords, [...]
What Scope Am I In?
In PowerShell the question of scope is too complicated and convoluted. I’m going to try to help you understand it, but I’m not guaranteeing that I will be able to make it seem any simpler than it actually is. Hopefully, I won’t make it more complicated than it inherently is In PowerShell you always have [...]
Be a responsible geek – encrypt your email (free)
Everyone should encrypt their emails … especially geeks, who can be expected to understand how little effort it would take for a rogue sysadmin or clever hacker to sniff your email on it’s way to it’s intended destination. Incidentally, if you’re a geek and you don’t know that, you should try running WireShark while you [...]
PowerShell PowerUser Tips: List the Cmdlets in an Assembly
Tiny script… let me know if you know a better way. function Get-Cmdlets { param([System.Reflection.Assembly]$assembly) $assembly.GetTypes() | Where-Object { $_.GetCustomAttributes([System.Management.Automation.CmdletAttribute],$false) } | ForEach-Object { $type = $_ $_.GetCustomAttributes([System.Management.Automation.CmdletAttribute],$false) } | Select VerbName, NounName, @{n="Type";e={$type}} | } ## Example usage. ## You can use the [System.Reflection.Assembly]::Load… methods to get [...]
PowerShell Power User Tips: A Better Prompt
For this edition of my Power User tips for PowerShell, I’m going to share my (heavily annotated) prompt function. Feel free to to copy useful pieces or just place the whole thing in your profile script I’m not going to say anything more, I’ll let the comments speak for themselves. Edit: Someone just pointed out [...]
PowerShell Power User Tips: Bash-style “alias” command.
I keep hearing from new users who are used to bash-style aliases, how frustrating it is not to be able to create aliases with parameters, the way you can in bash … I’m going to show you how to make the “alias” command work roughly the way it does in bash, but first, let me [...]
PowerShell Power User Tips: Current Directory
This is the second in an occasional series of tips for PowerShell users: short posts which don’t intend to give guidance, but merely a tip on a feature you may not be aware of, or maybe even answers to some of the recurring questions that come up in #PowerShell. Fixing the “Current Directory” problem The [...]
PowerShell Power User Tips: Get-Command precedence
This is the first in what I hope will be an occasional series of tips for PowerShell users: short posts which don’t intend to give guidance, but merely a tip on a feature you may not be aware of, or maybe even answers to some of the recurring questions that come up in #PowerShell. We’ll [...]