我有兴趣在防火墙后面的计算机上执行powershell脚本.我需要打开哪些端口?是否需要任何特殊配置,或者我将能够连接到全新安装的Windows Server 2008 r2并开始执行我的脚本?
我已经尝试了很多不同的方法来做到这一点,它们都会导致同样的错误.这是一组命令:
$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,它就可以工作.谢谢你的帮助!
我可以远程桌面到一个给定的机器并运行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) 我一直在使用PsExec -d远程PowerShell会话中启动控制台应用程序,因为我希望这些应用程序在执行某些任务时在后台运行.问题是我希望后台应用程序继续运行,即使我杀死远程PowerShell会话Remove-PSSession.当前发生的事情是远程PowerShell会话被杀死所以所有进程都是在帮助下启动的PsExec -d.我猜它与进程树有关,以及windows如何管理这些事情的生命周期.
有没有人知道如何启动远程后台进程并且即使在远程会话被杀死后该进程仍然存在?
我有一个在服务器(测试服务器)上运行的powershell脚本,并读取他的客户端(DC1)的日志文件.
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 V1的任何好的远程解决方案(我知道V2的东西很棒,但我的组织不喜欢使用预发布软件).我不需要任何明显的东西,只是在另一个盒子上启动PowerShell脚本并在完成后得到结果的方法.我正在考虑使用sysinternals PSEXEC和export-csv/import-csv,只是制作有用的东西.不过,我宁愿别人做这项工作.
我有一个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时etsn {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物理内存可用.让我知道你的想法!
我正在尝试建立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文章的副本粘贴.它适用于远程机器,但无论何时我瞄准我运行的机器,我都会收到上述错误.
到目前为止我尝试过的:
about_remote_troubleshooting帮助主题.与Access Denied错误相关的任何内容均无效.net use并net session确保我没有具有相同凭据问题的奇怪的多个连接.(我没有看到任何迹象表明)一些快速说明:
powershell access-denied powershell-remoting windows-server-2012 exchange-server-2013
我正在尝试检索位于远程服务器中的文件的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的新手.请帮我解决这个问题!