标签: powershell-remoting

PowerShell 2.0将"防火墙友好"是什么意思?

我有兴趣在防火墙后面的计算机上执行powershell脚本.我需要打开哪些端口?是否需要任何特殊配置,或者我将能够连接到全新安装的Windows Server 2008 r2并开始执行我的脚本?

powershell powershell-remoting

12
推荐指数
2
解决办法
4231
查看次数

如何通过Powershell Remoting运行7za.exe?

我已经尝试了很多不同的方法来做到这一点,它们都会导致同样的错误.这是一组命令:

$s = New-PSsession -ComputerName ServerA
$job = Invoke-Command -Session $s -Scriptblock { Start-Process -FilePath    
    "C:\Scripts\ArchiveEventLogs\ver4.5\7za.exe" -ArgumentList "a", 
    "C:\Scripts\Eventlogs.bak\ServerA-20101111.7z", "C:\Scripts\Eventlogs.bak\*.evt*", 
     "-mx7", "-oC:\Scripts\Eventlogs.bak", "-wC:\Scripts\Eventlogs.bak", "-t7z" -Wait }  
     -AsJob

Get-Job | Wait-Job
Receive-Job Job$
Run Code Online (Sandbox Code Playgroud)

我得到的输出是这样的:

7-Zip (A) 9.17 beta  Copyright (c) 1999-2010 Igor Pavlov  2010-10-04
Scanning

Creating archive C:\Scripts\Eventlogs.bak\ServerA-20101111.7z

ERROR: Can't allocate required memory!
Run Code Online (Sandbox Code Playgroud)

我怎么能通过那个错误?

我应该指出,如果我直接在没有远程处理的ServerA上运行Scriptblock,它就可以工作.谢谢你的帮助!

powershell 7zip invoke-command powershell-remoting

12
推荐指数
2
解决办法
4206
查看次数

Powershell,svn和身份验证

我可以远程桌面到一个给定的机器并运行svn,而不提供身份验证信息,它的工作原理; 我的AD身份验证允许我访问我想要的存储库.

我可以使用Powershell连接到机器并执行svn命令.但是,当我这样做时,我会"禁止访问".[Environment]::UserName从远程执行的脚本运行时,显示我期望的用户名(我的AD用户名).

我缺少什么让这项工作?

一些代码:

$Session = New-PSSession -ComputerName $computerName;

if (-Not ($Session)) {
    Write-Host "Did not create session!";
    Return;
}

Invoke-Command -Session $Session -FilePath 'switchAllRepositories.ps1' -ArgumentList $branchName;

Remove-PSSession $Session;
Run Code Online (Sandbox Code Playgroud)

在switchAllRepositories中,我有一个参数:

Param(
  [string]$branchURL
)
Run Code Online (Sandbox Code Playgroud)

一系列的调用如:

If(Test-Path "C:\webfiles\repositoryname") {
    Write-Host "Switching repositoryname"
    SwitchRepo "repositoryname" ($branchURL) "C:\webfiles\repositoryname";
}
Run Code Online (Sandbox Code Playgroud)

哪个电话:

Function SwitchRepo ($repoName, $branchPath, $workingCopy)
{
    $to = ("https://[url]/svn/" + $repoName + $branchPath);
    Write-Host "to $to";

    #debug
    $user = [Environment]::UserName
    Write-Host "as $user";

    $exe = "C:\Program Files\TortoiseSVN\bin\svn.exe";
    &$exe switch "$to" "$WorkingCopy" …
Run Code Online (Sandbox Code Playgroud)

svn powershell powershell-remoting

11
推荐指数
1
解决办法
1379
查看次数

在远程会话中启动后台任务,在删除会话时不会被杀死

我一直在使用PsExec -d远程PowerShell会话中启动控制台应用程序,因为我希望这些应用程序在执行某些任务时在后台运行.问题是我希望后台应用程序继续运行,即使我杀死远程PowerShell会话Remove-PSSession.当前发生的事情是远程PowerShell会话被杀死所以所有进程都是在帮助下启动的PsExec -d.我猜它与进程树有关,以及windows如何管理这些事情的生命周期.

有没有人知道如何启动远程后台进程并且即使在远程会话被杀死后该进程仍然存在?

powershell psexec powershell-2.0 powershell-remoting

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

使用Powershell中的Get-EventLog远程读取事件日志

我有一个在服务器(测试服务器)上运行的powershell脚本,并读取他的客户端(DC1)的日志文件.

  • 双方可以互相ping.
  • 在两侧,防火墙都被禁用.
  • DC1上启用了远程桌面和远程协助.

    Get-EventLog System -ComputerName test-server -Source Microsoft-Windows-Winlogon # WORKS
    Get-EventLog System -ComputerName DC1 -Source Microsoft-Windows-Winlogon # DOESN'T WORK
    
    Run Code Online (Sandbox Code Playgroud)

我在test-server上运行这个脚本.正如您在test-server上读取本地日志文件时所看到的那样工作正常但如果我尝试远程读取DC1的日志文件,则会收到错误" Get-EventLog:找不到网络路径 ".

错误的屏幕截图: 在此输入图像描述

如何使用Get-EventLog避免此错误并从测试服务器读取DC1的日志文件?

powershell cmdlets powershell-remoting

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

用V1进行Powershell远程处理

你知道使用powershell V1的任何好的远程解决方案(我知道V2的东西很棒,但我的组织不喜欢使用预发布软件).我不需要任何明显的东西,只是在另一个盒子上启动PowerShell脚本并在完成后得到结果的方法.我正在考虑使用sysinternals PSEXEC和export-csv/import-csv,只是制作有用的东西.不过,我宁愿别人做这项工作.

powershell powershell-1.0 powershell-remoting

9
推荐指数
1
解决办法
764
查看次数

Import-PSSession:已为'%'命令跳过代理创建,因为PowerShell无法验证其名称是否安全

我有一个Sharepoint服务器场设置,我正在使用远程PowerShell从域中的Windows 7计算机连接到我的一个应用程序/搜索服务器.客户端和应用程序服务器都具有PowerShell 2,执行策略设置为不受限制且启用了psremoting.此外,我正在运行cmdlet作为域管理员帐户.

我可以使用以下cmdlet创建到远程服务器的会话:

$Session = New-PSSession -ConfigurationName "Microsoft.PowerShell" -ConnectionUri "http://app01-spl1:5985/wsman/" -Authentication "Kerberos" 
Import-PSSession $Session -AllowClobber
Run Code Online (Sandbox Code Playgroud)

但是,当我导入会话时,我得到以下错误:

Import-PSSession : Proxy creation has been skipped for '%' command, because PowerShell couldn't verify its name as safe.
At line:1 char:17
+ Import-PSSession <<<<  $Session -AllowClobber
    + CategoryInfo          : InvalidData: (:) [Import-PSSession], InvalidOperationException
    + FullyQualifiedErrorId : ErrorSkippedUnsafeCommandName,Microsoft.PowerShell.Commands.ImportPSSessionCommand
Import-PSSession : Proxy creation has been skipped for '?' command, because PowerShell couldn't verify its name as safe.
At line:1 char:17
+ Import-PSSession <<<<  $Session -AllowClobber …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-2.0 powershell-remoting

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

使用PowerShell远程运行Java

当我在远程会话()中运行PowerShelletsn {servername},我有时似乎无法运行Java进程,即使是最简单的:

[chi-queuing]: PS C:\temp> java -cp .\hello.jar Hello
Error occurred during initialization of VM
Could not reserve enough space for object heap
Run Code Online (Sandbox Code Playgroud)

Hello.jar是一个"你好,世界!" 应该只打印"Hello"到标准输出的应用程序.

所以,问题是,在PowerShell会话的另一端运行进程有什么特别之处吗?关于Java VM如何工作可能不允许这样的处理吗?内存是在远程计算机上分配的,对吧?以下是可用物理内存的读数:

[chi-queuing]: PS C:\temp> $mem = Get-wmiobject -class Win32_OperatingSystem
[chi-queuing]: PS C:\temp> $mem.FreePhysicalMemory
1013000
Run Code Online (Sandbox Code Playgroud)

但是,当我远程桌面到服务器并询问操作系统有多少可用内存时,它说270 MB物理内存可用.让我知道你的想法!

java powershell process powershell-remoting

8
推荐指数
1
解决办法
6153
查看次数

尝试远程访问localhost上的Exchange服务器时出现"访问被拒绝"错误

我正在尝试建立PowerShell会话以对localhost上的Exchange服务器运行多个Exchange命令.我一直收到以下错误:

New-PSSession : [<HOSTNAME>] Connecting to remote server <HOSTNAME> failed with the following error message
: Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'h ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
   gTransportException
    + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed
Run Code Online (Sandbox Code Playgroud)

我的代码是Microsoft Technet文章的副本粘贴.它适用于远程机器,但无论何时我瞄准我运行的机器,我都会收到上述错误.

到目前为止我尝试过的:

  1. 检查了about_remote_troubleshooting帮助主题.与Access Denied错误相关的任何内容均无效.
  2. 使用与收到"拒绝访问"错误相同的凭据的目标远程计算机.(没有问题连接)
  3. 已验证我的PowerShell会话是以管理员身份运行的.(它是)
  4. 已验证Exchange命令行管理程序是否能够成功启动.(它是)
  5. 尝试没有凭据,看看是否可行.(它没有)
  6. 检查net usenet session确保我没有具有相同凭据问题的奇怪的多个连接.(我没有看到任何迹象表明)
  7. 从导致问题的脚本和手动键入命令到PowerShell控制台中尝试了这一点.(两种方式都得到了相同的结果.为了保持一致性)
  8. 在多个系统上尝试过这个.(到处都是相同的结果

一些快速说明:

  • 这是在Windows Server 2012上运行的Exchange 2013.它是一个基本安装,只是一个测试环境,除了安装和启用远程处理之外,它具有非常少的数据和最少的配置.
  • 使用的凭据用于域管理员,域管理员还具有必要的Exchange权限,可以执行我需要执行的任何操作.也就是说,只要我的目标机器不是我正在运行的机器,我就没有任何问题,没有其他任何改变我连接的方式.此外,这是一个测试域,其中域管理员的访问权限未受到任何限制或调整,因此它应该完全和完全访问所有内容. …

powershell access-denied powershell-remoting windows-server-2012 exchange-server-2013

8
推荐指数
1
解决办法
5万
查看次数

如何使用Invoke-Command将局部变量传递给在远程计算机上执行的脚本块?

我正在尝试检索位于远程服务器中的文件的Filehash Invoke-Command.我在powershell版本4上运行我的脚本.当我给出完整路径如下时,它工作正常:

Invoke-Command -ComputerName winserver -ScriptBlock { 
    Get-FileHash -Path E:\test\testfile.zip -Algorithm SHA1 
}
Run Code Online (Sandbox Code Playgroud)

以上命令有效.但是我需要通过变量传递文件名,如下所示:

Invoke-Command -ComputerName winserver -ScriptBlock { 
    Get-FileHash -Path "E:\test\$dest.zip" -Algorithm SHA1 
}
Run Code Online (Sandbox Code Playgroud)

我是脚本和PowerShell的新手.请帮我解决这个问题!

powershell powershell-remoting powershell-4.0

8
推荐指数
2
解决办法
1万
查看次数