标签: powershell-remoting

使用PowerShell凭据而不提示输入密码

我想重新启动属于域的远程计算机.我有一个管理员帐户,但我不知道如何从powershell使用它.

我知道有一个Restart-Computercmdlet,我可以通过凭据但是如果我的域名是,例如mydomain,我的用户名是myuser,我的密码是mypassword使用它的正确语法?

我需要安排重启,所以我不必输入密码.

powershell powershell-remoting

141
推荐指数
4
解决办法
45万
查看次数

使用ip-address作为目标的Powershell远程处理

我在Server 2008 R2上成功启用了PSRemoting.我可以使用主机名作为目标在同一网络中进行远程pssession.

当我尝试从任何计算机(在网络内或从其他网络(例如通过VPN))使用IP地址作为目标时,我失败了.我希望能够通过我的VPN连接使用远程处理,因为无法解析主机名,因此我必须使用IP地址.

我不想在我的hosts文件中添加名称,因为我们的客户端上有一些其他服务器具有相同的dns-name,我不想删除并再次插入name-ip-address-association然后再次.

我希望有人能告诉我如何通过IP调用psremoting-target.

编辑:更具体地说,我希望能够运行:

Enter-PSSession -Computername 192.168.123.123 -credentials $cred 
Run Code Online (Sandbox Code Playgroud)

但是,如果我将主机名传递给" -Computername" ,我只能运行该命令

Edit2:
当我尝试使用ip而不是主机名(来自内部网络)登录时,我收到了错误消息:

Enter-PSSession : Connecting to remote server failed with the following error message : The WinRM client cannot process
 the request. Default authentication may be used with an IP address under the following conditions: the transport is HT
TPS or the destination is in the TrustedHosts list, and explicit credentials are provided. Use winrm.cmd to configure T
rustedHosts. Note that computers …
Run Code Online (Sandbox Code Playgroud)

powershell remoting powershell-remoting

59
推荐指数
3
解决办法
14万
查看次数

Enter-PSSession在我的Powershell脚本中不起作用

当我从脚本运行下面的行时,文件最终会在我的本地计算机上创建.

$cred = Get-Credential domain\DanTest
Enter-PSSession -computerName xsappb01 -credential $cred

New-Item -type file c:\temp\blahxsappk02.txt

exit-pssession
Run Code Online (Sandbox Code Playgroud)

当我从powershell控制台单独运行每一行时,将正确创建远程会话,并在远程计算机上创建该文件.有什么想法吗?时间问题是脚本也许吗?

powershell powershell-remoting

36
推荐指数
1
解决办法
4万
查看次数

如何将自定义PowerShell模块导入远程会话?

我正在开发一个自定义PowerShell模块,我想在与另一台计算机的远程会话的上下文中使用它.以下代码(显然不起作用)解释了我想要实现的目标:

import-module .\MyCustomModule.psm1
$session = new-pssession -computerName server01
invoke-command -session $session -scriptblock { 
  <# use function defined in MyCustomModule here #> 
}
Run Code Online (Sandbox Code Playgroud)

第一个问题是,是否完全可以实现这种情况?我的意思是我只希望我的自定义模块实际存在于我的机器上,而不是远程服务器上.

我找到了这个帖子,但我没有管理它 - 它不允许从远程机器创建一个会话回到本地.可能,我面对在该线程的评论中提到的配置限制......此外,作者提到了对我的解决方案至关重要的性能影响......

如果那可能,那怎么样?

PowerShell的版本目前不是一个约束 - 如果解决方案仅在PS 3.0中可用 - 我可以忍受这个.

powershell powershell-2.0 powershell-remoting powershell-3.0

35
推荐指数
2
解决办法
3万
查看次数

如何在powershell远程会话中编辑文件(powershell)

我使用powershell远程连接到另一台计算机,非常好.可以做很多,但如何编辑文件?

PS C:\ Users\guutlee> Enter-PSSession -ComputerName appprod

[appprod]:PS C:\ Users\guutlee\Documents> cd\myapp

[appprod]:PS C:\ myapp>

如何在远程计算机上的文件上打开文件编辑器?

[appprod]:PS C:\ myapp>编辑app.config

所以编辑"filename"似乎挂起,来自powershell.exe或powershell_ise.exe

我唯一能想到的就是退出pssession和"start\webprod\c $\inetpub\myapp\web.config",这将打开visual studio.

[appprod]:PS C:\ myapp>退出

PS C:\ Users\guutlee> start\agobuild\c $\myapp\app.config

PS C:\ Users\guutlee> Enter-PSSession -ComputerName appprod

[appprod]:PS C:\ Users\guutlee\Documents> cd\myapp

[appprod]:PS C:\ myapp> myapp.exe

当然,我必须重新找到该文件,希望c $共享可用且可访问,并重新连接我的pssession并在我想继续时重新找到我的工作目录.它似乎并不优雅.

我可以把它包裹起来这是一个功能,但很难把我的脑袋包裹起来......

那么如何使用远程pssession方便地编辑文件?

编辑

kbrimington的帖子让我想到了ssh的-X选项.对于PowerShell会话而言,将窗口应用程序转发回原始窗口环境可能会是一件非常棒的事情......

但我仍然很高兴只是编辑文件.

编辑

使用vi,emacs,cmd和编辑测试

PS C:\ Users\Meredith> Enter-PSSession -ComputerName appprod

[appprod]:PS C:\ Users\guutlee\Documents> C:\ vim\vim72\vim filename.txt

[appprod]:PS C:\ Users\guutlee\Documents> C:\ emacs-23.2\bin\emacs.exe -nw filename.txt

emacs.exe:emacs:标准输入不是tty

+ CategoryInfo          \: NotSpecified: (emacs: standard input …
Run Code Online (Sandbox Code Playgroud)

powershell editing powershell-remoting

33
推荐指数
2
解决办法
4万
查看次数

使用PowerShell的Invoke-Command进行远程处理时,如何包含本地定义的函数?

我觉得我错过了一些显而易见的东西,但我无法弄清楚如何做到这一点.

我有一个ps1脚本,其中定义了一个函数.它调用该函数,然后尝试远程使用它:

function foo
{
    Param([string]$x)

    Write-Output $x
}

foo "Hi!"

Invoke-Command -ScriptBlock { foo "Bye!" } -ComputerName someserver.example.com -Credential someuser@example.com
Run Code Online (Sandbox Code Playgroud)

这个简短的示例脚本打印出"嗨!" 然后崩溃说"术语'foo'不被识别为cmdlet,函数,脚本文件或可操作程序的名称."

我知道该功能未在远程服务器上定义,因为它不在ScriptBlock中.我可以在那里重新定义它,但我不愿意.我想定义一次该函数并在本地或远程使用它.有没有办法做到这一点?

powershell powershell-2.0 powershell-remoting

29
推荐指数
3
解决办法
3万
查看次数

使用PowerShell运行我的第三方DLL文件

我不确定PowerShell是否可行.

但基本上我有一个Windows窗体程序来配置一个名为EO Server的程序.EO服务器有一个API,我引用了EOServerAPI.dll来运行以下代码.

using EOserverAPI;
...
private void myButton_Click(object sender, EventArgs e)
{
    String MDSConnString="Data Source=MSI;Initial Catalog=EOMDS;Integrated Security=True;";

    //Create the connection
    IEOMDSAPI myEOMDSAPI = EOMDSAPI.Create(MDSConnString);

    //Get JobID
    Guid myMasterJobID = myEOMDSAPI.GetJobID("myJobRocks");
}
Run Code Online (Sandbox Code Playgroud)

是否可以与API DLL文件交互并进行与Windows窗体应用程序中相同类型的调用?

powershell powershell-2.0 powershell-remoting

26
推荐指数
2
解决办法
7万
查看次数

如何执行远程计算机中可用的PowerShell脚本?

我试图在远程计算机上执行脚本.

Enable-PSremoting在远程机器上做了" ".

hello.ps1在远程机器上放了一个脚本.

[我的客户端机器是Windows XP,远程计算机是Windows 2003]

然后从我的客户端计算机,我试图执行脚本.

invoke-command -computer $MachineName -filepath "C:\hello.ps1"
Run Code Online (Sandbox Code Playgroud)

我收到以下错误.

Invoke-Command:找不到路径'C:\ hello.ps1',因为它不存在.

我认为它试图从客户端机器中查找脚本.

如果我试着跑

invoke-command -computer $MachineName -command { C:\hello.ps1 } ,它执行客户端远程机器中可用的脚本.

但我想在远程机器本身执行远程脚本.

如何使它运行远程机器中可用的脚本?

更新:

实际上这个命令" invoke-command -computer $MachineName -command { C:\hello.ps1 }"在远程端工作,并将结果返回给客户端.我通过查看它在客户端执行的返回值而误解了.

powershell powershell-2.0 powershell-remoting

24
推荐指数
1
解决办法
6万
查看次数

Powershell远程处理 - 策略不允许委派用户凭据

我是PowerShell的新手,我在使用凭证授权方面遇到了麻烦.我有以下脚本:

$session = New-PSSession myserver -Authentication CredSSP -Credential DOMAIN\Administrator
Invoke-Command -Session $session -ScriptBlock { <Some PowerShell Command> }
Run Code Online (Sandbox Code Playgroud)

在运行之前,我做了以下事情:

  1. Enable-PSRemoting在myserver上运行.
  2. Enable-WSManCredSSP Server在myserver上运行.
  3. Restart-Service WinRM在myserver上运行.
  4. Enable-WSManCredSSP Client –DelegateComputer myserver在客户端上运行.
  5. 重新启动服务器和客户端.

但是一旦我运行脚本,我收到以下错误消息:

[myserver] Connecting to remote server failed with the following error message : The WinRM client cannot process the request. A computer policy does not allow the delegation of
 the user credentials to the target computer. Use gpedit.msc and look at the following policy: Computer Configuration -> …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-remoting winrm

24
推荐指数
4
解决办法
4万
查看次数

PowerShell远程处理给出"访问被拒绝"错误

我正在尝试使用PowerShell远程处理从远程域中的服务器检查某些磁盘大小,但我运行的命令无法正常工作.

情况是这样的:

  • 源服务器位于域A中
  • 目标服务器位于域B中
  • 这些域之间没有信任

域B中的服务器正在运行Exchange 2010,我可以使用此命令从服务器A对其运行Exchange 2010特定命令:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange –ConnectionUri $ConnectionURI -Credential $Credentials -Authentication Basic
Import-PSSession $Session
Run Code Online (Sandbox Code Playgroud)

问题是我无法使用此会话对此服务器运行任何非Exchange命令,如果我尝试然后它说它无法理解命令.我已经检查并使用Invoke-Command运行Get-Command,并且设置为我建立的会话的-Session变量仅返回Exchange命令.

所以我想我会尝试使用Invoke-Command和相关的ComputerName,身份验证类型和凭据,但这是失败的:

Invoke-Command -ScriptBlock {Get-Service} -ComputerName "Servername.destination.com" -Credential $Credentials -Authentication "Basic"
Run Code Online (Sandbox Code Playgroud)

这是错误:

[servername.destination.com] Connecting to remote server failed with the following error message : The WinRM client can
not process the request. The authentication mechanism requested by the client is not supported by the server or unencry
pted traffic is disabled in the service configuration. Verify the unencrypted traffic …
Run Code Online (Sandbox Code Playgroud)

powershell remoting powershell-2.0 powershell-remoting

23
推荐指数
2
解决办法
9万
查看次数