Skip to content

Instantly share code, notes, and snippets.

@TaylorTWBrown
Created July 23, 2021 20:56
Show Gist options
  • Save TaylorTWBrown/d5da897d1c2c783f15e566ffc433b235 to your computer and use it in GitHub Desktop.
Save TaylorTWBrown/d5da897d1c2c783f15e566ffc433b235 to your computer and use it in GitHub Desktop.
Sitecore PS Assessment
# 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