Unit 6: Advanced PowerShell and Automation - Practice Quiz

CSC104 — It Fundamentals 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which PowerShell cmdlet loads a module into the current session?

Modules Easy
A. Export-ModuleMember
B. Install-Module
C. Get-Module
D. Import-Module

2 Which cmdlet lists modules currently imported into a PowerShell session?

Modules Easy
A. Publish-Module
B. New-Module
C. Get-Module
D. Find-Module

3 Which cmdlet imports data from a CSV file as PowerShell objects?

File handling (CSV, JSON, XML) Easy
A. ConvertFrom-Json
B. Get-Content with additional commands that manually split every comma-separated line
C. Export-Clixml
D. Import-Csv

4 Which cmdlet converts a JSON-formatted string into PowerShell objects?

File handling (CSV, JSON, XML) Easy
A. ConvertFrom-Json
B. ConvertTo-Json
C. Import-Clixml
D. Export-Csv

5 What is a common purpose of a menu in a PowerShell script?

Menus Easy
A. To encrypt all variables
B. To compile the script
C. To select an action
D. To automatically install every available operating system update before execution

6 Which cmdlet prompts a user to enter text in the console?

Prompts Easy
A. Write-Output
B. Read-Host
C. Write-Warning
D. Out-File

7 Which cmdlet displays processes running on a computer?

System tasks (services, processes, registry, tasks) Easy
A. Get-Item
B. Get-Service
C. Get-Process
D. Get-ScheduledTask

8 Which cmdlet starts a stopped Windows service?

System tasks (services, processes, registry, tasks) Easy
A. Resume-Job
B. Start-Process
C. Start-Service
D. Enable-ScheduledTask and configure it to run whenever the computer starts

9 Which PowerShell cmdlet retrieves an Active Directory user account?

Active Directory Easy
A. Get-ADGroup
B. Get-ComputerInfo
C. Get-LocalUser
D. Get-ADUser

10 Which PowerShell module commonly provides cmdlets such as Get-ADUser?

Active Directory Easy
A. A custom module that reads user accounts directly from exported CSV files
B. Microsoft.PowerShell.Management
C. ScheduledTasks
D. ActiveDirectory

11 Which cmdlet runs a command on one or more remote computers?

PowerShell Remoting Easy
A. Invoke-Command
B. Start-Job
C. Enter-PSSession
D. Invoke-Item

12 Which cmdlet starts an interactive PowerShell session with a remote computer?

PowerShell Remoting Easy
A. Enter-PSSession
B. Connect-PSSession and automatically execute every command stored in the user's history
C. Receive-PSSession
D. New-PSSession

13 Which cmdlet starts a PowerShell command as a background job?

Jobs Easy
A. Start-Job
B. Receive-Job
C. Wait-Job
D. Get-Job

14 Which cmdlet retrieves the results produced by a PowerShell background job?

Jobs Easy
A. Wait-Job and permanently save all results in the Windows event log
B. Remove-Job
C. Stop-Job
D. Receive-Job

15 What is the main purpose of a scheduled task?

Scheduled tasks Easy
A. To rename a user account
B. To run an action automatically
C. To convert unstructured files into Active Directory user objects without a script
D. To create a PowerShell module

16 Which attribute restricts a PowerShell parameter to a predefined set of values?

Advanced functions with validation Easy
A. CmdletBinding
B. ValidateSet
C. Alias
D. Parameter

17 Which .NET technology can be used to create graphical interfaces in PowerShell?

GUI scripting Easy
A. PowerShell Remoting
B. Background Jobs
C. The registry provider with recursively generated keys for each graphical control
D. Windows Forms

18 Why might a user-management script read account details from a CSV file?

Automation scripts for user management Easy
A. To process many accounts
B. To restart every service
C. To convert each account into a scheduled task that runs whenever the user signs in
D. To compile graphical forms

19 Which cmdlet retrieves entries from Windows event logs?

Log automation Easy
A. Get-Process
B. Get-WinEvent
C. Write-Host
D. Import-Module

20 What is the purpose of a basic system-monitoring script?

System monitoring Easy
A. To publish a module
B. To replace the operating system whenever memory usage exceeds a configured threshold
C. To track system health
D. To design a GUI theme

21 A script requires the ActiveDirectory module. Which command should be used at the beginning of the script to load the module and stop execution if loading fails?

Modules Medium
A. Get-Module ActiveDirectory -ErrorAction Stop
B. Import-Module ActiveDirectory -ErrorAction Stop
C. Install-Module ActiveDirectory -ErrorAction Stop
D. Export-ModuleMember ActiveDirectory -ErrorAction Stop

22 A CSV file contains Name and Enabled columns. Which command imports the file and returns only rows where Enabled is the text value True?

File handling (CSV, JSON, XML) Medium
A. Import-Csv ./users.csv | Where-Object Enabled -eq 'True'
B. Import-Clixml ./users.csv | Where-Object Enabled -eq 'True'
C. Get-Content ./users.csv | Where-Object Enabled -eq 'True'
D. ConvertFrom-Csv ./users.csv | Select-Object Enabled -eq 'True'

23 A nested PowerShell object is being saved as JSON, but properties below the second level are replaced with abbreviated output. Which command best preserves six levels of nested data?

File handling (CSV, JSON, XML) Medium
A. $data | ConvertTo-Json -Depth 6 | Set-Content ./data.json
B. $data | Export-Csv -Depth 6 -Path ./data.json
C. $data | ConvertTo-Xml -Depth 6 | Set-Content ./data.json
D. $data | ConvertFrom-Json -Depth 6 | Set-Content ./data.json

24 An XML configuration file contains <server enabled="true">APP01</server> inside a <servers> element. After loading it with [xml]$config = Get-Content ./config.xml, which expression selects only enabled server nodes?

File handling (CSV, JSON, XML) Medium
A. $config.GetElementsByTagName('true')
B. $config.SelectSingleNode('//enabled/server')
C. $config.SelectNodes('//server[@enabled="true"]')
D. $config.SelectNodes('//server/enabled="true"')

25 A console menu accepts choices 1, 2, or Q. Which construct most clearly routes each valid choice to a separate action?

Menus Medium
A. switch ($choice) { '1' {}; '2' {}; 'Q' {} }
B. where ($choice) { '1' {}; '2' {}; 'Q' {} }
C. select ($choice) { '1' {}; '2' {}; 'Q' {} }
D. foreach ($choice) { '1' {}; '2' {}; 'Q' {} }

26 A script must request administrator credentials without displaying the password as plain text. Which command is most appropriate?

Prompts Medium
A. $credential = Get-Credential
B. $credential = Read-Host 'Credentials'
C. $credential = Write-Output $env:USERNAME
D. $credential = Get-Content ./password.txt

27 A script must restart the Print Spooler only when it is currently running. Which command sequence meets the requirement?

System tasks (services, processes, registry, tasks) Medium
A. Get-Service Spooler | Where-Object Status -eq 'Stopped' | Start-Process
B. Get-Service Spooler | Where-Object Status -eq 'Running' | Restart-Service
C. Get-Service Spooler | Select-Object Status -eq 'Running' | Stop-Service
D. Get-Process Spooler | Where-Object Status -eq 'Running' | Restart-Service

28 Which command creates or updates the LogLevel DWORD value under HKLM:\Software\Contoso?

System tasks (services, processes, registry, tasks) Medium
A. New-Item -Path 'HKLM:\Software\Contoso' -Name LogLevel -Value 2 -ItemType DWord
B. Add-Content -Path 'HKLM:\Software\Contoso' -Name LogLevel -Value 2 -Type DWord
C. Set-Content -Path 'HKLM:\Software\Contoso\LogLevel' -Value 2 -Encoding DWord
D. New-ItemProperty -Path 'HKLM:\Software\Contoso' -Name LogLevel -Value 2 -PropertyType DWord -Force

29 An administrator must disable all enabled users in the OU=Contractors,DC=example,DC=com organizational unit. Which pipeline performs this task?

Active Directory Medium
A. Get-ADUser -Filter * -SearchBase 'OU=Contractors,DC=example,DC=com' | Enable-ADAccount
B. Get-ADUser -Filter 'Enabled -eq $true' -SearchBase 'OU=Contractors,DC=example,DC=com' | Disable-ADAccount
C. Search-ADAccount -UsersOnly -AccountDisabled | Enable-ADAccount
D. Get-ADGroup -Filter 'Enabled -eq $true' -SearchBase 'OU=Contractors,DC=example,DC=com' | Disable-ADAccount

30 A command must retrieve the WinRM service from SERVER01 and SERVER02 without creating persistent sessions. Which command should be used?

PowerShell Remoting Medium
A. Invoke-Command -ComputerName SERVER01,SERVER02 -ScriptBlock { Get-Service WinRM }
B. Start-Job -ComputerName SERVER01,SERVER02 -ScriptBlock { Get-Service WinRM }
C. New-PSSession -ComputerName SERVER01,SERVER02 | Get-Service WinRM
D. Enter-PSSession -ComputerName SERVER01,SERVER02 -ScriptBlock { Get-Service WinRM }

31 A script runs several commands repeatedly on the same remote computer. Which approach avoids creating a new remote connection for every command?

PowerShell Remoting Medium
A. Create a CIM class and pass it with -Class
B. Create a background job and pass it with -Job
C. Create a transcript and pass it with -Transcript
D. Create a PSSession and pass it with -Session

32 A background job has completed, and its output must be collected while keeping the job available for later inspection. Which command should be used?

Jobs Medium
A. Wait-Job -Job $job -Keep
B. Get-Job -Job $job -Keep
C. Stop-Job -Job $job -Keep
D. Receive-Job -Job $job -Keep

33 A PowerShell script must run daily at 2:00 AM under the SYSTEM account. Which set of objects is required before calling Register-ScheduledTask?

Scheduled tasks Medium
A. A script block, a background job, and a service account
B. A task action, a daily trigger, and a SYSTEM principal
C. A process object, a timer event, and a user profile
D. A module manifest, a cron expression, and a credential file

34 An advanced function parameter named Environment must accept only Dev, Test, or Prod. Which declaration enforces this rule before the function body runs?

Advanced functions with validation Medium
A. [ValidateRange('Dev','Test','Prod')][string]$Environment
B. [ValidateScript('Dev','Test','Prod')][string]$Environment
C. [ValidateSet('Dev','Test','Prod')][string]$Environment
D. [ValidatePattern('Dev','Test','Prod')][string]$Environment

35 A function accepts server names from the pipeline by property name. Which parameter attribute enables objects with a ComputerName property to bind automatically?

Advanced functions with validation Medium
A. [Parameter(ValueFromRemainingArguments=$true)]
B. [Parameter(ValueFromPipelineByPropertyName=$true)]
C. [Parameter(ValueFromPipeline=$true)]
D. [Parameter(Mandatory=$true, Position=0)]

36 A Windows Forms button should run code when a user clicks it. Which statement correctly attaches a click event handler?

GUI scripting Medium
A. $button.Invoke_Click({ Start-Process notepad.exe })
B. $button.Set_Click({ Start-Process notepad.exe })
C. $button.Add_Click({ Start-Process notepad.exe })
D. $button.Get_Click({ Start-Process notepad.exe })

37 A user-provisioning script imports employee records from CSV. Which design best prevents duplicate Active Directory accounts when the script is run again?

Automation scripts for user management Medium
A. Check for each account before calling New-ADUser
B. Delete each organizational unit before importing users
C. Rename every existing account before creating users
D. Call New-ADUser twice and suppress all errors

38 A log-maintenance script must archive .log files older than 30 days. Which filter correctly identifies the files?

Log automation Medium
A. Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) }
B. Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-30) }
C. Where-Object { $_.CreationTime -eq (Get-Date).AddDays(30) }
D. Where-Object { $_.Length -lt (Get-Date).AddDays(-30) }

39 A monitoring script samples processor usage and must alert when the average PercentProcessorTime value exceeds 80. Which approach correctly calculates the average from $samples?

System monitoring Medium
A. ($samples | Compare-Object PercentProcessorTime -Average).Average
B. ($samples | Select-Object PercentProcessorTime -Average).Average
C. ($samples | Measure-Object PercentProcessorTime -Average).Average
D. ($samples | Group-Object PercentProcessorTime -Average).Average

40 A deployment script installs an MSI package silently and must wait for installation to finish before verifying the application. Which command is most appropriate?

Deployment tasks Medium
A. Start-Job msiexec.exe -ArgumentList '/i app.msi /qn' -Wait
B. Invoke-Item msiexec.exe -ArgumentList '/i app.msi /qn' -Wait
C. Start-Process msiexec.exe -ArgumentList '/i app.msi /qn' -Wait
D. Get-Process msiexec.exe -ArgumentList '/i app.msi /qn' -Wait

41 A script module defines Get-Report, New-Report, and Remove-Report. The .psm1 file calls Export-ModuleMember -Function Get-Report,New-Report, while the manifest specifies FunctionsToExport = @('Get-Report','Remove-Report'). Which functions are exported when the manifest is imported?

Modules Hard
A. Only Get-Report
B. All three functions
C. Get-Report and New-Report
D. Get-Report and Remove-Report

42 A server has versions 2.1.0 and 3.0.0 of Contoso.Tools installed. A script must load at least version 2.0.0 but must never load version 3.0.0 or later. Which command enforces that requirement?

Modules Hard
A. Import-Module Contoso.Tools -RequiredVersion 2.0.0 -MaximumVersion 2.9.9
B. Import-Module Contoso.Tools -MinimumVersion 2.0.0 -MaximumVersion 2.9.9
C. Import-Module Contoso.Tools -Version 2.0.0 -MaximumVersion 2.9.9
D. Import-Module Contoso.Tools -MinimumVersion 2.0.0 -Force

43 A PowerShell object contains nested properties five levels deep. After ConvertTo-Json and ConvertFrom-Json, properties below the default serialization depth are missing or represented incompletely. Which change directly addresses the problem?

File handling (CSV, JSON, XML) Hard
A. Call ConvertTo-Json -Compress before writing
B. Call ConvertTo-Json -Depth 6 before writing
C. Call Export-Csv -NoTypeInformation before writing
D. Call ConvertFrom-Json -AsHashtable after reading

44 An XML document uses <d:server> elements under the namespace URI urn:datacenter. Why does Select-Xml -Xml $xml -XPath '//server' return no nodes, and what is the correct approach?

File handling (CSV, JSON, XML) Hard
A. XPath must use //*:server in every PowerShell version
B. XPath must use a registered prefix mapped to urn:datacenter
C. XPath must remove the namespace from each XML element first
D. XPath must convert the document to JSON before querying

45 A console menu accepts choices 1 through 4. It must reject 2abc, whitespace, and out-of-range integers without throwing an exception. Which validation design is most robust?

Menus Hard
A. Cast with [int] and test whether the result is nonzero
B. Use -match '[1-4]' and accept any successful match
C. Use [int]::TryParse() and then test the parsed range
D. Compare the input lexically with the strings 1 and 4

46 An automation script must prompt interactively for credentials and pass them to Invoke-Command without storing the password as plain text in a variable. Which approach is appropriate?

Prompts Hard
A. Use Read-Host and assign the value directly to -Credential
B. Use $Host.UI.ReadLine() and convert it with ConvertFrom-Json
C. Use Get-Credential and pass the resulting PSCredential
D. Use Read-Host and place the result in a custom object

47 A 64-bit machine has different values in the 32-bit and 64-bit registry views. A 32-bit PowerShell process must reliably modify the 64-bit HKLM\Software view. Which technique is correct?

System tasks (services, processes, registry, tasks) Hard
A. Prefix the registry path with 64bit::HKLM\Software
B. Open LocalMachine with Registry64 through Microsoft.Win32.RegistryKey
C. Set $Env:PROCESSOR_ARCHITECTURE to AMD64 before writing
D. Write through HKLM:\Software after calling Set-Location

48 A script locates a process, waits several seconds, and then stops it. Process IDs can be reused during that interval. Which design best reduces the risk of stopping a different process?

System tasks (services, processes, registry, tasks) Hard
A. Query the process name again and stop every matching process
B. Retain only the process ID and call Stop-Process -Id later
C. Sort all processes by ID and stop the original numeric position
D. Retain the process object and verify its StartTime before stopping

49 A provisioning script may be rerun after partial failure. It must add a user to a group without failing when the user is already a member. Which pattern is most idempotent?

Active Directory Hard
A. Always call Add-ADGroupMember and suppress every error
B. Remove the user first and then call Add-ADGroupMember
C. Test current membership and add the user only when absent
D. Recreate the group before calling Add-ADGroupMember

50 A script must find enabled users under one organizational unit whose Department equals the value in $department, while allowing the domain controller to perform the filtering. Which approach is appropriate?

Active Directory Hard
A. Use Get-ADUser -Identity with -SearchScope Subtree and filter locally
B. Use Get-ADObject -IncludeDeletedObjects and compare distinguished names
C. Use Get-ADUser -Filter with -SearchBase and request needed properties
D. Use Get-ADUser -Filter * for the domain and apply two Where-Object calls

51 After Invoke-Command -ComputerName Server1 { Get-Service BITS }, the returned object is labeled Deserialized.System.ServiceProcess.ServiceController, and its service-control methods are unavailable. What explains this behavior?

PowerShell Remoting Hard
A. Get-Service returns method-free objects outside interactive sessions
B. The local session must import the remote Microsoft.PowerShell.Management module
C. The BITS service blocks methods when queried through WinRM
D. Remoting serializes object data, so instance methods are not preserved

52 From workstation A, an administrator remotes to server B. A command on B then attempts to access a protected file share on server C using the administrator's credentials and receives access denied. Which remoting issue is most likely?

PowerShell Remoting Hard
A. PowerShell remoting strips group memberships from all remote tokens
B. The second hop cannot delegate the user's credentials by default
C. WinRM supports commands but never permits access to UNC paths
D. The remote session always converts domain accounts to local accounts

53 A script calls Receive-Job $job once for an interim status display and later calls it again after completion, but the first batch of output is missing from the final collection. Which change preserves previously received output?

Jobs Hard
A. Use Get-Job $job -IncludeChildJob for the interim read
B. Use Wait-Job $job -Force before the interim read
C. Use Receive-Job $job -AutoRemoveJob for the interim read
D. Use Receive-Job $job -Keep for the interim read

54 A scheduled PowerShell task must run on a server after reboot even when no user is signed in. It requires elevated local privileges and must not depend on an interactive desktop. Which configuration best meets these requirements?

Scheduled tasks Hard
A. Run as the current user with an event trigger and interactive token
B. Run as LOCAL SERVICE with a logon trigger and limited privileges
C. Run as SYSTEM with RunLevel Highest and a startup trigger
D. Run as an administrator with Interactive logon and a boot delay

55 An advanced function accepts server names from the pipeline both by value and by property name. It should collect input in process and perform one batched API call after all pipeline input arrives. Where should the API call be placed?

Advanced functions with validation Hard
A. In dynamicparam, after validation attributes are evaluated
B. In begin, before pipeline values have been bound
C. In process, once for every bound pipeline object
D. In end, using values accumulated during process

56 A function parameter must accept only existing leaf files. The function also accepts pipeline input, and validation must occur during parameter binding. Which declaration is most suitable?

Advanced functions with validation Hard
A. [ValidatePattern('.*')][System.IO.FileInfo]$Path
B. [ValidateScript({ Test-Path $_ -PathType Leaf })][string]$Path
C. [ValidateRange(1,1)][string]$Path
D. [ValidateSet('Leaf')][string]$Path

57 A WPF PowerShell tool starts a long-running scan directly in a button click handler, causing the window to freeze. Which architecture keeps the interface responsive and updates controls safely?

GUI scripting Hard
A. Run the scan in another runspace and modify WPF controls directly from it
B. Run the scan in the click handler and call Start-Sleep between operations
C. Run the scan in another runspace and marshal updates through the UI dispatcher
D. Run the scan in the rendering event and call DoEvents after each result

58 A bulk user-creation script reads a CSV and may stop halfway because of a transient directory failure. Which design most safely supports rerunning the same file?

Automation scripts for user management Hard
A. Generate a new account name on every run and retain all duplicates
B. Derive stable identities, compare desired state, and update only differences
C. Skip every row after the first error and report only the final row
D. Delete every matching account before recreating the complete input set

59 A script polls a growing text log every minute. It must avoid rereading old lines and must also handle log rotation, where the replacement file can be smaller than the previous file. What state should it persist?

Log automation Hard
A. Only the number of lines observed during the previous poll
B. A file identity plus byte offset, resetting when identity or length changes
C. A hash of the final line without any file position information
D. Only the timestamp of the most recently parsed line

60 A monitoring script computes CPU utilization from a cumulative processor-time counter sampled at times and . On an -logical-processor system, which expression gives normalized utilization as a percentage?

System monitoring Hard
A.
B.
C.
D.