Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Listing facets and their properties


In this recipe, we will list all available facets and their properties.

How to do it...

Let's take a look at the steps for listing facets and their properties:

  1. Open PowerShell ISE as an administrator. Import the SQLPS module as follows:

    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
  2. Add the following script and run it:

    $result = @()
    
    [Microsoft.SqlServer.Management.Dmf.PolicyStore]::Facets |
    ForEach-Object {
       $facet = $_
       $facet.FacetProperties |
       ForEach-Object {
           $property = $_
           $item = [PSCustomObject] @{
              Name = $facet.Name
              PropertyName = $property.Name
              PropertyType = $property.PropertyType
           }
           $result += $item
       }
    }
    
    $result |
    Format-Table
  3. When the script successfully finishes executing, the resulting screen should display all the facets and their properties.

How it works...

Facets are introduced with SQL Server 2008's Policy Based Management (PBM) feature. PBM is a feature that...