PowerShell (Coding) Assessment Test

PowerShell (Coding)

 45 Minutes
 3 Questions


PowerShell Coding Assessment
This PowerShell coding assessment evaluates a candidate's proficiency in PowerShell scripting and automation.
The test includes a variety of coding challenges that simulate real-world scenarios and tasks commonly encountered by system administrators, DevOps engineers, and IT professionals.

Key Areas Covered:
- Conditional Logic and Control Structures: Candidates will demonstrate their ability to use PowerShell's conditional operators (-or, -and, if-else) to implement complex decision-making logic.
- File and Content Manipulation: Challenges will assess how candidates read, manipulate, and process file content, such as identifying patterns, counting occurrences, and generating reports.
- String and Data Handling: Proficiency in working with strings, arrays, and data structures to transform and analyze information.
- Scripting Automation: Scenarios that require automating repetitive tasks, such as file management, network configurations, and system monitoring.
- Basic Error Handling: Ensuring candidates can handle exceptions and errors gracefully in their scripts.


Example Question:

Coding
Task: Find the largest file in a given path and return the file size in bytes.

Write a PowerShell script that accepts a directory path as input and returns the size of the largest file in that directory. The file size should be returned in bytes. If there are no files in the directory, the script should return 0.

Requirements:

The script should handle both absolute and relative paths.
If the provided path is invalid or does not exist, the script should return 0.
The size of the largest file should be returned in bytes.

Example Input:

Get-LargestFileSize -Path $filePath
Assuming the following files are in the directory

productA.jar 1293 bytes
productB.jar 11003 bytes
productC.jar 31003 bytes

The function should return the following number of bytes:

31003

The script should return the size of the largest file in bytes or 0 if no files are found or if the directory does not exist.