How to replace string with variable in PowerShell? -
i have code struggling little bit with:
$numberofprofiles = read-host "enter number of profiles" $directory = "c:\users\apple\folder(1..howmuchprofilescreated\text.txt" variable1 = "plane" variable2 = "yacht" variable100 = "bike" while ($numberofprofiles -gt 0) { (get-content $directory) | %{$_.replace("car", "don'tknowwhattoputhere")} | set-content $directory $numberofprofiles--
the text.txt file same in folders , contains same string wish alter (e.g. "car" in case), new string should come variables have declared before and(or may improve utilize array?)
e.g. $numberofprofiles = 10 , create 10 folders same text.txt , need "car" replaced variable1 in folder1, variable2 in folder2 , on.
if can build name of variable, can utilize get-variable
. illustration illustrate:
$variable1 = "bike" $folderid = 1 get-variable -name "variable$folderid" -valueonly
will result in
bike
powershell
No comments:
Post a Comment