我是 powershell 新手,我需要一些帮助。下面是我编写的用于在文件夹中查找 excel 文件的脚本。excel 工作表中的文件将与同一台机器上另一个文件夹的内容进行比较。位置是:“C:\MKS_DEV\”,生成的匹配文件将被压缩并放在脚本中所示的另一个位置。这些脚本将由不同机器上的其他人使用,因此两个文件夹的位置在不同机器上可能不同。
我想为两个文件夹的位置编写一个参数或使用参数,这样我就不必一直指定位置,我必须运行脚本并且无法弄清楚如何实现它。
脚本完美运行,但我只需要将参数/参数合并到其中。任何帮助将不胜感激。
谢谢。
这是代码:
# Creating an object for the Excel COM addin
$ExcelObject = New-Object -ComObject Excel.Application
# Opening the Workbook
$ExcelWorkbook = $ExcelObject.Workbooks.Open("C:\Eric_Source\Test.xls")
# Opening the Worksheet by using the index (1 for the first worksheet)
$ExcelWorksheet = $ExcelWorkbook.Worksheets.Item(1)
# The folder where the files will be copied/The folder which will be zipped
# later
$a = Get-Date
$targetfolder = "C:\"+$a.Day+$a.Month+$a.Year+$a.Hour+$a.Minute+$a.Second
# Check if the folder already exists. Command Test-Path $targetfolder returns
# true or false.
if(Test-Path $targetfolder)
{
# delete the folder if it already exists. The following command deletes a
# particular directory
Remove-Item $targetfolder -Force -Recurse -ErrorAction SilentlyContinue
}
# The following command is used to create a particular directory
New-Item -ItemType directory -Path $targetfolder
# Declaration of variables, COlumn value = 6 for Column F
$row = 1
$col = 6
# Read a value from the worksheet with the following command
$filename = $ExcelWorksheet.Cells.Item($row,$col).Value2
$filename
# change the folder value below to specify the folder where the powershell
# needs to search for the filename that it reads from excel file.
$folder = "C:\MKS_DEV\"
$null = ""