troubleshooting Question

Modify powershell script to rewrite data based on what it finds

Avatar of E=mc2
E=mc2Flag for Canada asked on
PowershellWindows 10Scripting Languages
9 Comments1 Solution107 ViewsLast Modified:
I would like to change this script so that when at position 100 if it sees the specific digits 078965 -
that it replaces 078965 without the leading 0 - so that the number is replaced without the 0...
It should just contain 78965

	$filename = 'c:\Temporary\Import1.csv',
	$newFile  = 'c:\Temporary\Import2.csv'
$content = Get-Content $filename

$outRecords = @()

foreach( $record in $content )
	$array = $record.Split( ',' )
	## entries in $array are zero-based
	if ($array.Length -lt 101) {
		$outRecords += $record
	} else {
	     if ($array[3] -eq '65-ABCDEF' ) {
		if ($array[99] -eq "") {
		      if ($array[98].Length -gt 5) {
			$array[99] = $array[98].substring($array[98].length-6,5)
	     $outRecords += $array -join ","
$outRecords | Out-File $newFile -Encoding ASCII

Open in new window

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros