Войти

Показать полную графическую версию : [решено] выбрать после select только определенные значения поля


nokogerra
22-12-2016, 08:01
PS C:\Windows\system32> Get-VM | where {($_.name -like "*gz*") -and ($_.name -notlike "*test*")} | select name, {$_.gues
t.ipaddress}

Name $_.guest.ipaddress
---- ------------------
GZ_Integration {xxxx, 192.168.205.4}
GZ_Transport {10.33.31.50, xxxxx, 192.168.205.2}
GZ_Web {10.33.31.51, 192.168.205.3, xxxx}
GZ_App {20.0.10.12, xxxx, 192.168.205.8}
GZ_General 192.168.205.5
GZ_BD 192.168.205.7
GZ_Rep 192.168.205.6


Как добавить условие, чтобы в $_.guest.ipaddress в итоге отлистились только адреса -like "*192.168*"?

Kazun
22-12-2016, 08:54
| select name, @{n="IP";e= {$_.guest.ipaddress | ? {$_ -match "192.168"}}}

nokogerra
22-12-2016, 09:31
Спасибо. Вы не могли бы объяснить на пальцах как это работает?
@ я так понял объявление массива, но дальше не понимаю что происходит, почему 2 поля данных n и e?

Kazun
22-12-2016, 09:39
Get-Help Select-Object

-Property [<Object[]>]
Specifies the properties to select. Wildcards are permitted.

The value of the Property parameter can be a new calculated property. To create a calculated, property, use a
hash table. Valid keys are:

-- Name (or Label) <string>

-- Expression <string> or <script block>

Required? false
Position? 1
Default value none
Accept pipeline input? false
Accept wildcard characters? false




© OSzone.net 2001-2012