Forum Discussion
Get the output of a command into a string
- Sep 23, 2021
Hello, write the output of first step to external file, examplae text.csv
with these file you can read each line and add the variable with content of the file.Get-Content .\test.csv | ForEach-Object { if($_ -match $temp){ #I add write-output to show the content of the file test.csv[n] Write-Output $_ } }
Hello, write the output of first step to external file, examplae text.csv
with these file you can read each line and add the variable with content of the file.
Get-Content .\test.csv | ForEach-Object {
if($_ -match $temp){
#I add write-output to show the content of the file test.csv[n]
Write-Output $_
}
}Hi, thanks, that is great!
So now I got the output in a text file, with this structure:
SamAccountName
--------------
User1
User2
User3
So I can make the next step I need to clean up the first 2 lines of the output text file, so I can have the needed values to compare only.
I've searched and tried to use this command:
Get-Content $Path | Select-Object -Skip 3 | Set-Content $Path
If I run this on the file without the Set-Content $Path it works just fine, but when goes to write to the output file, I always got the error:
Set-Content : The process cannot access the file 'C:\Temp\teste.txt' because it is being used by another process.
I've read about it, and some say it's related to having Powershell ISE opened, but I close it and it's just the same.
Any tips on this?
Thanks