0

考虑到用户已经在浏览器上登录了他/她的 Google 帐户,该 Powershell 脚本打算写入 Google 表格,但它会引发错误System.Net.WebException。信息:

Invoke-WebRequest: The remote server returned an error: (401) Unauthorized.
In C:\Users\F76254C\Desktop\Nova pasta\Batch files\Available Projects\Latam HIL Lab Menu\libs\GAS.ps1:141 character:1
+ Invoke-WebRequest -UseBasicParsing -Uri $GoogleWebAppURL -Method POST ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

我使用使用我的个人 Google 帐户(谁有权访问该应用程序:任何人)部署的 Google Web App 测试了此代码,它工作正常,没有错误,但我需要使用我的专业 Google 部署的 Google Web App 使其工作帐户(有权访问应用程序的人员:公司内的任何人)。

$GoogleWebAppURL = 'URL_DEPLOYED_FROM_PROFESSIONAL_GOOGLE_ACCOUNT'

$Column1Name = 'Computer'
$Column1Value = $env:COMPUTERNAME

$Column2Name = 'IP Address'
$Column2Value = (Test-Connection -ComputerName ::1 -Count 1|select ipv4address).ipv4address

$Column3Name = 'OS Version'
$Column3Value = "$([System.Environment]::OSVersion.Version.Major)`.$([System.Environment]::OSVersion.Version.Minor)`.$([System.Environment]::OSVersion.Version.Build)`.$([System.Environment]::OSVersion.Version.Revision)"

$Column4Name = 'Uptime'
$Column4Value = (Get-CimInstance -ClassName win32_operatingsystem | select lastbootuptime).lastbootuptime

$postParams = @{$Column1Name=$Column1Value;$Column2Name=$Column2Value;$Column3Name=$Column3Value;$Column4Name=$Column4Value}
Invoke-WebRequest -UseBasicParsing -Uri $GoogleWebAppURL -Method POST -Body $postParams

Write-Host `"$Column1Name=$Column1Value"&"$Column2Name=$Column2Value"&"$Column3Name=$Column3Value"&"$Column4Name=$Column4Value`"
4

0 回答 0