Hello,
Can someone help me with this? I typed in 2000, and it grabbed the correct CoreID (FMD354200000), but as you can see below, it added my computer name to a 1000 core ID. I want it to add it to the FMD354200000 CoreID
Branch Number,CoreID,Available
1000,FMD354100000,2UA51427CH
1000,FMD354100001,Yes
1000,FMD354100002,Yes
1000,FMD354100003,Yes
1000,FMD354100004,Yes
2000,FMD354200000,Yes
2000,FMD354200001,Yes
2000,FMD354200002,Yes
2000,FMD354200003,Yes
$Workstation = $env:COMPUTERNAME
$CoreIP = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\CORe\IP"
$CSV = '\\hqfs1\users\tantony\PowerShell\GetCoreID\CoreID.csv'
$ImportCSV = Import-Csv $CSV
$GetBranchNum = Read-Host "Enter branch number and press ENTER: "
if($ImportCSV | Where-Object {$_."Branch Number" -eq $GetBranchNum})
{
Write-Host -NoNewline "Branch number found in CSV file!`t" -ForegroundColor Green
if($ImportCSV | Where-Object {$_."Available" -eq "Yes".Trim() -eq "Y" -and $_."Branch Number".Trim() -eq $GetBranchNum})
{
Write-Host "$HowManyLeft Available Core ID found!" -ForegroundColor Green
$First = $ImportCSV | Where-Object {$_.'Branch Number'.Trim() -eq $GetBranchNum -and $_.Available.Trim() -eq "Yes"} | Select-Object -First 1
$AddCoreID = $First.CoreID
New-ItemProperty -path $CoreIP -name "TTable ID" -PropertyType String -Value $AddCoreID -Force | Select-Object "TTable ID" | Format-List
$lines = Get-Content -Path $CSV -Raw
$pattern = $First.Available
$regEx = New-Object -TypeName 'System.Text.RegularExpressions.Regex' -ArgumentList $pattern
$result = $regEx.Replace($lines, $Workstation, 1)
$result | Out-File -FilePath $CSV -Encoding ascii -Force
}
else
{
Write-Host "No Available Core ID found!" -ForegroundColor Red
}
}
else
{
Write-Warning "Branch number not found in CSV file!"
}