Skip to content

Instantly share code, notes, and snippets.

@brianbunke brianbunke/NewSplit.ps1

Last active Nov 12, 2015
What would you like to do?
2015-11 Scripting Games Puzzle
# Ideally this is [string[]]
# Copying from old: Split up names by commas, trim the ends, output to screen
$VMNameStr -split "," | %{$_.trim()}
# Not [string[]], so will only accept one value
# Don't define an empty array up top if you're not appending into it below
# If there's a comma, we need to split into multiple names
if($VMNameStr.indexof(",") -gt 0) {
# $Trace only intended as debugging, can be ignored
$Trace="Found Comma..."
# Split up the names on commas, then trim up the ends
# This is the useful line, the other stuff makes it worse
$VMs=$VMNameStr -split "," | %{$_.trim()}
# Still ignoring here because it's not called below
$trace+="Length = $($VMs.length)"
$trace+=$VMs -is [array]
# This is the long way of coding ForEach
for($i=0;$i -lt $VMs.length;$i++){
# Continuation of ForEach logic
if($VMs[$i] -gt ""){
# Create $vmname0, value is the string name of current VM
# More variables that will not be called later
set-variable -Name ("vmname" + $i) -value $VMs[$i]
# Append the current VM name into $VMNames
# VMNameStr --> $VMName0 --> $VMNames
# Show your triumphant split of names by comma
# Format varies depending on your input into the parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.