PowerShell keep text formatting when reading in a file

前端 未结 3 1678
花落未央
花落未央 2021-01-11 10:31

I believe this is a simple question, but I can\'t wrap my head around it. I want to do diagnostic commands in command shell on Windows. Like this:

   $cmd =          


        
3条回答
  •  滥情空心
    2021-01-11 11:00

    To read all the data as a single string with the line breaks embedded

    $file = 'c:\testfiles\testfile.txt'
    
    (IPconfig /all) > $file
    
    [IO.File]::ReadAllText($file)
    

    If you have V3, they added the -Raw parameter that will accomplish the same thing:

    Get-Content $file -Raw
    

提交回复
热议问题