這是現在我的腳本:如何在PowerShell中將相同的變量寫入x次?
[int]$NumberOfProfiles = Read-Host "Enter the number of profiles You need"
$WhereToWrite = Read-Host "Enter the full path where You'd like to install the profiles"
$Source = Get-Location
$FolderName = "Fish"
$SourceDirectory = "$Source\$Foldername"
$Variable1 = "Plane"
$Variable2 = "Car"
...
$Variable100 = "Boat"
while ($NumberOfProfiles -gt 0) {
$DestinationDirectory = Join-Path $WhereToWrite "$Foldername$NumberOfProfiles"
$PrefsDirectory = "$DestinationDirectory\Data\profile\prefs.js"
$Changer = Get-Variable -Name "Variable$NumberOfProfiles" -ValueOnly
Copy-Item $SourceDirectory $DestinationDirectory -Recurse -Container
Write-Host "Made a new profile to" $DestinationDirectory
(Get-Content $PrefsDirectory) | %{$_.Replace("SomeInfo", "Changer")} | Set-Content $PrefsDirectory
$NumberOfProfiles--
}
我想實現的事情是,我會寫$變量1至五個第一複製文件夾等。
E.g.它看起來像這樣:在Fish1,Fish2,Fish3,Fish4,Fish5中的prefs.js中的「Plane」。 「Car」在Prefs.js中的Fish6,Fish7,Fish8,Fish9,Fish10等等。
請退後一步並描述實際問題正在努力解決,而不是你認爲的解決方案。你想通過這樣做來達到什麼目的? –
如果您必須使用100個變量,請使用[array](http://technet.microsoft.com/zh-cn/library/hh847882.aspx)。 – vonPryz