Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Out-File to CSV holds on to information

$
0
0

Hey everyone,

Here is my issue. I have a Powershell v2.0 application that I created using Sapien Powershell Studios, that sends information to a CSV. Then I have another script(batch) that reads the CSV, but does not find any information until I physically open the CSV file, save, and close the file. The information does indeed go to the CSV I have confirmed that. Does anyone have any ideas? I have posted my code below.

Powershell

Out-File -Append -FilePath $namesFile -InputObject @(" ") Out-File -Append -FilePath $namesFile -InputObject @($tfPO.Text + "," + $tfLoc.Text + ", Qty: " + $qty.Text + ", ," + $username) Out-File -Append -FilePath $namesFile -InputObject @(" ")

for ([int]$i = 0; $i -lt $datagrid.RowCount; $i++) { Out-File -Append -FilePath $namesFile -InputObject @($datagrid.Rows[$i].Cells['Serial'].Value + "," + $datagrid.Rows[$i].Cells['Hostname'].Value + "," + $cbType.SelectedItem.ToString() + "," + $cbImage.SelectedItem.ToString()) }

Batch(I know this works fine)

FOR /F "delims=, tokens=2,3,4" %%A in ('type y:\names.csv ^| FIND /i "%Serial%"') do Set Model=%%C

I have also tried to utilize the Type command by itself thru command prompt. I am also looking for a work around that will open the CSV, save and close or similar. Here are the ones that I have tried that have not worked.

Get-Content

$file = Get-ChildItem -LiteralPath $namesfile
	$stream = $file.OpenRead()
	$stream.Close()

Any help would be awesome. Thanks!

 



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>