如何使用PowerShell将文件中的数据从文件读入变量? 我ListOfFileNames.txt具有都是这样的一个数组:如何使用Powershell将数组读入特定文件中的变量以使用Powershell中的变量
#Begin ArrayOneList:
Filename4.txt
FilenameD.png
myone.exe
#Begin ArrayTwo:
myFile2.txt
Filename1.gif
#Begin ArrayNextOne:
speficifFile.doc
ExcelFile.xls
File3.png
AnotherFile.png
logFile.log
现在我想读入数组变量和PowerShell中与他们合作:
$ArrayOneList = Get-Content C:\Scripts\ListOfFileNames.txt
foreach($File in $ArrayOneList)
{
$Weekday = $File.LastWriteTime.DayOfWeek
$Destination = "D:\Test\$Weekday"
Copy-Item $File.FullName -Destination $Destination -Recurse
}
$ArrayTwo = Get-Content C:\Scripts\ListOfFileNames.txt
foreach($File in $ArrayTwo)
{
$Weekday = $File.LastWriteTime.DayOfWeek
$Destination = "E:\Dir\Dest"
Copy-Item $File.FullName -Destination $Destination -Recurse
}
$ArrayNextOne= Get-Content C:\Scripts\ListOfFileNames.txt
foreach($File in $ArrayNextOne)
{
$Weekday = $File.LastWriteTime.DayOfWeek
$Destination = "E:\Dir\SpecificDirectory"
Copy-Item $File.FullName -Destination $Destination -Recurse
}
我怎样才能阅读所有的数组从一个文件到变量?
难道我已经像这样调用它?:Powershell.exe -File“MyScriptPath-ps1”“ArrayOneList,ArrayTwo,ArrayNextOne”如何在不从外部调用数组的情况下使用这些参数,而只能从脚本内部调用这些参数? – Mailo
@Mailo:是的,你必须这样打电话。我给出的链接,你可以看到一些例子 –
没有例子说明如何在不从外部调用参数的情况下使用它。我只想调用poweeshellfile.ps1 withouth参数 – Mailo