Hi all,
I have the below code to get the alarm de finitions that are enabled and I want to split the name/string from the second empty space until the end:
Get-AlarmDefinition | where-Object {$_.Enabled -eq 'True'} | Select-Object name,
@{N="Short Name";E={ $_.Name.Split('')[2]}} |
Export-Csv $outfile -NoTypeInformation -UseCulture
The alarms are for example:
Type:3 Team:Ops Virtual machine reboot or shut down (IP:192.168.0.1)
but I'm getting just:
Virtual
How can I split from the second empty space until the end of the string to get it like:
Virtual machine reboot or shut down (IP:192.168.0.1)
Thanks.
Try like this
Select-Object name,
@{N="Short Name";E={
$d1,$d2,$t = $_.Name.split(' ')
$t -join ' '}} |
Export-Csv $outfile -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
Select-Object name,
@{N="Short Name";E={
$d1,$d2,$t = $_.Name.split(' ')
$t -join ' '}} |
Export-Csv $outfile -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
One altenative is to split the string into 3 substrings:
$_.Name.Split('',3)[2]
André
I suspect you need to split on a blank, not an empty string
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD a.p.
Thanks guys both of them worked perfectly, do you know of any good video or lecture that covers this "split" topic in depth?
Ed Wilson did a good intro on the split method, see Using the Split Method in PowerShell
And if you want to see all the possibilities, have a look at the .NET Split method documentation.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference