我正在尝试从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
一旦访问域,它应该打印页面标题,我也已经成功地进行了工作。非常感谢您的帮助,在此先感谢您。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句