I am fairly new to scripting so this may be a little vague or poorly worded. I also cut some stuff out, it is irrelevant, just names, but this is for someone else so in case they don't want it out there better safe than sorry. ANYWAY
I have a script to run a simple test against my system using another .exe that outputs a CSV file of the result when it is finished. I have it using a stream reader to read the output from the CSV file when I run it and erase the CSV it is running from at the end of the test. I am trying to tweak it to create a new file when a test is run that is titled "date-time.txt" and output that specific test into the time-stamped .txt file
Here is what I have so far, I am not sure if it is easier to piggyback off this code or make a separate function.
code to stream read tests and format
I have tried the following code someone suggested:
enter code here $FileName = (Get-Date -Format "yyMMdd-HHmmss") + ".txt" $File = New-Item -Type File -Path "." -Name $FileName $stream_reader = New-Object System.IO.StreamReader{$File.FullName} This creates the file but I cannot figure out where I should put it in my code and the proper way to get the content of the audit.csv into the new file and not disrupt the test.
Invoke-Expression(iex) should generally be avoided; definitely don't use it to invoke an external program or PowerShell script.New-Object SomeType(arg1, ...), useNew-Object SomeType [-ArgumentList] arg1, ...- PowerShell cmdlets, scripts and functions are invoked like shell commands, not like methods. That is, no parentheses around the argument list, and whitespace-separated arguments (,constructs an array as a single argument, as needed for-ArgumentList). However, method syntax is required if you use the PSv5+[SomeType]::new()constructor-call method. See this answerNew-Itemcreates a new file, whereas a[System.IO.StreamReader]instance is used for reading an existing file.