Powershell einzelne Zeile aus Text Datei einlesen
Text Datei sieh so aus: $var = "c:\tools\Variabeln.txt"
"C:\Tools"
"C:\Users\Admin\Documents"
"C:\Users\Admin\Downloads"
"Y:\_Backup_Test"
"C:\temp\PS_DIR.txt"
Ich muss jede einzelne Zeile in eine Variabel einlesen.
$Quelle = "C:\Tools"
$Quelle1 = "C:\Users\Admin\Documents"
.
.
.
.
Versucht habe ich es mit:
$quelle = Get-Content -Path $var -TotalCount 1
$quelle1 = Get-Content -Path $var -TotalCount 2
write-host $quelle
write-host $quelle1
Da kommt dann das:
"C:\Tools"
"C:\Tools" "C:\Users\Admin\Documents"
raus.
Dann habe es so Versucht:
$input = Get-Content "c:\tools\Variabeln.txt"
foreach ($temp in $input)
{
$Inhalttrennen = $temp.Split("|")
$Quelle = $Inhalttrennen[0]
$Quelle1 = $Inhalttrennen[1]
$Quelle2 = $Inhalttrennen[2]
}
Da bekomme ich aber auch nicht die Werte raus die ich brauche.
Was muss ich machen das ich jede Zeile einzeln einlesen kann und dann gleich in die Richtige Var. einlesen kann?
VG
"C:\Tools"
"C:\Users\Admin\Documents"
"C:\Users\Admin\Downloads"
"Y:\_Backup_Test"
"C:\temp\PS_DIR.txt"
Ich muss jede einzelne Zeile in eine Variabel einlesen.
$Quelle = "C:\Tools"
$Quelle1 = "C:\Users\Admin\Documents"
.
.
.
.
Versucht habe ich es mit:
$quelle = Get-Content -Path $var -TotalCount 1
$quelle1 = Get-Content -Path $var -TotalCount 2
write-host $quelle
write-host $quelle1
Da kommt dann das:
"C:\Tools"
"C:\Tools" "C:\Users\Admin\Documents"
raus.
Dann habe es so Versucht:
$input = Get-Content "c:\tools\Variabeln.txt"
foreach ($temp in $input)
{
$Inhalttrennen = $temp.Split("|")
$Quelle = $Inhalttrennen[0]
$Quelle1 = $Inhalttrennen[1]
$Quelle2 = $Inhalttrennen[2]
}
Da bekomme ich aber auch nicht die Werte raus die ich brauche.
Was muss ich machen das ich jede Zeile einzeln einlesen kann und dann gleich in die Richtige Var. einlesen kann?
VG
Please also mark the comments that contributed to the solution of the article
Content-Key: 34266697871
Url: https://administrator.de/contentid/34266697871
Printed on: April 28, 2024 at 08:04 o'clock
3 Comments
Latest comment
Hallo.
tio.run
Katrin
Was muss ich machen das ich jede Zeile einzeln einlesen kann und dann gleich in die Richtige Var. einlesen kann?
Ganz einfach, das Ergebnis von Get-Content ist per Default eh ein String-Array, ergo kannst du jede Zeile mit Ihrem Index ansprechen$lines = Get-Content "c:\tools\Variabeln.txt"
$lines[0]
$lines[1]
$lines[2]
# ...
Katrin