logo
down
shadow

Substring in powershell


Substring in powershell

Content Index :

Substring in powershell
Tag : powershell , By : Gerhard Miller
Date : January 12 2021, 08:33 AM

around this issue I usually use: , You can simplify this:
(Get-Item -Path $File).Extension
PS C:\> $File = 'C:\Temp\Fold\File.exe'
PS C:\> $File -match '(?<Extension>\.\w+$)'
True
PS C:\> $Matches.Extension
.exe
PS C:\> ($File -split '\.')[-1]
exe

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Getting substring from string with powershell


Tag : powershell , By : dbarbot
Date : March 29 2020, 07:55 AM
I hope this helps . I want to extract verssion number from MFC *.rc file. It looks like: , There's a [Version] type you can use for that:
$text = 'VALUE "FileVersion", "1.22.333.4444\0"'
$version = [version]($text -replace '^.+?([0-9.]+)\\.+','$1')
$version


Major  Minor  Build  Revision
-----  -----  -----  --------
1      22     333    4444    
$version.ToString()

1.22.333.4444

'{0}.{1}' -f $version.major,$version.minor

1.22

powershell substring of substring


Tag : powershell , By : Marie Ramos
Date : March 29 2020, 07:55 AM
wish help you to fix your issue couple of ways you could do this:
first- specify what you dont want
Get-Content -Path textfile | 
  Where-Object {$_ -NotLike 'this is a*'} | 
    Set-Content file2.txt
Get-Content -Path textfile | 
  Where-Object {$_ -Like 'second*' -or $_ -like 'third*'}  | 
    Set-Content file2.txt
Get-Content -Path textfile | 
  Where-Object {$_ -match '^(second|third)'}   | 
    Set-Content file2.txt

How to extract substring in Powershell


Tag : powershell , By : shehan
Date : March 29 2020, 07:55 AM
this one helps. this uses a named capture group and a lazy capture that stops before the 1st \ after \companies. in order to get the wanted part of the text. it is fragile in that it depends on a very specific pattern, but your two samples fit that pattern. [grin]
$InStuff = @'
DEVSRC\2019\REL\19-REL-07\Sales\CustomerFlow\company.Presales.CustomerFlow.Web.UI.CustomerMobile\App_Themes\Bundles
DEVSRC\2019\REL\19-REL-07\Policy\XPM\Insured\company.PolicyManagement.WebSite.Customer.Components\content
'@ -split [System.Environment]::NewLine

foreach ($IS_Item in $InStuff)
    {
    $Null = $IS_Item.Replace('DEVSRC\2019\REL\19-REL-07\', '') -match '(?<Wanted>.+\\company.+?)\\.+'

    $Matches.Wanted
    }
Sales\CustomerFlow\company.Presales.CustomerFlow.Web.UI.CustomerMobile
Policy\XPM\Insured\company.PolicyManagement.WebSite.Customer.Components

get ALL specified substring in powershell


Tag : regex , By : nickthecook
Date : March 29 2020, 07:55 AM
around this issue
Since your first