Created
August 11, 2023 12:50
-
-
Save twobob/f4eed5daafa6af5bb232a98e9060775d to your computer and use it in GitHub Desktop.
creates a set of links with the values sample_nn_nn_nn.ps1 and sample_nn_nn.ps1 and sample_nn.ps1 where nn is every variant of the model numbers
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
param( | |
[switch]$dryrun = $false | |
) | |
$basePath = ".\sample_" | |
$targetPath = ".\sample.ps1" | |
# List of model numbers | |
$modelNumbers = '15', '42', '110' | |
# Iterate through all subsets of the model numbers | |
$combinations = [System.Collections.ArrayList]@() | |
$range = 1..([math]::Pow(2, $modelNumbers.Length) - 1) | |
$range | ForEach-Object { | |
$binary = [Convert]::ToString($_, 2).PadLeft($modelNumbers.Length, '0') | |
$combination = -join (0..($binary.Length - 1) | Where-Object { $binary.Substring($_, 1) -eq '1' } | ForEach-Object { $modelNumbers[$_] + "_" }) | |
$combination = $combination.TrimEnd("_") | |
$combinations.Add($combination) | |
} | |
# Create hard links for each combination | |
$combinations | ForEach-Object { | |
$hardLinkPath = $basePath + $_ + ".ps1" | |
if ($dryrun) { | |
Write-Host "Dry run: Would create hard link: $hardLinkPath" | |
} else { | |
if (-Not (Test-Path $hardLinkPath)) { | |
New-Item -ItemType HardLink -Path $hardLinkPath -Target $targetPath | |
Write-Host "Created hard link: $hardLinkPath" | |
} else { | |
Write-Host "Hard link already exists: $hardLinkPath" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment