• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/25

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

25 Cards in this Set

  • Front
  • Back

How can you retrieve a list of environment variables?

gci env:

OR

Get-ChildItem Env:

How can you append a string to a variable?

+=
$tableEntry += SomeString1
$tableEntry += SomeString2

How can we determine the unique items in a collection?

Get-Unique
Get-Content c:\scripts\test.txt | Sort-Object | Get-Unique

How to run an executable with arguments - method 1

$exe = "X:\setup.exe"
$args = @("/ARG1","VALUE1","/ARG2","VALUE2","/ARG3","/ARG4")
& $exe $args

Which command enables you to display data in the Windows PowerShell window and to save that same data to a text file, all with a single command?

Get-Process | Tee-Object -file D:\TEMP_Work\test.txt

How can you run a PS script located on a network share on the local machine you are logged into?

\\server\share\script.ps1
Use this for logging into machines via RDP and running build/config scripts.

How can you pause a script in PowerShell?

How can you pause a script in PowerShell?
Start-Sleep -s 10

What are the implications of upgrading a PowerShell version from the default to a newer version?

It might break apps - certain apps such as Exchange/SCCM require certain versions of PS and the WMF.

How can you run the erase the contents of a file without deleting the file itself?

Clear-Content c:\scripts\test.txt

How can you get a history of previously run items on the PS Command Line?

Get-History

How can you run a previously executed command?

Invoke-History 3
Invoke-History 3;Invoke-History 4

When using Write-Host, how can you mix colours of text on the same line?

Write-Host "Data for " -nonewline; Write-Host "atl-ws-01" -foregroundcolor red -backgroundcolor yellow -nonewline; Write-Host " retrieved May 12, 2006"

What is the CMDLET to write a warning message?

Write-Warning "The folder C:\Scripts2 does not exist."

How can you determine whether or not a specific string value exists in a text file? e.g. Check a log file for the string "error".

Get-Content c:\Temp\ErrorLog.txt | Select-String "Failed" -caseinsensitive

How can you exit a function immediately?

Use the return statement.
function Get-NamedProcess($name=$null) {
if ($name -eq $null) {Write-Host -foregroundcolor Red 'Specify a name!'
return }
Get-Process $name}

How can you determine the number of days between two dates?

New-TimeSpan cmdlet

How can you work around a Citrix XenApp server GPO Lockdown policy that denies CMD prompt access?

powershell.exe

How can you get info about installed modules?

Get-Module -listavailable

How to run an executable with arguments - method 2

$ChocoStart = 'choco'
$ChocoInstall = 'install'
& $ChocoStart $ChocoInstall 'GoogleChrome'

How do you format a function?

function Disable-Firewall { netsh advfirewall set allprofiles state off }
# Call the function
Disable-Firewall

How can you capture user input?

Use Read-Host
$a = Read-Host “Enter your name”
Write-Host "Hello" $a

How can you pass Command Line Arguments to script with spaces?

myscript.ps1 server1 benp
Accessed in script by $args array
$servername = $args[0]
$username = $args[1]

What are four loop options?

Do While loop, Do Until loop
For loop, ForEach loop

What is the difference between Do While and Do Until loops?

Do While loop - repeat a set of commands WHILE a condition is met
Do Until loop - repeat a set of commands UNTIL a condition is met

What is the difference between For and ForEach loops?

For loop - repeat the same steps a specific number of times
ForEach loop - loop through a collection of objects