Is there a way to read a text file D:\SetCredentials.txt which contains credentials and set the values in variables so that I can use those variables in other script.
File looks like this:
serv|16762646t|6879i0i2|9878p989868
I want to set the value of a variable in my script below is the code we use in batch script but i want it in powershell script
For /F "tokens=1-4 delims=|" %%A in (SetCredentials.txt) do (
set username=%%A
set password=%%B
set servername=%%C
set key=%%D
Below is something i wrote, it is just reads and splits the text file -
$credInFile = Get-Content -path "D:\SetCredentials.txt"
$credInFileSplit = credInFile.Split("|")
foreach($i in $credInFileSplit){
echo $i
}
$credInFileSplit = $credInFile.Split("|")then look at each element of$credInFileSplite.g.$credInFileSplit[0],$credInFileSplit[1]etc$foo, $bar, $baz = 'foo|bar|baz'.Split('|')Import-Csv -Path 'X:\yourfile.txt' -Header 'Server','Password','UserName','Key' -Delimiter '|'. Since the fields are unclear to me, that header order may be wrong, only you can tell as it is now..