以下内容对我不起作用 -
%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Noninteractive -command "& Invoke-Command -ComputerName "Spider_LT_86" -ScriptBlock { msiexec.exe /i "D:\3PDInstallers\ETLBackgroundWorkerSetup.msi" /qn /l*vx "D:\3PDInstallers\logs" }"
Run Code Online (Sandbox Code Playgroud)
我需要做的就是在远程机器上运行msiexec.我假设运行脚本的用户将具有对远程计算机的必需访问权限.
即使Computername指向本地计算机,该脚本也不起作用(并且使用相同的登录用户运行msiexec工作正常,因此它看起来不像权限问题) - 我确保WinRM服务正在运行,我也禁用防火墙检查是否是问题的原因,但到目前为止没有运气.我在这里错过了什么?
这是完整的错误,但它几乎列出了所有可能性 -
Connecting to remote server failed with the following error message : WinRM cannot process the request. The following error occured while using
Kerberos authentication: The network path was not found.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are specified.
-Kerberos …Run Code Online (Sandbox Code Playgroud) 我有另一个命令行程序,我从我的 powershell 脚本调用它,并希望在从 powershell 打开后在该窗口中运行一些交互式命令。
换句话说 - 我做了一个Invoke-Item $link_to_app为该应用程序打开交互式命令行的操作,现在我想在 powershell 脚本中使用特定于应用程序的命令。
例如app.exe -help调用app.exe.
任何指针都会有所帮助。谢谢!
我创建了以下脚本(test.ps1),我从命令行执行它作为"powershell.\ test.ps1"
Write-Host(Start-Transcript -Path "D:\logs.txt")
$remoteScript = {
Write-Host "Remote Log"
}
Invoke-Command -ConnectionUri $uri -Credential $creds -ScriptBlock $remoteScript
Write-Host "Local Log"
Write-Host(Stop-Transcript)
Run Code Online (Sandbox Code Playgroud)
但是在执行脚本后生成的日志文件中,我没有看到远程或本地的日志语句.这曾经与Powershell 3.0一起使用,但最近我升级到Powershell 4.0并且它停止工作.
有没有人遇到类似的问题或者是否知道从远程和本地命令捕获输出的任何其他方法?
谢谢,
拉夫
powershell powershell-ise powershell-remoting powershell-3.0 powershell-4.0
我正在尝试执行以下test.ps1脚本
param([string]$name,[string]$password);
write-Output "Hello $($name) my password is $($password)";
dir c:\
New-Item c:\HRTemp\test.txt -ItemType file
Run Code Online (Sandbox Code Playgroud)
在远程服务器上使用以下命令
StartPowershellScript("Invoke-Command", args =>
{
args.Append("ScriptBlock", "{{c:\\test.ps1 -name dato -password test}}" );
});
Run Code Online (Sandbox Code Playgroud)
我能够从命令行成功调用这个命令,现在我想要使用 cake 脚本。
我正在使用Cake.Powershell插件。
当我尝试用一个大括号执行它{c:\\test.ps1 -name dato -password test}时,出现错误:
Error: Input string was not in a correct format.
当我用两个花括号尝试它时
{{c:\\test.ps1 -name dato -password test}}
输出如下
Executing: Invoke-Command -ScriptBlock {{c:\test.ps1 -name dato -password test}}
但是,当我检查远程服务器 test.txt 文件时没有创建。
你知道为什么会这样吗?
我有两个非域虚拟机。两者都运行相同版本的 PowerShell。其中一台虚拟机托管 WindowsServerCore 的透明网络 Docker 容器。非 Docker 虚拟机有 * 表示受信任的机器。Docker 容器已运行 Enable-PSRemoting 并托管自签名证书。Docker VM 端口 5985 和 5986 都可供非 Docker VM 访问,通过与这些端口上的 Docker IP 的 telnet 会话证明。我已将新用户添加到 Docker VM 并将其设置在管理员组中。我已经重置了 WinRM 服务。
无论我使用什么用户名/密码组合,当我尝试从非 Docker 虚拟机在 HTTP 或 HTTPS 上建立远程 PowerShell 会话时,访问总是被拒绝。
有人能够让它发挥作用吗?
在 powershell 中,我试图创建一个远程会话。它失败了(没关系,我知道为什么失败),但问题是我正在尝试设置失败超时。
我创建了一个 New-PSSessionOption 并以毫秒为单位设置了 OpenTimeout,但似乎无论如何它总是花费相同的时间:15 秒。*
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$pso = New-PSSessionOption -OpenTimeout 10000
$server = "hostname"
$session = New-PSSession -ComputerName $server -Credential $cred -SessionOption $pso
...
Remove-PSSession $session
Run Code Online (Sandbox Code Playgroud)
New-PSSession 行出现的错误消息(如果与未应用超时的原因相关)是这样的:
连接到远程服务器“主机名”失败,并显示以下错误消息:WinRM 无法完成操作。验证指定的计算机名称是否有效、该计算机是否可通过网络访问、WinRM 服务的防火墙例外是否已启用并允许从此计算机进行访问。默认情况下,公共配置文件的 WinRM 防火墙例外限制对同一本地子网内的远程计算机的访问。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。
编辑: * 当更改 OpenTimeout 值时,它似乎发生了变化,但保持在一定范围内,即 5-20 秒。也许这个参数有一个未记录的最小值和最大值?
我有一台 Windows 10 主机,它连接到托管在同一台机器上的 Hyper-V Windows 10 VM。我一直在关注 Pluralsight PowerShell 教程。我正在尝试在远程计算机上获得可用的服务。
我可以使用以下命令在远程计算机上启动会话:
Enter-PSSession -ComputerName Client1 -Credential username
Run Code Online (Sandbox Code Playgroud)
会话开始并连接后,我尝试调用 Get-Service 来识别客户端计算机上的服务。
[Client1]: PS C:\Users\username\Documents>Get-Service
Run Code Online (Sandbox Code Playgroud)
当我运行上述命令时,我收到以下错误消息:
未实现远程主机方法 get_WindowSize。
+ CategoryInfo : ResourceUnavailable: (:) [out-lineoutput], PSRemotingDataStructureException
+ FullQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.OutLineOutputCommand
我在主机和客户端机器上运行相同版本的 PowerShell ( 5.1.18362.145 )。我认为不知何故这是客户端机器上的问题?
我正在通过 PS 远程会话访问服务器。git pull我正在尝试从 github 存储库运行 a 。远程计算机上的 git 凭据存储在 Windows 凭据管理器中。但是我收到这个错误:
fatal: Unable to persist credentials with the 'wincredman' credential store.
See https://aka.ms/gcm/credstores for more information.
bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Username for 'https://github.com': No such file or directory
Run Code Online (Sandbox Code Playgroud)
无论我使用交互式会话还是Invoke-Command. 当我 RDP 进入远程服务器并在那里运行命令时,工作正常git pull。git fetch有没有办法在远程会话中访问 WCM?
这个自我回答的问题是从 PowerShell (Core) v7.3.x 开始编写的,旨在解决以下症状:
有时,使用或似乎都无法有效地通过/语句捕获和处理错误。-ErrorAction -Stop$ErrorActionPreference = 'Stop'trycatch
这是两个例子:
Get-NetAdapter$ErrorActionPreference = 'Stop' 从脚本或函数中忽略(从全局范围以外的范围):
# Run on Windows. Affects both PowerShell editions.
# The `catch` block isn't triggered, and the (still non-terminating) error prints.
& { # Simulate running in a child scope.
$ErrorActionPreference = 'Stop'
try {
Get-NetAdapter nosuch
}
catch {
"Should get here, but don't."
}
}
Run Code Online (Sandbox Code Playgroud)
-ErrorAction Stop( Get-NetAdapter nosuch -ErrorAction Stop …error-handling powershell powershell-remoting powershell-core
我的powershell脚本使用以下代码将文件发送到自定义会话中的多个客户端(代码缩短)
function DoCopyFile
{
param(
[Parameter(Mandatory=$true)] $RemoteHost,
[Parameter(Mandatory=$true)] $SrcPath,
[Parameter(Mandatory=$true)] $DstPath,
[Parameter(Mandatory=$true)] $Session)
.
.
.
$Chunks | Invoke-Command -Session $Session -ScriptBlock { `
param($Dest, $Length)
$DestBytes = new-object byte[] $Length
$Pos = 0
foreach ($Chunk in $input) {
[GC]::Collect()
[Array]::Copy($Chunk, 0, $DestBytes, $Pos, $Chunk.Length)
$Pos += $Chunk.Length
}
[IO.File]::WriteAllBytes($Dest, $DestBytes)
[GC]::Collect()
} -ArgumentList $DstPath, $SrcBytes.Length
.
.
.
}
$Pwd = ConvertTo-SecureString $Node.Auth.Password -asplaintext -force
$Cred = new-object -typename System.Management.Automation.PSCredential -ArgumentList ("{0}\{1}" -f $Name, $Node.Auth.Username),$Pwd
$Sopts = New-PSSessionOption -MaximumReceivedDataSizePerCommand …Run Code Online (Sandbox Code Playgroud)