使Powershell运行下载的程序

时间:2019-03-08 12:40:05

标签: powershell

我正在尝试运行使用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

此脚本的要点是最终我将能够与我的同事共享该脚本,并且他们将能够连接到Office 365 为我们的客户提供服务,并为每个客户管理Office 365帐户

1 个答案:

答案 0 :(得分:1)

这对我有用:

$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”下载了文件