Variable Creation

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 :slight_smile:

Cheers,
Narayan

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

$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".