Variable Creation

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of random commandline random commandline 5 months, 3 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #37179
    Profile photo of Narayan Gupta
    Narayan Gupta
    Participant

    Hi Mates,

    I need one quick help with a scenario..

    I have 2 files named ABC123.txt and ABC456.txt. I want powershell to read the file names and pick the 3 integers from them and store into variables. So the Variables should be

    $X="123"
    $Y="456"

    Many thanks in advance 🙂

    Cheers,
    Narayan

    #37182
    Profile photo of Narayan Gupta
    Narayan Gupta
    Participant

    $data =Get-ChildItem .\abc123.conf
    $D=$data.name.substring(5,3)
    $V1=$D.GetValue(0)
    $V1=$D.GetValue(1)

    #37191
    Profile photo of random commandline
    random commandline
    Participant
    $files = Get-ChildItem -Path .\ABC123.txt,ABC456.txt
    # Create variables
    switch -Regex ($files){
    '\d+' {New-Variable -Name $_.BaseName -Value $Matches[0] -Verbose}
    }
    
    #VERBOSE: Performing the operation "New variable" on target "Name: abc456 Value: 456".
    #VERBOSE: Performing the operation "New variable" on target "Name: abc123 Value: 123".
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.