PowerShell Exam 1

0.0(0)
studied byStudied by 6 people
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/39

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

40 Terms

1
New cards

Conditions must be bounded by _____

()

2
New cards

What is wrong with the following statement?

if ($abc == "One")

  {Write-Host "They are equal"}

The == cannot be used as a conditional operator. You must use -eq

3
New cards

Play computer.  What is the first line printed by the code below?

$val = "Red"
$b=0
$r=0
$g=0
switch ($val)
  {
        "Blue" {
                $b++
                  Write-host "Violets are Blue"}
        "Green" {
                 $g++
                  Write-host "Leaves are green"}
        "Red" {
                 $r++
                 Write-host "Apples are red"}
  }
Write-host "B = $b    g = $g    R = $r"

Apples are red

4
New cards

What output would result from the following command?

$n = 3

if ($n -lt 5)

  { write-host $n}

3

5
New cards

What does the following code do?

if (test-connection -Computername "SRV1" -quiet -count 1 )

  {

       get-content -path \\SRV1\c$\config.txt

 }

If SRV1 is "pingable", it retrieves the contents of the specified file

6
New cards

Play Computer.  What will be printed by the code below?

for ($var = 0; $var -lt 3; $var++)

{  write-host $var }

0 1 2

7
New cards

Play Computer.  Step through the following program statements, keeping track of what is stored in memory and what is output.  Select the answer that correctly shows what is output following execution.

$grd = 75

$numpass = 0

$numfail = 0

if ($grd -lt 60)

     { numfail++ }

else

      {numpass++}

write-host "Number passing = $numpass, Number failing = $numfail"

Number passing = 1, Number failing = 0

8
New cards

Play Computer.  What will be printed by the code below?

$counter = 0 
 while ($counter -lt 5) 
   {    
              $counter    
              $counter++ 
           }

0 1 2 3 4

9
New cards

A condition must evaluate to be _______.

boolean ($true or $false)

10
New cards

Play Computer.  What will be printed by the statements below, assuming Cottonmouth and Diamond can be contacted, but Python can't.

$s = @("Cottonmouth", "Diamondback", "Python")
foreach ($i in $s)
{  
  if (test-connection -Computername $i -quiet -count 1)
    { write-host "$i is up"
    }
 else
   { write-host "$i is down"}
 }

Cottonmouth is up Diamondback is up Python is down

11
New cards

The | character is called a ______________

pipe or pipeline

12
New cards

The PowerShell ISE is an acronym for

Integrated Script Environment

13
New cards

Which of the commands below illustrates the best way to invoke the script Script1 which resides in my current directory?

.\Script1

14
New cards

You can use an editor such as Word to create PowerShell Scripts.

False

15
New cards

____________________ is a process that matches each object you pass in to a command to parameters specified by the second command

Parameter binding

16
New cards

What happens when the following command is issued?

Get-Service -name "wuauserv" | Start-Service

the output of Get-service is piped into the start-service command, eliminating the need to specify parameters of what service to start

17
New cards

A ___________ is one or more commands, stored in a common file, that are executed individually when the file is executed.

script

18
New cards

What does the following command do?

command1 | more

the output of command1 is broken into multiple pages of output

19
New cards

PowerShell scripts must end with the extension ______.

.ps1

20
New cards

The PowerShell ISE allows you to enter a script and run or test it within the same application.

True

21
New cards

By default, the type of $n will be ___________.

$n = 123

Int32

22
New cards

Newbie Admin wants to store the value 0 in a variable.  Which of the following statements would correctly solve the problem? (Select ALL correct answers)

  • A. tot = 0

  • B. $tot

  • C. $tot = 0

  • D. $n = 0

C & D

23
New cards

In PowerShell, what would be printed by the code below?

$num = 1

$num = 2.8

$fnum = [Int32]$num

$fnum

3

24
New cards

What are the basic data types?

boolean, string, integer and floating point

25
New cards

PowerShell uses Double by default for numbers with a decimal point.

True

26
New cards

What would be printed by the following code?

$Num = 80

$str = 'The Result is $Num'

$str

The Result is $Num

27
New cards

Newbie Admin is writing a PowerShell script and needs to determine the number of characters stored in the string variable $str.  Which of the following would be a correct way to count the characters and store the result in the variable $num?

$num = $str.length

28
New cards

In the statements below,  remove is  a ________________

$Str = "A rolling stone gathers no moss."

$Str2 = $Str.remove(4,3)

method

29
New cards

What would be printed by the following code?

$Num = 80

$str = "The Result is $Num"

$str

The Result is 80

30
New cards

In the following scenario, what is stored in $Str2?

$Str = "A rolling stone gathers no moss."

$Str2 = $Str.remove(4,3)

A rong stone gathers no moss.

31
New cards

What command allows you to view help information on a command? (PowerShell command, not an alias)

get-help

32
New cards

When you are in PowerShell, commands are case-sensitive.

False

33
New cards

What command can be used to display all stored aliases?

Get-alias

34
New cards
<p>Based on the image, If your current location is dir2, which statement below would move your location to dir3?</p>

Based on the image, If your current location is dir2, which statement below would move your location to dir3?

Set-Location ..\dir3

35
New cards
<p>Based on the image,&nbsp;your current working directory is dir1.&nbsp; Which of the legacy DOS commands below would successfully change your directory location to dir3?</p>

Based on the image, your current working directory is dir1.  Which of the legacy DOS commands below would successfully change your directory location to dir3?

cd ..\dir3

36
New cards
<p>Based on the image, Your current directory is dir1, which command below would successfully list the contents of dir2?</p>

Based on the image, Your current directory is dir1, which command below would successfully list the contents of dir2?

Get-Childitem ..\dir2

37
New cards
<p>Based on the image, Your current location is dir3.&nbsp; Which of the statements below would successfully delete file3a.docx from dir3a?</p>

Based on the image, Your current location is dir3.  Which of the statements below would successfully delete file3a.docx from dir3a?

remove-item dir3a\file3a.docx

38
New cards
<p>Based on the image,&nbsp;If you are in dir1, what command would successfully remove all files in dir2?</p>

Based on the image, If you are in dir1, what command would successfully remove all files in dir2?

remove-item ..\dir2\*.*

39
New cards

Dir is the alias for which PowerShell command?

Get-ChildItem

40
New cards

How do you run PowerShell in Administrator mode?

Access the PowerShell app, Right-click, then select "Run as Administrator"