Classwork 7
Classwork 7
Classwork 7
Set-Location C:\
Clear-Host
New-Alias –Name np –Value “C:\Windows\Notepad.exe”
Part Two
Var refers to the variable itself, meaning the container in which you can put things.
That creates a new variable, $x, containing the value 7. Keep looking atthe
example until you’re sure you understand why.
However, this only works with variables – you cannot use this same technique to
access properties, array indices, etc. To do those, you must use a
Kevin Hoag
Classwork 7
subexpression:
PS C:\> $message
Remember that you can declare a type for your variables. Common types include
[string], [int], [bool], [xml], [datetime], and others.
PS C:\> [int]$x = 5
PS C:\> $x = "Hello"
Error: "Input string was not in a correct format." At line:1 char:1 + $x = "Hello" +
~~~~~~~~~~~~ + CategoryInfo : MetadataError: (:) [],
ArgumentTransformationMetadataException + FullyQualifiedErrorId : RuntimeException
Exercises
Write down your answers for the following tasks:
Get-Variable
$x = 100
Remove-Variable x
Kevin Hoag
Classwork 7
$procs = Get-Process
$procs[0]
$procs[0].Name