Last active
September 5, 2021 16:28
-
-
Save techthoughts2/bc0b1a038bd7bc99c6e9 to your computer and use it in GitHub Desktop.
String Manipulation
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
#replace | |
if($vDisk -contains " "){ | |
$vDisk = $vDisk -replace(" ",",") | |
} | |
#remove last character | |
$string.Substring(0,$string.Length-1) | |
#extract a specific string set from a long string | |
[regex]$r = "(?<=Vlan).*?(?= )" | |
$r.matches($nativeVLANString) | ` | |
ForEach-Object { | |
$nativeVLANStringFinal = $_.Value | |
} | |
#match airport code | |
if ($APC -match "^[A-Z]{3}$") { | |
#correct | |
} | |
#splitting a string up at a certain character | |
$split = $switch.display_name.split("[") | |
$switchname = $split[0] + ".$region" | |
#another example | |
$config.Hostname = ($corePull.result.name.split("."))[0] | |
#reduce string to a certain length | |
if($compName.length -gt 6){ | |
$compName = $compName.substring(0,6) | |
} | |
#get all the object things and put them into a list serparated by commas | |
$secondaryDisks = $t.'VM-Object'.DataDisks | |
($secondaryDisks | Select-Object -ExpandProperty DiskSize) -join "," | |
# get last character of a string | |
$a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
$a.substring($a.length - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment