我一直在使用函数将字节转换为"友好"目录的大小如下所示:
脚本:
function Get-FriendlySize {
param($Bytes)
$sizes='Bytes,KB,MB,GB,TB,PB,EB,ZB' -split ','
for($i=0; ($Bytes -ge 1kb) -and
($i -lt $sizes.Count); $i++) {$Bytes/=1kb}
$N=2; if($i -eq 0) {$N=0}
"{0:N$($N)} {1}" -f $Bytes, $sizes[$i]
}
dir 'C:\Windows\ccmsetup' | Select-Object -Property Name, LastWriteTime, @{N='FriendlySize';E={Get-FriendlySize -Bytes $_.Length}}
输出:
Name LastWriteTime FriendlySize
---- ------------- ------------
cache 7/5/2017 10:47:32 AM 1 Bytes
Logs 5/17/2018 5:18:28 PM 1 Bytes
{6EF23B21-22B7-453C-A975-52723EE71ABA} 1/7/2018 1:06:03 PM 1 Bytes
ccmsetup.cab 1/7/2018 1:04:21 PM 9.42 KB
ccmsetup.exe 11/7/2017 8:00:00 PM 3.55 MB
ccmsetup.xml 12/1/2017 3:55:00 PM 10.51 KB
CLP1031.MSP 11/9/2017 9:00:00 AM 1.77 MB
CLP1036.MSP 11/9/2017 9:00:00 AM 1.77 MB
CLP1041.MSP 11/9/2017 9:00:00 AM 1.77 MB
CLP2052.MSP 11/9/2017 9:00:00 AM 1.77 MB
configmgr1702-client-kb4019926-x64.msp 4/11/2017 11:50:00 AM 7.36 MB
MicrosoftPolicyPlatformSetup.msi 2/28/2017 9:11:22 AM 2.45 MB
SCEPInstall.exe 6/20/2016 12:54:16 PM 27.05 MB
Silverlight.exe 4/10/2017 6:34:48 PM 6.70 MB
WindowsFirewallConfigurationProvider.msi 2/28/2017 9:11:22 AM 589.00 KB
我现在尝试将相同的逻辑应用于Get-Process输出,以便内存工作集显示友好而不是默认字节,但输出始终为" 1字节。&# 34;
脚本:
function Get-FriendlySize {
param($Bytes)
$sizes='Bytes,KB,MB,GB,TB,PB,EB,ZB' -split ','
for($i=0; ($Bytes -ge 1kb) -and
($i -lt $sizes.Count); $i++) {$Bytes/=1kb}
$N=2; if($i -eq 0) {$N=0}
"{0:N$($N)} {1}" -f $Bytes, $sizes[$i]
}
Get-Process -Name explorer | Select-Object -Property Handles, @{N='RAM Working Set';E={Get-FriendlySize -Bytes $_.Length}}, CPU, Id, ProcessName
输出:
Handles : 2521
RAM Working Set : 1 Bytes
CPU : 169.125
Id : 10080
ProcessName : explorer
我做错了什么?
答案 0 :(得分:3)
您需要使用import { Component} from '@angular/core';
import { DataService } from '../../services/data.service';
@Component({
selector: 'app-slot',
template: '<app-menu id="1"></app-menu>',
styleUrls: ['./slot.component.css']
})
export class SlotComponent {
private component:string;
constructor(
public dataService : DataService
) {
}
}
来获取内存而不是$_.WorkingSet
$_.Length