Powershell retrieving a variable from a text file

前端 未结 3 1122
渐次进展
渐次进展 2021-02-01 05:08

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
         


        
3条回答
  •  有刺的猬
    2021-02-01 06:01

    Yes, read the file, split each line and assign the split result to the Name and Value parameters:

    Get-Content file.txt | Foreach-Object{
       $var = $_.Split('=')
       New-Variable -Name $var[0] -Value $var[1]
    }
    

提交回复
热议问题