如何运行基于联机的powershell脚本

如何运行基于联机的powershell脚本,powershell,scripting,Powershell,Scripting,我有一个Powershell脚本存储在这里: 我想通过这个gitlab中的一个预定任务在许多服务器上运行这个脚本,这样我就可以对脚本进行单个更改,并且它将在所有服务器上运行最新的脚本 有谁能告诉我这是否可能,以及如何做到 谢谢您可以使用Invoke WebRequest with-OutFile下载一个文件,然后执行它。您可以将该文件以.txt格式存储在web服务器上,这样就不必添加MIME类型 $scriptUrl = "http://localhost/test.txt" $destina

我有一个Powershell脚本存储在这里:

我想通过这个gitlab中的一个预定任务在许多服务器上运行这个脚本,这样我就可以对脚本进行单个更改,并且它将在所有服务器上运行最新的脚本

有谁能告诉我这是否可能,以及如何做到


谢谢

您可以使用Invoke WebRequest with-OutFile下载一个文件,然后执行它。您可以将该文件以.txt格式存储在web服务器上,这样就不必添加MIME类型

$scriptUrl = "http://localhost/test.txt"
$destination = "c:\temp\test.txt"
$scriptName = "c:\temp\test.ps1"

Invoke-WebRequest $scriptUrl -OutFile $destination

# if the file was downloaded, delete the old script file and rename the new
# file
if(test-path $destination){
    remove-item $scriptName
    Rename-Item $destination $scriptName
}

&$scriptName
道具