The scenario i have is that, i have list of objects in the array for the most part each object in the array has the same character length (trxc-fa01-tc01,trxc-fa02-tc01) but then there are a few different ones such as (trxc-pvc05 and trxc-dtc01) so i am trying something very basic; pretty much with if else statement but having hard time to extract the character number [8] from my value.
When you post code or error messages or sample data or console output format it as code, please.
In the “Text” view you can use the code tags “PRE”, in the “Visual” view you can use the format template “Preformatted”. You can go back edit your post and fix the formatting - you don’t have to create a new one.
Thanks in advance.
Do you mean something like this?
$MyServers = @('trxc-fa06-tc01', 'trxc-fa05-tc01', 'trxc-fa04-tc01', 'trxc-fa03-tc01', 'trxc-pvc05', 'trxc-fa01-tc01', 'trxc-dtc01', 'trxc-sa01-tc01')
ForEach ($Server in $MyServers) {
if ($Server -like '*pvc05*') {
"$Server is in Cage1"
}
elseif ($Server -like '*dtc01*') {
"$Server is in Cage2"
}
else {
"$Server is in Cage $($Server.substring(8,1))"
}
}