Hi,
I am trying to access the array d1 or d2 outside foreach or for loop and all I get is the null array. I checked online regarding functions etc. but not sure how exactly to access the array values outside the for loop or for each loop. The array elements are displayed correctly when called inside the loop but nothing if called outside the loop. Below is the code:
=============
$Path = "C:\Scripting\text3"
$Path1 = Get-Content $Path
$Text = "Accounting-Input-Octets:"
$Text2 = "Accounting-Output-Octets:"
$Text3 = "Rating-Group:"
$Text4 = "Subscription-Id-Data:"
$Text5 = "Event-Timestamp:"
$Text6 = "Time-First-Usage:"
$Text7 = "Time-Last-Usage:"
$Text8 = "AF-Charging-Identifier:"
$Text9 = "PS-Information:"
$Text10 = "Stop-Time:"
$d1 = @()
$b = @()|Format-table -autosize
$mdn = $Path1 | Select-String -Pattern "Subscription-Id-Data:"
write-output $mdn[0,1,2,3,4,5]
write-output $Path1[0]
ForEach ($p in $Path1) {
if ($p -eq $mdn[0])
{ $c = $p; write-output "value of c is" $c }
if ($c -eq $mdn[0])
{
$d1 = ($p | Select-String -Pattern "Accounting-Input-Octets:") -replace 'Accounting-Input-Octets:',' '
}
# write-output $sum1
if ($p -eq $mdn[1])
{ $c = $p; write-output "value of c is" $c }
if ($c -eq $mdn[1])
{
$d2 = ($p | Select-String -Pattern "Accounting-Input-Octets:") -replace 'Accounting-Input-Octets:',' '
}
if ($p -eq $mdn[2])
{ $c = $p; write-output "value of c is" $c }
if ($c -eq $mdn[2])
{
$d3 = ($p | Select-String -Pattern "Accounting-Input-Octets:") -replace 'Accounting-Input-Octets:',' '
}
write-output $d1
write-output $d2
write-output $d3
}
write-output $e1
# write-output $array.$d1
# write-output Sum($d1)