Bagikan melalui


Tampilan Daftar (Dasar)

Contoh ini menunjukkan cara menerapkan tampilan daftar dasar yang menampilkan 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

  1. Salin XML dari bagian Contoh topik ini ke dalam file teks.

  2. Simpan file teks. Pastikan untuk menambahkan ekstensi format.ps1xml ke file untuk mengidentifikasinya sebagai file pemformatan.

  3. 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 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 menampilkan empat properti objek System.ServiceProcess.ServiceController. Di setiap baris, nama properti ditampilkan diikuti dengan nilai properti .

<Configuration>
  <View>
    <Name>System.ServiceProcess.ServiceController</Name>
    <ViewSelectedBy>
      <TypeName>System.ServiceProcess.ServiceController</TypeName>
    </ViewSelectedBy>
    <ListControl>
      <ListEntries>
        <ListEntry>
          <ListItems>
            <ListItem>
              <PropertyName>Name</PropertyName>
            </ListItem>
            <ListItem>
              <PropertyName>DisplayName</PropertyName>
            </ListItem>
            <ListItem>
              <PropertyName>Status</PropertyName>
            </ListItem>
            <ListItem>
              <PropertyName>ServiceType</PropertyName>
            </ListItem>
          </ListItems>
        </ListEntry>
      </ListEntries>
    </ListControl>
  </View>
</Configuration>

Contoh berikut menunjukkan bagaimana Windows PowerShell menampilkan objek System.ServiceProcess.ServiceController setelah file format ini dimuat.

Get-Service f*
Name        : Fax
DisplayName : Fax
Status      : Stopped
ServiceType : Win32OwnProcess

Name        : FCSAM
DisplayName : Microsoft Antimalware Service
Status      : Running
ServiceType : Win32OwnProcess

Name        : fdPHost
DisplayName : Function Discovery Provider Host
Status      : Stopped
ServiceType : Win32ShareProcess

Name        : FDResPub
DisplayName : Function Discovery Resource Publication
Status      : Running
ServiceType : Win32ShareProcess

Name        : FontCache
DisplayName : Windows Font Cache Service
Status      : Running
ServiceType : Win32ShareProcess

Name        : FontCache3.0.0.0
DisplayName : Windows Presentation Foundation Font Cache 3.0.0.0
Status      : Stopped
ServiceType : Win32OwnProcess

Name        : FSysAgent
DisplayName : Microsoft Forefront System Agent
Status      : Running
ServiceType : Win32OwnProcess

Name        : FwcAgent
DisplayName : Firewall Client Agent
Status      : Running
ServiceType : Win32OwnProcess

Lihat Juga

Contoh File Pemformatan

Menulis File Pemformatan PowerShell