Created
July 23, 2021 20:56
-
-
Save TaylorTWBrown/d5da897d1c2c783f15e566ffc433b235 to your computer and use it in GitHub Desktop.
Sitecore PS Assessment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: Sitecore PS Assessment | |
# Author: Taylor Brown | |
# Date: July 23, 2020 | |
# Provided array | |
$buildFiles=@("file.json","f.rtmp","file.exe","file1.json","f.exe","1.tmp","f.json","demo.exe") | |
# Task 1 - List relevant build files. Filter and print json/exe files from array. | |
function Get-BuildFiles { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory)] | |
[array]$BuildFiles | |
) | |
$result = @() | |
foreach ($i in $BuildFiles) { | |
if($i -like "*.exe" -Or $i -like "*.json") { | |
$result += $i | |
} | |
} | |
return $result | |
} | |
# Task 2 - Match exe and json files. | |
function Get-BuildFilePairs { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory)] | |
[array]$BuildFiles | |
) | |
$result = @() | |
$exe = @() | |
foreach ($i in $BuildFiles) { | |
if($i -like "*.exe") { | |
$exe += $i | |
} | |
} | |
foreach ($l in $exe) { | |
$json = $l.Substring(0,$l.Length-4) + ".json" | |
foreach ($n in $BuildFiles) { | |
if($n -like $json) { | |
$pair = [PSCustomObject]@{ | |
json = $n | |
exe = $l | |
} | |
$result += $pair | |
} | |
} | |
} | |
return $result | |
} | |
Write-Output "Build files (exe and json files):`n" | |
Get-BuildFiles -BuildFiles $buildFiles | |
Write-Output "`n`n`nBuild files (json and exe pairs):" | |
$filepairs = Get-BuildFilePairs -BuildFiles $buildFiles | |
$filepairs | fl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment