我正在尝试从 Excel 文档中提取特定的单元格值,并将该单元格值添加到 URL 的末尾。目前其余代码工作,成功打开文件,获取特定单元格值并打印它,但我不确定如何将变量保存在 Invoke-webrequest 中。
# start Excel
$excel = New-Object -comobject Excel.Application
#open file
$FilePath = 'FilePath'
$workbook = $excel.Workbooks.Open($FilePath)
#make it visible (just to check what is happening)
$excel.Visible = $true
#print file name
$workbook.sheets.item(1).activate()
$workSheet = $Workbook.Sheets.Item(1)
$WorkSheet.Name
#print cell value
$WorkbookTotal=$workbook.Worksheets.item(1)
$value = $WorkbookTotal.Cells.Item(1, 1)
$value.Text
# First retrieve the website
$result = Invoke-webrequest -Uri "https://www.website.com/$value" -Method Get
$resultTable = @{}
# Get the title
$resultTable.title = $result.ParsedHtml.title
# Return the table we have built as an object
Write-Output New-Object -TypeName PSCustomObject -Property $resultTable
#close excel
$excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
spps -n Excel
一旦它访问域,它应该打印页面标题,我也成功地工作了。非常感谢任何帮助,并提前感谢您。