簡體   English   中英

Powershell 遠程執行命令

[英]Powershell remotely execute commands

我在嘗試遠程執行命令時遇到問題。 首先,該命令試圖將可執行文件復制到遠程系統,我認為這是我的問題,因為您無法直接訪問 \hostname\C$\Windows\Temp,您必須先連接到 C$,然后再連接到 go 到 C :\Windows\Temp

話雖如此,我也嘗試過( $Dest = "C$" ),但仍然無法正常工作

僅供參考:該文件夾可能存在也可能不存在於客戶端中


$SetupFolder = "C$\Windows\Temp\Logs"

$Path = "C:\Windows\Temp\Logs\Install.exe"

$Dest = "C$"

# Remote run the install for each system

foreach ($System in $SystemList) {
    if (test-Connection -Cn $System -quiet) { 
        Copy-item $Package -Destination \\$System\$SetupFolder -recurse -Force
        if (Test-Path - Path $Path) {
            Invoke-Command -ComputerName $System -ScriptBlock {powershell.exe $Path /S} -credential $Credentials

            Write-Host -ForegroundColor Green "Installation Successful on $System"
        }

    } else {
    Write-Host -ForegroundColor Red "$System is not online, Install failed"
    }

}

如果您不能使用Invoke-Command ,您可以使用Enter-PSSession ,這將啟動與遠程計算機的交互式 session ,您需要先獲得遠程計算機的權限才能連接,

PowerShell 文檔中的更多信息, https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.7.core/enter-pssession?1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM