我在服务器 2008sysocmgr中的 Windows XP 中编写了脚本servermanagercmd,现在我发现我必须使用新的 PowerShell 模块servermanager在 Server 2008 R2 上安装功能,所以我希望我会在 Windows 7 中使用相同的模块,但事实并非如此那里。
如何在 Windows 7 中使用命令行或 PowerShell 安装 Windows 功能?
我如何找出(在 Powershell 中)哪个进程/任何使用最多内存的进程?
编辑:我试图弄清楚如何使用 Powershell 找出所有物理内存的使用情况,以防任务管理器等无法解释为什么所有物理 RAM 都已用完。即我需要识别缓存等使用的内存。
我想知道如何更改 $profile 变量指向的位置。
PS H:\> $profile
H:\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Run Code Online (Sandbox Code Playgroud)
H:\ 是网络共享,所以当我创建我的配置文件并加载 powershell 时,我得到以下信息:
安全警告只运行您信任的脚本。虽然来自 Internet 的脚本很有用,但此脚本可能会损害您的计算机。是否要运行 H:\WindowsPowerShell\Microsoft.PowerShell_profile.ps1?[D] 不运行 [R] 运行一次 [S] 暂停 [?] 帮助(默认为“D”):
根据微软的说法,$profile 的位置由 %USERPROFILE% 环境变量决定。这不是真的:
PS H:\> $env:userprofile
C:\Users\username
Run Code Online (Sandbox Code Playgroud)
例如,我有一台 XP 机器可以按照我想要的方式工作:
PS H:\> $profile
C:\Documents and Settings\username\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PS H:\> $env:userprofile
C:\Documents and Settings\username
PS H:\> $env:homedrive
H:
PS H:\> $env:homepath
\
Run Code Online (Sandbox Code Playgroud)
这是 Vista 机器的相同输出,其中 $profile 指向错误的位置:
PS H:\> $profile
H:\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PS H:\> $env:userprofile
C:\Users\username
PS H:\> $env:homedrive
H:
PS H:\> $env:homepath
\
Run Code Online (Sandbox Code Playgroud)
由于 $profile 实际上不是由 …
我正在尝试向 Exchange 2010 中的一位用户授予“发送身份”权限。这是我正在运行的 Powershell 命令:
Add-ADPermission "User1" -User "Ourdomain\User2" -Extendedrights "Send As"
Run Code Online (Sandbox Code Playgroud)
Powershell 返回此错误:
DC.OurDomain.pri 上的 Active Directory 操作失败。此错误不可重试。附加信息:访问被拒绝。活动目录响应:00000005:SecErr:DSID-031521D0,问题 4003(INSUFF_ACCESS_RIGHTS),数据 0 + CategoryInfo:WriteError:(0:Int32)[Add-ADPermission],ADOperationException +FullyQualifiedErrorId:EDBB94.添加AD权限
我已经尝试了 Powershell 命令的多种替代方法 - 即。使用 -Identity 等,但这和 EMC 向导都返回相同的错误。
我不确定“INSUFF_ACCESS_RIGHTS”是指运行命令的我还是我授予发送权限的用户?
我一直在关注 Microsoft Technet “管理邮箱发送权限”网页:http : //technet.microsoft.com/en-us/library/bb676368.aspx
因此,添加了您需要执行此操作的两个权限:
组织管理
收件人管理
但这无济于事。有任何想法吗?
如果我执行以下操作:
这是有效的,如果我关闭 ADUaC 并再次打开它并重新检查那些新权限,它们仍然存在。如果我在大约 10 分钟后返回,这些权限现在消失了 - user2 根本没有出现在 user1 的安全权限中。
不要以为我以前从未见过这种 AD 行为。
在尝试使用远程处理创建 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) 我有一个带有 Windows 2003、2008 和 2008r2 服务器的网络。我有一个 powershell 脚本,我编写它来使用“Microsoft.Update”com 对象修补本地机器。(类似于 Windows 更新 PowerShell 远程处理。)我的脚本在本地运行良好,但我想远程使用它的功能,因为我有相当数量的服务器需要管理。在这种情况下,它会掉下来(类似于没有解决的其他帖子)。
然而,我能够将失败缩小到特定类的两种方法。
(New-Object -ComObject "Microsoft.Update.Session").CreateUpdateDownloader()
(New-Object -ComObject "Microsoft.Update.Session").CreateUpdateInstaller()
Run Code Online (Sandbox Code Playgroud)
如果您以管理员身份在本地的 powershell 中运行这些,则不会有任何问题。如果您尝试使用 invoke-command(或 enter-session 或 winrs),您将收到以下错误。(这是使用 localhost 进行测试,但任何主机都可以。我还尝试了不同的身份验证方法,例如 credssp 和 kerberos。);
PS C:\> Invoke-Command -ComputerName localhost -ScriptBlock { (New-Object -ComObject "microsoft.update.session").createUpdateDownloader()}
Exception calling "CreateUpdateDownloader" with "0" argument(s): "Access is denied. (Exception from HRESULT: 0x80070005
(E_ACCESSDENIED))"
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
Run Code Online (Sandbox Code Playgroud)
我在博客上看到这是一个错误,但没有备份该声明。存在两种解决方法,但都不让我高兴。
我对在主机上远程运行更新的其他方法持开放态度,因为这似乎是很多人都遇到的问题。
我找到了 …
powershell windows-server-2003 windows-server-2008 windows-update winrm
我需要在 PS 脚本中处理 SVN 工作副本,但是我无法将参数传递给函数。这是我所拥有的:
function foo($arg1, $arg2)
{
echo $arg1
echo $arg2.FullName
}
echo "0: $($args[0])"
echo "1: $($args[1])"
$items = get-childitem $args[1]
$items | foreach-object -process {foo $args[0] $_}
Run Code Online (Sandbox Code Playgroud)
我想通过$arg[0]为$arg1对foo,和$arg[1]作为$arg2。但是,它不起作用,由于某种原因$arg1总是空的:
PS C:\Users\sbi> .\test.ps1 blah .\Dropbox
0: blah
1: .\Dropbox
C:\Users\sbi\Dropbox\Photos
C:\Users\sbi\Dropbox\Public
C:\Users\sbi\Dropbox\sbi
PS C:\Users\sbi>
Run Code Online (Sandbox Code Playgroud)
注:该"blah"参数不为过$arg1。
我绝对确定这是一件非常简单的事情(我才刚开始做 PS,仍然觉得很笨拙),但我已经用了一个多小时的时间来解决这个问题,我找不到任何东西。
使用 Powershell v2.0 我想删除任何早于 X 天的文件:
$backups = Get-ChildItem -Path $Backuppath |
Where-Object {($_.lastwritetime -lt (Get-Date).addDays(-$DaysKeep)) -and (-not $_.PSIsContainer) -and ($_.Name -like "backup*")}
foreach ($file in $backups)
{
Remove-Item $file.FullName;
}
Run Code Online (Sandbox Code Playgroud)
但是,当 $backups 为空时,我得到: Remove-Item : Cannot bind argument to parameter 'Path' because it is null.
我试过了:
if (!$backups)if (Test-Path $file -PathType Leaf)if ([IO.File]::Exists($file.FullName) -ne $true)这些似乎都不起作用,如果在列表为空时防止进入 foreach 循环的推荐方法怎么办?
我目前正在阅读 Windows PowerShell 3.0 Step by Step 书,以获取有关 PowerShell 的更多见解。
在第 201 页上,作者演示了过滤器比具有相同功能的函数更快。
这个脚本在他的电脑上需要 2.6 秒:
MeasureAddOneFilter.ps1
Filter AddOne
{
"add one filter"
$_ + 1
}
Measure-Command { 1..50000 | addOne }
Run Code Online (Sandbox Code Playgroud)
而这个 4.6 秒
MeasureAddOneFunction.ps1
Function AddOne
{
"Add One Function"
While ($input.moveNext())
{
$input.current + 1
}
}
Measure-Command { 1..50000 | addOne }
Run Code Online (Sandbox Code Playgroud)
如果我运行此代码,则会得到与他的结果完全相反的结果:
.\MeasureAddOneFilter.ps1
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 226
Ticks : 2266171
TotalDays : 2,62288310185185E-06 …Run Code Online (Sandbox Code Playgroud) 我正在 Windows 8 机器上从 PowerShell 控制台运行以下命令,尝试配置 Server 2012 R2 RDS 连接代理:
Import-Module RemoteDesktop
Set-RDSessionCollectionConfiguration -CollectionName "Example" -CustomRdpProperty "gatewayhostname:s:rdp.example.com" -ConnectionBroker "ep-ts01.ad.example.com"
Run Code Online (Sandbox Code Playgroud)
但是,即使我指定了要使用的连接代理,它也总是尝试连接到localhost:
New-PSSession : [localhost] 连接到远程服务器 localhost 失败并显示以下错误消息:clie 无法连接到请求中指定的目标。验证目标上的服务是否正在运行并正在接受请求。查阅在目标上运行的 WS-Management 服务的日志和文档,最常见的是 IIS 或 WinRM。如果目标是 WinRM 服务,则在目标上运行以下命令来分析和配置 WinRM 服务:“winrm quickconfig”。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。

但是,Get-RDSessionCollection -ConnectionBroker ep-ts01.ad.example.com工作正常并返回集合。
如果我这样做Enter-PSSession ep-ts01.ad.example.com并从那里运行它,这是同样的故事。但是,如果我从服务器本身(即不是远程)运行命令,它就可以正常工作。
我怎样才能解决这个问题?
powershell remote-desktop-services powershell-v3.0 windows-server-2012-r2
powershell ×10
windows ×2
winrm ×2
credssp ×1
exchange ×1
remoting ×1
user-profile ×1
windows-7 ×1