我们有一堆不属于域的PC(并且无法添加)。他们没有安装PS,我们宁愿不必安装它。
我想从服务器使用Powershell每小时获取2个进程的内存使用量。不幸的是,get-process似乎不支持-credential参数。我确实得到了win32_process(如下所示),但它返回了大量的信息(不知道我是如何为两个进程获取VMsize的。)
$Pass = ConvertTo-SecureString -string "SECRET" -AsPlainText –Force
$User = "USER"
$Cred = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $Pass
gwmi win32_process -computername PCName -Credential $Cred
有没有办法在不安装PS或将PC放入域的情况下执行此操作?
答案 0 :(得分:1)
您可以使用Filter
参数来限制获取信息的过程,例如:
Get-WmiObject -cn $c win32_process -Filter "Name='PowerShell.exe'" | ft Name, PrivatePageCount
答案 1 :(得分:0)
想出来。这会获得$ HostNames中列出的计算机上$ Processnames中列出的应用程序的VM和工作集大小。它检查计算机是否还活着
$Pass = ConvertTo-SecureString -string "SECRET" -AsPlainText –Force
$User = "User"
$Cred = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $Pass
$ProcessNames = @('App1.exe', 'App2.exe')
$HostList =@('Computer1','Computer2')
foreach ($CurrHost in $HostList)
{
# check if it's alive
if((Test-Connection -Cn $CurrHost -BufferSize 16 -Count 1 -ea 0 -quiet))
{
gwmi win32_process -computername $CurrHost -Credential $Cred |
Where-Object {$ProcessNames -contains $_.Name } |
Select-Object CSName, Name, WorkingSetSize, VirtualSize #|
#Format-Table -AutoSize
}
}