0
0
PowerShellscripting~20 mins

Why string manipulation is frequent in PowerShell - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Manipulation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why is string manipulation common in scripting?
In scripting, why do we often manipulate strings like filenames, paths, or user input?
ABecause strings are the main way to represent and handle text data in scripts.
BBecause strings are faster to process than numbers in scripts.
CBecause scripts cannot handle numbers or other data types.
DBecause string manipulation automatically fixes all script errors.
Attempts:
2 left
💡 Hint
Think about how scripts interact with files, commands, and user input.
💻 Command Output
intermediate
2:00remaining
Output of string manipulation in PowerShell
What is the output of this PowerShell command? $path = 'C:\Users\Admin\Documents\file.txt' $filename = Split-Path $path -Leaf Write-Output $filename
PowerShell
$path = 'C:\Users\Admin\Documents\file.txt'
$filename = Split-Path $path -Leaf
Write-Output $filename
ADocuments
Bfile.txt
Cfile
DC:\Users\Admin\Documents
Attempts:
2 left
💡 Hint
The -Leaf parameter extracts the file name from a path.
📝 Syntax
advanced
2:00remaining
Correct way to replace text in a string in PowerShell
Which option correctly replaces all occurrences of 'cat' with 'dog' in the string $text?
PowerShell
$text = 'The cat sat on the cat mat.'
Areplace($text, 'cat', 'dog')
B$text.replace('cat', 'dog')
C$text -replace 'cat', 'dog'
D$text.replaceAll('cat', 'dog')
Attempts:
2 left
💡 Hint
PowerShell uses the -replace operator for string replacement.
🔧 Debug
advanced
2:00remaining
Identify the error in this PowerShell string manipulation
What error does this script produce? $name = 'Alice' Write-Output $name.ToUpperCase()
PowerShell
$name = 'Alice'
Write-Output $name.ToUpperCase()
AMethod invocation failed because method 'ToUpperCase' does not exist.
BOutputs 'ALICE' correctly.
CSyntaxError: Missing parentheses.
DOutputs 'alice' in lowercase.
Attempts:
2 left
💡 Hint
Check the exact method name for converting to uppercase in PowerShell.
🚀 Application
expert
3:00remaining
Extract domain from email using PowerShell string methods
Given the email address stored in $email = 'user@example.com', which command extracts the domain part 'example.com'?
PowerShell
$email = 'user@example.com'
A$email.Split('@')[0]
B$email.Substring($email.IndexOf('@') + 1)
C$email -replace '.*@', ''
D$email.Split('@')[1]
Attempts:
2 left
💡 Hint
Splitting by '@' separates user and domain parts.