Import-Csv .\employees.csv | Where-Object $_.YearsOfExperience -ge 2 | Sort-Object Salary -Descending | Select-Object -First 3 | Group-Object Department | Select-Object @N="Department";E=$_.Name, @N="AverageSalary";E= [math]::Round(($_.Group | Sort-Object Department | Format-Table -AutoSize
This script reads an array of integers (potentially from standard input), processes each element, and returns the result in ascending order.
A common task is to read an array of integers, perform an operation (like squaring them), sorting the array, and then outputting the result. This tests your use of the pipeline, object properties, and cmdlets. powershell 3 cmdlets hackerrank solution
New-Item -Path $sourcePath -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null
Below is a breakdown of how to solve tasks related to these foundational cmdlets. 1. Identify Available Commands ( Get-Command ) Import-Csv
To see only concrete usage examples, use the -Examples parameter:
$currentDate = Get-Date $formattedDate = $currentDate.ToString("yyyy-MM-dd") New-Item -Path "C:\Logs\log-$formattedDate.txt" -ItemType File Use code with caution. This report details the solution strategy for the
This report details the solution strategy for the challenge commonly found on HackerRank. The objective of this challenge is to assess the candidate's ability to read specific inputs, process arithmetic operations, and format the output using standard PowerShell command-lets (cmdlets).
: This is the PowerShell operator for "Greater Than." (Do not use > as it is reserved for text redirection).
). The pipeline allows the output of one cmdlet to be used as the input for another, enabling developers to perform complex operations in a single line of code. For instance, a solution involving finding specific files and calculating their hashes can be achieved by piping Get-ChildItem Get-FileHash
Here are some example use cases: