在尝试使用远程处理创建 PowerShell 脚本时,我遇到了我认为的双跳问题。在那篇文章中,Perriman 简要描述了问题以及解决问题的具体步骤(如果您知道命令,那几乎是微不足道的,但对于像我这样不太熟悉的人来说,这些信息非常宝贵!)。
我Enable-WSManCredSSP Server在我的 Win7 服务器上运行Enable-WSManCredSSP Client –DelegateComputer <FQDN of the server>时没有发生任何意外,但尝试在我的 Win7 客户端上运行时产生了这个错误:
Enable-WSManCredSSP : The client cannot connect to the destination specified
in the request. Verify that the service on the destination is running and
is accepting requests.
Consult the logs and documentation for the WS-Management service running
on the destination, most commonly IIS or WinRM. If the destination
is the WinRM service, run the following com mand on the …Run Code Online (Sandbox Code Playgroud) 通过我刚才的问题启发这里,我一直在尝试与PSEXEC。
目标是从另一台 WindowsXP 机器上跳出一些相当简单的脚本/程序,并且由于 PowerShell 2 还没有在 XP 上进行远程处理,PSexec 似乎可以很好地解决我的问题。
但是,除了“访问被拒绝”错误之外,我什么也得不到。
这是我迄今为止尝试过的:
我有一对 WindowsXP MCE 机器,它们在没有服务器或域控制器的工作组中联网。
我在两台机器上都关闭了“简单文件共享”。
在安全策略下,本地帐户的网络访问:共享和安全模型设置为经典,而不是两台机器的来宾。
我知道密码的每台计算机都有一个管理用户。:)
尽管如此,像“ > psexec \\otherComputer -u adminUser cmd”这样的命令会提示输入密码(就像它应该的那样)然后退出:
Couldn't access otherComputer:
Access is denied.
Run Code Online (Sandbox Code Playgroud)
所以,在这一点上,我转向社区。我在这里错过了什么步骤?
我有 Windows Server 2012(和 Server 2008,但它是下一个优先级)来使用txwinrm监视它。txwinrm 库内部使用的是 WinRS 协议。我必须使用最低权限的用户来监视它,但不知道如何为他配置访问权限。
我设法做的就是为我的用户配置远程 Powershell 会话,但看起来 winrs 和 powershell 会话具有不同的安全描述符:
Invoke-Command -ComputerName 192.168.173.206 -Credential (credential Administrator $pwd) -ScriptBlock { 2 + 2}
# gives 4
Invoke-Command -ComputerName 192.168.173.206 -Credential (credential lpu1 $pwd) -ScriptBlock { 2 + 2}
# gives 4
winrs -r:192.168.173.206 -u:Administrator -p:$pwd 'powershell -command "2+2"'
# gives 4
winrs -r:192.168.173.206 -u:lpu1 -p:$pwd 'powershell -command "2+2"'
# Gives Winrs error: Access is denied.
Run Code Online (Sandbox Code Playgroud)
我的用户的配置如下:
(Get-Item WSMan:\localhost\Service\RootSDDL).value
# O:NSG:BAD:P(A;;GA;;;BA)(A;;GA;;;S-1-5-21-3231263931-1371906242-1889625497-1141)S:P(AU;FA;GA;;;WD)(AU;SA;GWGX;;;WD)
(Get-PSSessionConfiguration -name Microsoft.Powershell).SecurityDescriptorSddl …Run Code Online (Sandbox Code Playgroud) 我在执行远程 powershell 脚本时遇到问题,该脚本应该更新应用程序的安装,以便在每天运行一次的任务管理器任务中进行自动化测试。
这个相当简单的脚本(详情如下)曾经成功运行了大约一年。突然它开始失败,因为无法执行远程PowerShell脚本。我不知道这是什么根本原因。本地 IT 确保他们没有更改任何内容。
(我应该注意,我可能可以用其他东西替换 powershell 脚本,但我不打算轻易放弃。除此之外,我想了解这里有什么问题)
这是一般设置:
未连接到域的 Windows Server 2008 R2 虚拟机,称为目标。u_target分配到目标上的管理员组的本地用户。
域中的 Windows Server 2008 R2 虚拟机(我们称为域 D),称为源。u_source分配给源上管理员组的域 D 用户。
Powershell 在两个 VM 上都有 2.0 版。
目标上的所有命令都u_target以管理员权限执行,源上的所有命令都u_source以管理员权限执行。在所有情况下,我都检查了 powershell 是否已以管理员身份启动。
大约一年前,我在两个 VM 上启用了 psremoting,如下所示:
在目标上,u_target 在 admin powershell 中执行
enable-psremoting -force,
set-item wsman:\local\client\TrustedHosts -value 'source'
然后机器重新启动。
两个命令都执行没有任何错误。后来,当我遇到麻烦时,我用 * 替换了 'source' 以确保问题不是由于打字错误造成的。
在源代码中,u_source在 admin powershell 中执行
enable-psremoting -force。这台机器也重新启动了。
后来,当事情失败时,目标也被添加到了 TrustedHosts 中。
应该执行的脚本原则上如下所示:
$server = 'target' …Run Code Online (Sandbox Code Playgroud) 我正在尝试执行以下 Powershell 命令:
Enter-PSSession -ComputerName localhost
Run Code Online (Sandbox Code Playgroud)
正在使用的服务器运行的是 Windows Server 2008 R2 SP1 64 位。服务器位于域中。我使用域管理员帐户登录。powershell 会话以管理员身份启动。
我从 powershell 本身收到以下错误消息:
PS C:\Users\Daniel> Enter-PSSession -Computername localhost
Enter-PSSession : Connecting to remote server localhost failed with the following error message : The client cannot
connect to the destination specified in the request. Verify that the service on the destination is running and is
accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most
commonly IIS or WinRM. If …Run Code Online (Sandbox Code Playgroud) PowerShell 2.0具有一些超级时髦的远程处理功能。但是,我不清楚它们是否可以在 Windows XP 机器上/之间使用,或者您是否需要 Windows Vista 或 Windows 7。
这是我所拥有的:
一对安装了 SP3 和.NET 3.5的 Windows XP MCE 机器。
两者都安装了 PowerShell 2.0 CTP3。
WS-Management v1.1 安装在两者上(因为 2.0 似乎不适用于 Windows XP?)
有了所有这些,“启用-PSRemoting”仍然让我犯了这个错误:
Enable-PSSessionConfiguration :此计算机未启用或不支持 Windows PowerShell 远程处理功能。这可能是因为您没有安装正确版本的 WS-Management,或者此版本的 Windows 当前不支持远程处理。
通常,此时我的回答是“好吧,我想是时候下载 Windows 7 RC”了,但是我已经看到了足够多的关于人们在 Windows XP 中进出远程处理的模糊评论,这让我觉得这是可能的.
我怎样才能让它发挥作用?
我正在尝试在 Windows Server 2008 上启用 Powershell Remoting,但据我了解,默认防火墙例外是仅当计算机(客户端和服务器)位于同一本地子网时才允许 PSRemoting。
如何在 Windows Server 2008 中删除本地子网限制。我知道在 server 2012 及更高版本中,您可以执行以下操作:
Set-NetFirewallRule –Name "Name" –RemoteAddress Any
Run Code Online (Sandbox Code Playgroud)
如何在 Windows Server 2008 中做完全相同的事情?
我有一些用于设置 IIS Web 应用程序、消息队列等的 Powershell 脚本。
他们使用我们创建的一组共享函数库 - 所以每个脚本都以行开头
. .\common.ps1
引用共享库。共享库包含一组函数,例如Create-IisApplicationPool,Create-MessageQueue等等,然后从实际脚本中调用这些函数。这些脚本的问题在于您需要通过远程桌面登录并在本地运行它们,因此我正在编写一些新脚本来将代码部署到 Amazon EC2 实例,并使用 Powershell 远程处理在本地调用它们。
我无法解决的是如何使这个共享库在远程 Powershell 会话中可用。
这是一个简单的例子:
函数.ps1
function Add-Title([string] $name) {
"Mr. $name"
}
function Say-HelloWorld([string] $name = "World") {
$computerName = $env:COMPUTERNAME
$greeting = Add-Title($name)
Write-Host "Hello, $greeting ($computerName)"
}
Run Code Online (Sandbox Code Playgroud)
例子.ps1
. ./functions.ps1
$remoteUsername = "username"
$remotePassword = "password"
$remoteHostname = "172.16.0.100"
$securePassword = ConvertTo-SecureString -AsPlainText -Force $remotePassword
$cred = New-Object System.Management.Automation.PSCredential $remoteUsername, $securePassword
Say-HelloWorld("Spolsky")
Run Code Online (Sandbox Code Playgroud)
在本地运行,这很好用 - 并按预期说“你好,斯波尔斯基先生(DYLAN_PC)”。
现在,如果我Say-HelloWorld …