Manipulating Data Within Powershell Functions Flashcards
Name the types of variables.
- Loosely typed - when a value is assigned to an undefined type of variable
$variable - Strongly typed - type is assigned to variable
Variable is an integer, or string
What is a variable?
A unit of memory in which values are stored
What are the different variable types?
- User-created variables
- Automatic variables
- Preference variables
What is a user created variables?
Created and maintained by the user. Variables created within the PS command line exits only while the PS window is open.
What are automatic variables?
Store the state of PS. PS created these variables and changes their values as required to maintain their accuracy.
What are preference variables?
Store users preference for PS. These variables are created by PS and populated with default values that may be changed.
Create a typed variable for the number 10
[Int]$variable1 = 10
Created a typed variable for the date January 1, 2023
[DateTime]$variable1 = “January 1, 2023”
What are six common variable types?
Boolean
DateTime
Powershell object
Script block
String
Array
What is casting data values?
Converting one object type to another
Not all objects can be cast
When a value is cast to a particular data type, it is a ……
One time change
When a variable is cast to to a particular data type it stays until…..
It is updates
Cast $variable1 = 1 as an integer using the AS operator
$Variable1 -as [int]
What is the F operator?
Used to format the values or string into something else
You can begin the statement with the format you want
Format ‘$variable1 = 123.4567890’ to display only three decimal places
“{0:n3}” -f $variable
Format ‘$variable1 = 3106359509’ with dashes to look like a phone number
“{0:###-###-####}” -f $variable1
How do you determine what type of variable ‘number1’ is?
$number1.GetType().Name
What does the dash replace operator do?
-replace
It takes the Input string - replace operator - matching pattern - replacement string