PowerShell Flashcards
The $ sign does what in variables?
Gets the contents of that variable. Also can be used to do things with the contents of the variable.
After executing break. What statements after the break cmd will be executed?
If, else if, and if statements
What does the global scope represent?
The entire shell
Whenever you run a script is a scope created for it?
Yes a separate on for the script
Do functions get their own scope too?
Yes they do
What is used to express relationships between scopes in powershell
Parent child type of relationship
If the value is being read and after going to global scope, and nothing is found what happens?
You get an error or a default value is used such as a empty string for variable $x
When you write a value, what scope does it take place in?
The current scope
When your done using a variable in a scope, does the same variable get destroyed in the other scopes? why?
No because the other scopes have their own copy and could have their own values.
When reading in a scope can you go down the path to child scopes?
No parent scopes aren’t allowed to do that.
Can each scope create elements with the same name as other scopes?
Yes it can for example aliases such as d in global and another d in script scope.
What is a best practice for scopes?
Let the scope be a wall, don’t start reaching into other ones, can make it very confusing.
What is another best practice?
Never access anything outside your own scope
best practice on undefined variable accessing?
Never access a variable that hasn’t been defined in your own scope yet
What should be used to pass info in and out of scopes?
A parameter to get info into the scope. And a write-output to pass info out of the scope
What does a cmdlet binding attribute do?
it changes your simple parametrized function into a advanced function. Some call it a script cmdlet.
How does the parameter decorater go?
[Parameter()]
Goes on a per parameter basis
If you have an array [] in your powershell script, and add a single item, will it fail?
No powershell will take that one item and make your array, an array of one item.
What parameter description will accept input from pipeline?
ValueFromPipeline=$True
Of course you can probably go false but haha no reason to do that, probably don’t even let you do that.
Any script or function that accepts input from the pipeline needs to have three named script blocks. What are they?
Begin{}
Process{}
End{}