Author Posts

January 1, 2012 at 12:00 am

by link12 at 2012-11-16 08:23:44

How can I trim/split the following

aa-computername-cc
aa-computer-name-cc

I basically want to trim the aa- and the -cc, but leave the computer name regardless if it has a "-" or not.

by ArtB0514 at 2012-11-16 09:12:48

Easy: takes two steps:
1. Split the name on "-"
2. Rejoin the name, skipping the first (id=0) and the last (id=count -1)

$Original = $ComputerName -Split "-"
$Final = (1..($Original.count – 2) | foreach {$Original[$_]}) -join "-"

by link12 at 2012-11-16 09:18:56

Worked like a charm. Can you briefly explain this line
$Final = (1..($Original.count – 2) | foreach {$Original[$_]}) -join "-"

Thanks

by link12 at 2012-11-16 09:23:28

I see your explaination above, nevermind. Thanks again