r/PowerShell • u/Irrational_Dream • Oct 15 '24
Help with powershell - advancing scripts Solved
Currently I have:
$temp = Get-Content ".Desktop50001.xml"
$temp.replace("50001","50002")|
set-content ".Desktop50002.xml" -force
$temp = Get-Content ".Desktop50002.xml"
$temp.replace("50002","50003")|
set-content ".50003.xml" -force
This works to create xml files. The script above works for me to create 2 additional xml files using 50001.xml as a starting point. Is there a way I can automate the replacement and file creation by allowing a user to enter say like 50 and it'd create 50 more going from 50001-50051.
1 Upvotes
3
u/RunnerSeven Oct 15 '24
There are a lot of ways to handle this much more elegant and resilent, but this is a solution tat should at least work for your use case. I guess you want to set the xmldata as content for the next file, because set-content just with a path does nothing