我正在尝试运行使用PowerShell Web请求cmdlet下载的Microsoft Online Services登录助手。
我刚刚开始编写脚本并停留在这部分 - 这应该是启动下载的程序。
这是代码:
$link = Invoke-WebRequest https://download.microsoft.com/download/5/0/1/5017D39B-8E29-48C8-91A8-8D0E4968E6D4/en/msoidcli_64.msi
$DLPath= ($ENV:USERPROFILE) + "\Downloads\" + ($link.split("/")[8])
Write-Host "Microsoft sign in assistance" -foregroundcolor yellow
Start-BitsTransfer -Source $Link -Destination $DLPath
Start-Process -FilePath $DLPath -Wait
我在$ DLPath部分有错误
PS C:\Windows\system32> $DLPath= ($ENV:USERPROFILE) + "\Downloads\" + ($link.split("/")[8])
Method invocation failed because [Microsoft.PowerShell.Commands.WebResponseObject] does not contain a method named 'split'.
At line:1 char:1
+ $DLPath= ($ENV:USERPROFILE) + "\Downloads\" + ($link.split("/")[8])
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
这个脚本的重点是,我最终能够与我的同事分享,他们将能够为我们的客户连接到办公室365,并为每个客户管理办公室365帐户
这对我有用:
$link = "https://download.microsoft.com/download/5/0/1/5017D39B-8E29-48C8-91A8-8D0E4968E6D4/en/msoidcli_64.msi"
$DLPath = Join-Path $ENV:USERPROFILE (join-path "Downloads" (Split-Path $link-Leaf))
Invoke-WebRequest $link -OutFile $DLPath
Write-Host "Microsoft sign in assistance" -foregroundcolor yellow
Start-Process -FilePath $DLPath -Wait
我放弃了“start-bitstransfer”,因为我已经使用“invoke-webrequest”下载了该文件