PowerShell – Environment Variables

to set an environment variable, you can do this [powershell] [environment]::SetEnvironmentVariable("TestVar", "a simple string", "Machine") [/powershell] Note, I think you can set the value at sessions/user/machine level. In the above case I have set them to the machine level. Now to retrieve an environmenment from somewhare else, e.g. from another […]

Read More

PowerShell – Common Paramaters

Every command in powershell, has a set of “common parameters” (i.e. options). This is indicated in all the help pages, in the syntax section…which alway ends with: [] This family of paramaters is made up of the following parameters: – Debug (db) – ErrorAction(ea) – ErrorVariable(ev) – OutVariable(ov) – OutBuffer(ob) […]

Read More

PowerShell – Windows Media Instrumentation (WMI)

WMI is a standalone component and Powershell only interacts with it. WMI essentially houses a massive collection of system information and tries to organise this data in a meaningful way. Here is very useful guide: [powershell] help about_WMI_Cmdlets [/powershell] At the top level, WMI is organised into namespaces (which are […]

Read More

PowerShell – exiting out of outerloop

Special Chapter – exiting out of outerloop when exiting out of an outer loop, you are effecting exiting out from all the inner loops. You do this by labeling your loops like this: $list = 1,2,3,4,5 # here we use the “:{loops label}” syntax to give a loop a name, […]

Read More

PowerShell – Running tasks in the background

PowerShell lets you run commands in the background and you can then retrieve the results later.This is useful if you want to run time consuming commands and you want to keep the terminal free. Here’s how to start a background job. [powershell] start-job -scriptblock {get-childitem} [/powershell] or if you have […]

Read More