Close

PowerShell

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 – Scope

Chapter 5 – Scope Note: in csharp, even an if-else statement is it’s own scope. See if this is also true in powershell. Scope is a containerization system designed to stop things from conflicting with each other. If you define a variable in a script, and then redefine it within […]

Read More

PowerShell – Working with xml (via DOM and XPATH)

Let’s say you have the following xml file: PS C:\> $myxmldata = Get-Content C:\temp\credentials.xml PS C:\> $myxmldata codingbee mysecret PS C:\> if you have xml data in an xml file, then you load it into powershell like this: PS C:\> [xml]$myxmldata = Get-Content C:\temp\credentials.xml PS C:\> $myxmldata xml scom — […]

Read More

PowerShell – Filtering and Comparisons

Chapter 11 – Filtering and comparisons There is basically 2 approaches to filtering a command’s output: 1. Using wildcards 2. Using the where-object command. 1. Using wildcards e.g.: get-service -name e*,*x* # returns anything where the name property either begins with “e” or contains the letter “x” Here are some […]

Read More