Select-Object 版本 PowerShell 7.5 搜索 Invoke-Expression Invoke-RestMethod Invoke-WebRequest Join-String Measure-Command Measure-Object New-Alias New-Event New-Guid New-Object New-TemporaryFile New-TimeSpan New-Variable Out-File Out-GridView
Select-Object[[-Property] <Object[]>] [-InputObject <psobject>] [-ExcludeProperty <string[]>] [-ExpandProperty <string>] [-Unique] [-Last <int>] [-First <int>] [-Skip <int>] [-Wait] [<CommonParameters>] PowerShell Select-Object[[-Property] <Object[]>] [-InputObject <...
修改现有属性:可以使用Select-Object命令的Property参数来修改现有属性的名称。例如,假设有一个对象数组$users,每个对象包含属性FirstName和LastName,可以使用以下命令将属性名称修改为Name和Surname: 在上述命令中,@{Name="Name"; Expression={$_.FirstName}}表示将FirstName属性的名称修改为Name。 通过修改Select-Object...
(Get-Date) -$_.LastAccessTime).Days}}# You can also shorten the name of your label key to 'l' and your expression key# to 'e'.Get-ChildItem$PSHOME-File|Select-ObjectName,$size,$daysName Size(KB) Days --- --- --- Certificate.format.ps1xml12.5244140625223Diagnostics.Format.ps1xml4.955...
Get-Service | Select-Object Name, DisplayName, @{Name="LogonAccount";Expression={(Get-WmiObject -Class Win32_Service -Filter "Name='$($_.Name)'").StartName}} 这个命令将列出所有服务的名称、显示名称以及登录账户。 上一篇Service Control Manager (SCM):Windows 自带的服务控制管理器(SCM)是一个...
这样还不够细腻。我们还可以往 -Property 里面传一个hashtable对象,前一个参数是 label / l string, 表示标题,后一个对象是 expression / e scriptblock 表示 callback(用法和上图一样)来进行标题的表示: 思考1:为什么 Select-Object -Property 可以放 ScriptBlock?它是什么意思?
() }$groupResult=$groupResult|Sort-ObjectTotalMilliseconds$groupResult|Select-Object*, @{ Name ='RelativeSpeed'Expression = {$relativeSpeed=$_.TotalMilliseconds /$groupResult[0].TotalMilliseconds$speed= [Math]::Round($relativeSpeed,2).ToString() +'x'if($speed-eq'1x') {$speed}else{$speed+...
对自定义对象使用Select-Object可以根据指定参数选择指定的成员。参数有Property和ExcludeProperty。Property表示选择指定的成员,ExcludeProperty表示在Property的基础上排除指定的成员。示例如下: $O = [PSCustomObject]@{a = 1; b = 2; c = 3} Write-Host ($O | Select-Object -Property a, b) Write-Host ...
Get-ADComputer-Filter*-PropertyLastLogonTimestamp |Select-ObjectName,@{Name="LastLogonDate";Expression={[DateTime]::FromFileTime($_.LastLogonTimestamp)}} 检查计算机是否在域中: powershellCopy Code Test-ComputerSecureChannel -Verbose 这些命令可以帮助您更精确地管理和监控您的域及其计算机。
New-Module-NameMyModule-ScriptBlock{functionReturn-MrOsVersion{Get-CimInstance-ClassNameWin32_OperatingSystem |Select-Object-Property@{label='OperatingSystem';expression={$_.Caption}} }Export-ModuleMember-FunctionReturn-MrOsVersion} |Import-Module ...