Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Contoh ini memperlihatkan cara mengimplementasikan tampilan daftar yang memisahkan baris daftar ke dalam grup. Tampilan daftar ini menampilkan properti System.ServiceProcess.ServiceController objek yang dikembalikan oleh cmdlet Get-Service. Untuk informasi selengkapnya tentang komponen tampilan daftar, lihat Membuat Tampilan Daftar.
Muat file pemformatan ini
Salin XML dari bagian Contoh topik ini ke dalam file teks.
Simpan file teks. Pastikan untuk menambahkan ekstensi
format.ps1xmlke file untuk mengidentifikasinya sebagai file pemformatan.Buka Windows PowerShell, dan jalankan perintah berikut untuk memuat file pemformatan ke sesi saat ini:
Update-FormatData -PrependPath PathToFormattingFile.
Peringatan
File pemformatan ini menentukan tampilan objek yang sudah ditentukan oleh file pemformatan Windows PowerShell. Anda harus menggunakan parameter PrependPath saat menjalankan cmdlet, dan Anda tidak dapat memuat file pemformatan ini sebagai modul.
Menunjukkan
File pemformatan ini menunjukkan elemen XML berikut:
Elemen Nama untuk tampilan.
Elemen ViewSelectedBy yang menentukan objek apa yang ditampilkan oleh tampilan.
Elemen GroupBy yang menentukan bagaimana grup objek baru ditampilkan.
Elemen ListControl yang menentukan properti apa yang ditampilkan oleh tampilan.
Elemen ListItem yang menentukan apa yang ditampilkan dalam baris tampilan daftar.
Elemen PropertyName yang menentukan properti mana yang ditampilkan.
Contoh
XML berikut menentukan tampilan daftar yang memulai grup baru setiap kali nilai properti System.ServiceProcess.ServiceController.Status berubah. Saat setiap grup dimulai, label kustom ditampilkan yang menyertakan nilai baru properti.
<Configuration>
<ViewDefinitions>
<View>
<Name>System.ServiceProcess.ServiceController</Name>
<ViewSelectedBy>
<TypeName>System.ServiceProcess.ServiceController</TypeName>
</ViewSelectedBy>
<GroupBy>
<PropertyName>Status</PropertyName>
<Label>New Service Status</Label>
</GroupBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<PropertyName>Name</PropertyName>
</ListItem>
<ListItem>
<PropertyName>DisplayName</PropertyName>
</ListItem>
<ListItem>
<PropertyName>ServiceType</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>
Contoh berikut menunjukkan bagaimana Windows PowerShell menampilkan objek System.ServiceProcess.ServiceController setelah file format ini dimuat. Baris kosong yang ditambahkan sebelum dan sesudah label grup secara otomatis ditambahkan oleh Windows PowerShell.
Get-Service f*
New Service Status: Stopped
Name : Fax
DisplayName : Fax
ServiceType : Win32OwnProcess
New Service Status: Running
Name : FCSAM
DisplayName : Microsoft Antimalware Service
ServiceType : Win32OwnProcess
New Service Status: Stopped
Name : fdPHost
DisplayName : Function Discovery Provider Host
ServiceType : Win32ShareProcess
New Service Status: Running
Name : FDResPub
DisplayName : Function Discovery Resource Publication
ServiceType : Win32ShareProcess
Name : FontCache
DisplayName : Windows Font Cache Service
ServiceType : Win32ShareProcess
New Service Status: Stopped
Name : FontCache3.0.0.0
DisplayName : Windows Presentation Foundation Font Cache 3.0.0.0
ServiceType : Win32OwnProcess
New Service Status: Running
Name : FSysAgent
DisplayName : Microsoft Forefront System Agent
ServiceType : Win32OwnProcess
Name : FwcAgent
DisplayName : Firewall Client Agent
ServiceType : Win32OwnProcess
Lihat Juga
Contoh File Pemformatan