Last year I wrote a few articles on working with variables. One task I needed was to identify the variables that I had created in a given PowerShell session with a function I wrote called Get-MyVariable. I also posted an article on identifying the object type for a variable value. While trying to find something…
Tag: Variable
Friday Fun What’s My Variable
I use scriptblocks quite a bit in my PowerShell work, often saved as variables. These are handy for commands you want to run again, but don’t necessarily need to turn into permanent functions. $freec={(get-wmiobject win32_logicaldisk -filter “deviceid=’c:'” -property Freespace).FreeSpace/1mb} Now in PowerShell I can invoke the scriptblock. PS S:\> &$freec 94079.72265625 Ok then. I have…
Create a Read-Only PowerShell Session
In my PowerShell training class this week, I was demonstrating how to take advantage of the -Whatif and -Confirm parameters. These parameters exist (or should) for any cmdlet that changes the environment such as stopping a service, killing a process or copying a file. PS C:\> get-process | kill -whatif What if: Performing operation “Stop-Process”…
Warning Signs
I was working on a project with an advanced PowerShell function. One of the goals was to take advantage of the common parameters like -ErrorVariable and -WarningVariable so that when you run the function you can save errors and warnings and work with them later. Turns out one of these works and one doesn’t. But…
Get Variable Definition
Last week a question came across my email about how to find out where a variable came from. I thought this was a great question because I’ve run into this scenario as well. I see a variable but don’t recall what command I typed to create it. What I need is an easy way to…