About 253,000 results
Open links in new tab
  1. Read file line by line in PowerShell - Stack Overflow

    Nov 4, 2015 · I want to read a file line by line in PowerShell. Specifically, I want to loop through the file, store each line in a variable in the loop, and do some processing on the line. I know the Bash equi...

  2. Powershell retrieving a variable from a text file - Stack Overflow

    Is there a way to read a text file C:\\test.txt and retrieve a particular value? ie file looks like this: serverName=serv8496 midasServer=serv8194 I want to set the value of a variable in my scrip...

  3. powershell - How to load or read an XML file using ConvertTo-Xml …

    Dec 12, 2020 · Not reading a file with the correct encoding will result in mangled data or errors except in very basic or very lucky cases. The often-seen method of using Get-Content and casting the resulting string to [xml] is the wrong way of dealing with XML for this very reason.

  4. How to process a file in PowerShell line-by-line as a stream

    To minimize buffering avoid assigning the result of Get-Content to a variable as that will load the entire file into memory. By default, in a pipleline, Get-Content processes the file one line at a time. As long as you aren't accumulating the results or using a cmdlet which internally accumulates (like Sort-Object and Group-Object) then the memory hit shouldn't be too bad. Foreach-Object ...

  5. Read UTF-8 files correctly with PowerShell - Stack Overflow

    Apr 2, 2014 · The same PowerShell script reads the file, adds some more content and writes it all as UTF-8 back to the same file This can be iterated many times With Get-Content and Out-File -Encoding UTF8 I have problems reading it correctly.

  6. How to read a line from a file in PowerShell - Stack Overflow

    Dec 13, 2016 · I want to read each line and ping for the first host (Host1), then the second host (Host2) and then the third host (Host3). While pinging each host name, I need to check the ping response IP address for that host and match it back with the IP …

  7. powershell - Store Entire Text File Contents in Variable - Stack …

    Jun 13, 2024 · I'd like to use PowerShell to store the entire contents of a text file (including the trailing blank line that may or may not exist) in a variable. I'd also like to know the total number of lines in the text file.

  8. powershell - Get last n lines or bytes of a huge file in Windows …

    Apr 9, 2016 · If you have PowerShell 3 or higher, you can use the -Tail parameter for Get-Content to get the last n lines. Get-content -tail 5 PATH_TO_FILE; On a 34MB text file on my local SSD, this returned in 1 millisecond vs. 8.5 seconds for get-content |select -last 5

  9. powershell - How to load a JSON file and convert it to an object of …

    Mar 8, 2016 · Now I want to use ConvertFrom-Json to load the JSON file to memory and covert the output of the command to a FooObject object, and then use the new object in a cmdlet Set-Bar which only accept FooObject as the parameter type.

  10. How can I replace every occurrence of a String in a file with ...

    Jun 17, 2013 · Using PowerShell, I want to replace all exact occurrences of [MYID] in a given file with MyValue. What is the easiest way to do so?

Refresh