<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Indented! &#187; wmi</title>
	<atom:link href="http://www.indented.co.uk/index.php/tag/wmi/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.indented.co.uk</link>
	<description></description>
	<lastBuildDate>Fri, 02 Jul 2010 10:45:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PowerShell, IIS and log settings</title>
		<link>http://www.indented.co.uk/index.php/2010/01/12/powershell-iis-and-log-settings/</link>
		<comments>http://www.indented.co.uk/index.php/2010/01/12/powershell-iis-and-log-settings/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 10:06:45 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[IIS]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.indented.co.uk/?p=1353</guid>
		<description><![CDATA[A function to retrieve IIS log settings from a local or remote IIS 6 server. Written to be compatible with PowerShell 1.0. Function Get-IISLogSetting { Param([String[]]$Servers = $Env:Computername) $Servers &#124; %{ $Server = $_ $WMI = New-Object Management.ManagementScope(&#34;\\$Server\root\MicrosoftIISv2&#34;) $WMI.Options.Authentication = &#34;PacketPrivacy&#34; $Query = New-Object Management.ObjectQuery( ` &#34;SELECT Name, LogFileDirectory, LogFileTruncateSize, &#34; + ` &#34;LogType, LogFilePeriod [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>A function to retrieve IIS log settings from a local or remote IIS 6 server. Written to be compatible with PowerShell 1.0.<br />
<span id="more-1353"></span></p>
<pre class="brush: powershell;">
Function Get-IISLogSetting
{
  Param([String[]]$Servers = $Env:Computername)

  $Servers | %{
    $Server = $_

    $WMI = New-Object Management.ManagementScope(&quot;\\$Server\root\MicrosoftIISv2&quot;)
    $WMI.Options.Authentication = &quot;PacketPrivacy&quot;
    $Query = New-Object Management.ObjectQuery( `
      &quot;SELECT Name, LogFileDirectory, LogFileTruncateSize, &quot; + `
      &quot;LogType, LogFilePeriod FROM IIsWebServerSetting&quot;)

    $Searcher = New-Object Management.ManagementObjectSearcher($WMI, $Query)

    Trap [UnauthorizedAccessException]
    {
      Write-Error &quot;$($Server): Unable to connect or Access is denied&quot;
      continue
    }
    $Searcher.Get() | Select-Object `
      @{n='Name';e={ $Server }}, `
      @{n='Site';e={ $_.Name }}, `
      @{n='IIS Logging';e={
        Switch ($_.LogType) {
          0 { &quot;Disabled&quot; }
          1 { &quot;Enabled&quot; }
        } }}, `
      @{n='Log Path';e={ $_.LogFileDirectory }}, `
      @{n='Log File Size';e={
        If ([Int]$_.LogFileTruncateSize -eq -1) { &quot;Unlimited&quot; } else {
          &quot;$([Int]$_.LogFileTruncateSize / 1Gb) Gb&quot; } }}, `
      @{n='Log File Rollover';e={
        Switch ($_.LogFilePeriod) {
          0 { &quot;Size&quot; }
          1 { &quot;Date&quot; }
        } }}
  }
}
</pre>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2010/01/12/powershell-iis-and-log-settings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reading share security with PowerShell</title>
		<link>http://www.indented.co.uk/index.php/2009/02/20/reading-share-security-with-powershell/</link>
		<comments>http://www.indented.co.uk/index.php/2009/02/20/reading-share-security-with-powershell/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 17:31:23 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[acl]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[securitydescriptor]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=972</guid>
		<description><![CDATA[The cmdlet Get-ACL is very capable when it comes to NTFS permissions, but it cannot read share permissions. This function makes an effort to provide a simple way to return share security (and other information) from a share. The function makes use of two WMI Classes, Win32_Share and Win32_LogicalShareSecuritySetting. To simplify enumeration each Access Control [...]


Related posts:<ol><li><a href='http://www.indented.co.uk/index.php/2009/10/02/get-dsacl/' rel='bookmark' title='Permanent Link: Get-DsAcl'>Get-DsAcl</a> <small>The goal of this PowerShell function is to create a...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>The cmdlet Get-ACL is very capable when it comes to NTFS permissions, but it cannot read share permissions. This function makes an effort to provide a simple way to return share security (and other information) from a share.<br />
<span id="more-972"></span><br />
The function makes use of two WMI Classes, Win32_Share and Win32_LogicalShareSecuritySetting. To simplify enumeration each Access Control Entry found within the shares Discretionary Access Control List is converted to a FileSystemAccessRule before being added to the Access object, allowing the access to be displayed in a similar way to Access from Get-ACL.</p>
<p>Security information is only returned for shares of type 0, standard shared folders. Security for automatically generated administrative shares will not show. Access is added to the remainder of the information returned by Win32_Share. The Control Flags for the security descriptor are available, but not interesting as they are set to DiscretionaryAclPresent and SelfRelative.</p>
<p>The function accepts two parameters, the name of the share, and optionally the name of a computer. With no parameters, information for all shares on the computer is returned. WQL wildcards are supported (% and _) within the share name.</p>
<h4>Get-ShareACL</h4>
<pre class="brush: powershell;">
Function Get-ShareACL {
  Param(
    [String]$Name = &quot;%&quot;,
    [String]$Computer = $Env:ComputerName
  )

  $Shares = @()
  Get-WMIObject Win32_Share `
    -Computer $Computer -Filter &quot;Name LIKE '$Name'&quot; | `
    %{
      $Access = @();
      If ($_.Type -eq 0) {
        $SD = (Get-WMIObject -Class Win32_LogicalShareSecuritySetting `
          -Computer $Computer `
          -Filter &quot;Name='$($_.Name)'&quot;).GetSecurityDescriptor().Descriptor
        $SD.DACL | %{
          $Trustee = $_.Trustee.Name
          If ($_.Trustee.Domain -ne $Null) {
            $Trustee = &quot;$($_.Trustee.Domain)\$Trustee&quot;
          }
          $Access += New-Object Security.AccessControl.FileSystemAccessRule( `
            $Trustee, $_.AccessMask, $_.AceType)
        }
      }
      $_ | Select-Object Name, Path, Description, Caption, `
        @{n='Type';e={ Switch ($_.Type) {
          0 { &quot;Disk Drive&quot; }
          1 { &quot;Print Queue&quot; }
          2 { &quot;Device&quot; }
          2147483648 { &quot;Disk Drive Admin&quot; }
          2147483649 { &quot;Print Queue Admin&quot; }
          2147483650 { &quot;Device Admin&quot; }
          2147483651 { &quot;IPC Admin&quot; } }} }, `
        MaximumAllowed, AllowMaximum, Status, InstallDate, `
        @{n='Access';e={ $Access }}
  }
}
</pre>
<h4>Example</h4>
<pre class="brush: plain;">
PS C:\&gt; Get-ShareACL Test

Name           : Test
Path           : C:\Test
Description    :
Caption        : Test
Type           : Disk Drive
MaximumAllowed :
AllowMaximum   : True
Status         : OK
InstallDate    :
Access         : {System.Security.AccessControl.FileSystemAccessRule}

PS C:\&gt; (Get-ShareACL Test).Access

FileSystemRights  : ReadAndExecute
AccessControlType : Allow
IdentityReference : somedomain\chrisdent
IsInherited       : False
InheritanceFlags  : None
PropagationFlags  : None
</pre>


<p>Related posts:<ol><li><a href='http://www.indented.co.uk/index.php/2009/10/02/get-dsacl/' rel='bookmark' title='Permanent Link: Get-DsAcl'>Get-DsAcl</a> <small>The goal of this PowerShell function is to create a...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2009/02/20/reading-share-security-with-powershell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Reading NTFS and Share security with VbScript</title>
		<link>http://www.indented.co.uk/index.php/2009/02/19/reading-ntfs-and-share-security-with-vbscript/</link>
		<comments>http://www.indented.co.uk/index.php/2009/02/19/reading-ntfs-and-share-security-with-vbscript/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 17:25:25 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[VbScript]]></category>
		<category><![CDATA[acl]]></category>
		<category><![CDATA[ntfs]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[securitydescriptor]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=908</guid>
		<description><![CDATA[NTFS (File System) and Share security can be enumerated using the Win32_LogicalFileSecuritySetting and Win32_LogicalShareSecuritySetting WMI classes. This post demonstrates how to use each class to read the security descriptors. In each case the WMI class contains a GetSecurityDescriptor method used to retrieve the Security Descriptor (as a Win32_SecurityDescriptor). The references section at the bottom of [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>NTFS (File System) and Share security can be enumerated using the Win32_LogicalFileSecuritySetting and Win32_LogicalShareSecuritySetting WMI classes. This post demonstrates how to use each class to read the security descriptors.<br />
<span id="more-908"></span><br />
In each case the WMI class contains a GetSecurityDescriptor method used to retrieve the Security Descriptor (as a Win32_SecurityDescriptor).</p>
<p>The references section at the bottom of this article include details of sources for all constants. A little PowerShell creeps in to show how the numeric values were retrieved and checked.</p>
<h3>DACLs and SACLs</h3>
<p>A DACL or Discretionary Access Control List is the most heavily used, it contains Access Control Entries that define who can, and who cannot, access a resource or object. These are seen when viewing the Security tab of an object.</p>
<p>An SACL or System Access Control List defines which actions will be audited when accessing an a resource or object. Seen by accessing the Audit tab through Security and Advanced.</p>
<h3>NTFS security vs Share security</h3>
<p>Both the NTFS and the Share security descriptor can be read in exactly the same way. However, there are important differences between them.</p>
<h4>NTFS security descriptor</h4>
<ul>
<li>Supports inheritance on descriptor and on individual Access Control Entries</li>
<li>Can hold a Discretionary Access Control List and an System Access Control List</li>
</ul>
<h4>Share security descriptor</h4>
<ul>
<li>Has no owner or Primary Group</li>
<li>Control flags will be set (and usually limited) to SelfRelative and DiscretionaryACLPresent</li>
<li>Access Control Entry (ACE) Flags will not be set</li>
<li>Can hold a Discretionary Access Control List only</li>
<li>Supports a sub-set of Access Masks (rights) on each ACE</li>
</ul>
<h3>Getting the security descriptor</h3>
<h4>NTFS</h4>
<pre class="brush: vb;">
Dim strComputer : strComputer = &quot;.&quot;
' Connect to WMI on strComputer
Dim objWMI : Set objWMI = GetObject(&quot;winmgmts://&quot; &amp; strComputer &amp; &quot;/root/cimv2&quot;)
' Get an instance of LogicalFileSecuritySetting for C:\
Dim objSecuritySettings : Set objSecuritySettings = _
  objWMI.Get(&quot;Win32_LogicalFileSecuritySetting='C:\'&quot;)
Dim intReturnValue : Dim objSD
' Request the Security Descriptor as objSD
intReturnValue = objSecuritySettings.GetSecurityDescriptor objSD
</pre>
<h4>Share</h4>
<pre class="brush: vb;">
Dim strComputer : strComputer = &quot;.&quot;
' Connect to WMI on strComputer
Dim objWMI : Set objWMI = GetObject(&quot;winmgmts://&quot; &amp; strComputer &amp; &quot;/root/cimv2&quot;)
' Get an instance of LogicalShareSecuritySetting for ShareName
Dim objSecuritySettings : Set objSecuritySettings = _
  objWMI.Get(&quot;Win32_LogicalShareSecuritySetting='ShareName'&quot;)
Dim intReturnValue : Dim objSD
' Request the Security Descriptor as objSD
intReturnValue = objSecuritySettings.GetSecurityDescriptor objSD
</pre>
<h4>Error handling</h4>
<p>The GetSecurityDescriptor method of each WMI class (Win32_LogicalFileSecuritySetting and Win32_LogicalShareSecuritySetting) has a return value to allow errors to be handled. The return codes are represented by the constants below.</p>
<pre class="brush: vb;">
Const SUCCESS = 0
Const ACCESS_DENIED = 2
Const UNKNOWN_FAILURE = 8
Const PRIVILEGE_MISSING = 9
Const INVALID_PARAMETER = 21
</pre>
<h3>Values in the security descriptor</h3>
<p>The security descriptor contains three fields in addition to the DACL and SACL which are described later.</p>
<h4>Control flags</h4>
<p>Each security descriptor has a ControlFlags field which dictates how the descriptor behaves. This includes settings such as DACLProtected which indicates that the DACL cannot inherit values from a parent.</p>
<p>The script loads the values above into a Scripting.Dictionary object to simplify enumeration.</p>
<pre class="brush: vb;">
Dim objControlFlags : Set objControlFlags = CreateObject(&quot;Scripting.Dictionary&quot;)
objControlFlags.Add 32768, &quot;SelfRelative&quot;
objControlFlags.Add 16384, &quot;RMControlValid&quot;
objControlFlags.Add 8192, &quot;SystemAclProtected&quot;
objControlFlags.Add 4096, &quot;DiscretionaryAclProtected&quot;
objControlFlags.Add 2048, &quot;SystemAclAutoInherited&quot;
objControlFlags.Add 1024, &quot;DiscretionaryAclAutoInherited&quot;
objControlFlags.Add 512, &quot;SystemAclAutoInheritRequired&quot;
objControlFlags.Add 256, &quot;DiscretionaryAclAutoInheritRequired&quot;
objControlFlags.Add 32, &quot;SystemAclDefaulted&quot;
objControlFlags.Add 16, &quot;SystemAclPresent&quot;
objControlFlags.Add 8, &quot;DiscretionaryAclDefaulted&quot;
objControlFlags.Add 4, &quot;DiscretionaryAclPresent&quot;
objControlFlags.Add 2, &quot;GroupDefaulted&quot;
objControlFlags.Add 1, &quot;OwnerDefaulted&quot;
</pre>
<p>Note that they are intentionally entered in order from highest to lowest. A For Each loop will start with the highest value (because it was added first), then compare it to the ControlFlags value. In bitwise comparison, if the integer value can be there, then it must be there, that would all go wrong unless it starts with the highest possible value.</p>
<p>The values and names were taken from the .NET Framework, they can be displayed in PowerShell with the following command.</p>
<pre class="brush: powershell;">
[Enum]::GetValues([System.Security.AccessControl.ControlFlags]) | `
  Select-Object @{ n='Name';e={[String]$_} }, @{ n='Value';e={$_.value__} }
</pre>
<p>That logic is applied within the code as follows.</p>
<pre class="brush: vb;">
' Read the value of Control Flags from the descriptor
dblControlFlags = objSD.ControlFlags
WScript.Echo &quot;Control Flags:&quot;
' For each possible flag
For Each dblFlag in objControlFlags
  ' If it is possible for the flag to be there, then it must be there
  ' Something like bitwise AND
  If dblControlFlags &gt;= dblFlag Then
    ' Echo the flag, indicating it is present
    WScript.Echo &quot;  &quot; &amp; objControlFlags(dblFlag)
    ' Remove this value from the control flag value,
    ' already found this flag
    dblControlFlags = dblControlFlags - dblFlag
  End If
Next
</pre>
<h4>Primary group</h4>
<p>The Primary Group is not very interesting unless Services for Unix is in use. In many cases it will be blank.</p>
<p>If set, it can be enumerated as a Win32_Trustee, an object containing a Domain, Username, SID array, SID length and SIDString.</p>
<h4>Owner</h4>
<p>As with the Primary Group, the owner is stored as a Win32_Trustee object. It can be read from the descriptor as follows.</p>
<pre class="brush: vb;">
WScript.Echo &quot;Domain: &quot; &amp; objSD.Owner.Domain
WScript.Echo &quot;Username: &quot; &amp; objSD.Owner.Name
WScript.Echo &quot;SID: &quot; &amp; objSD.Owner.SIDString
</pre>
<h3>Access control entries in the DACL and SACL</h3>
<p>Both the DACL and SACL, if present, consist of one or more Access Control Entries (ACE). The ACE, like the security descriptor, breaks down into a number of different fields.</p>
<h4>Access Mask</h4>
<p>The access mask defines which rights should be used by the Access Control Entry. In the case of System ACL it defines which actions should be audited.</p>
<p>A number of the right names are omitted from the list below as they carry the same numeric value (mask the same bit), the meaning only changes in the context the right is applied.</p>
<pre class="brush: vb;">
Dim objAccessRights : Set objAccessRights = CreateObject(&quot;Scripting.Dictionary&quot;)
objAccessRights.Add 2032127, &quot;FullControl&quot;
objAccessRights.Add 1048576, &quot;Synchronize&quot;
objAccessRights.Add 524288, &quot;TakeOwnership&quot;
objAccessRights.Add 262144, &quot;ChangePermissions&quot;
objAccessRights.Add 197055, &quot;Modify&quot;
objAccessRights.Add 131241, &quot;ReadAndExecute&quot;
objAccessRights.Add 131209, &quot;Read&quot;
objAccessRights.Add 131072, &quot;ReadPermissions&quot;
objAccessRights.Add 65536, &quot;Delete&quot;
objAccessRights.Add 278, &quot;Write&quot;
objAccessRights.Add 256, &quot;WriteAttributes&quot;
objAccessRights.Add 128, &quot;ReadAttributes&quot;
objAccessRights.Add 64, &quot;DeleteSubdirectoriesAndFiles&quot;
objAccessRights.Add 32, &quot;ExecuteFile&quot;
objAccessRights.Add 16, &quot;WriteExtendedAttributes&quot;
objAccessRights.Add 8, &quot;ReadExtendedAttributes&quot;
objAccessRights.Add 4, &quot;AppendData&quot;
objAccessRights.Add 2, &quot;CreateFiles&quot;
objAccessRights.Add 1, &quot;ReadData&quot;
</pre>
<p>Note that a number of the rights in the list are composites of simpler rights, including Read, FullControl, Write and Modify.</p>
<p>The list can be retrieved, using PowerShell again, with the following command:</p>
<pre class="brush: powershell;">
[Enum]::GetValues([System.Security.AccessControl.FileSystemRights]) | `
  Select-Object @{n='Name';e={[String]$_} }, @{n='Value';e={$_.value__} }
</pre>
<p>Holding the flags in this fashion allows the Access Mask to be converted to a friendly form in the same way as the Control Flags were displayed.</p>
<pre class="brush: vb;">
' For each access control entry in the discretionary access control list
For Each objACE in objSD.DACL
  WScript.Echo &quot;Access Mask:&quot;
  ' Read the value of the access mask from the Access Control Entry
  dblAccessMask = objACE.AccessMask
  ' For each possible Right
  For Each dblAccess in objAccessRights
    ' If the right can be there then it must...
    If dblAccessMask &gt;= dblAccess Then
      ' Echo the right name
      WScript.Echo &quot;  &quot; &amp; objAccessRights(dblAccess)
      ' Remove the value from the access mask,
      ' already found this right.
      dblAccessMask = dblAccessMask - dblAccess
    End If
  Next
Next
</pre>
<h4>Flags</h4>
<p>The flags on an Access Control Entry defines whether the entry applies to Leaf or Container objects, how it behaves when inheritance is calculated, and whether or not the ACE is inherited or explicit.</p>
<pre class="brush: vb;">
Dim objAceFlags : Set objAceFlags = CreateObject(&quot;Scripting.Dictionary&quot;)
objAceFlags.Add 128, &quot;FailedAccess&quot;
objAceFlags.Add 64, &quot;SuccessfulAccess&quot;
objAceFlags.Add 16, &quot;Inherited&quot;
objAceFlags.Add 8, &quot;InheritOnly&quot;
objAceFlags.Add 4, &quot;NoPropagateInherit&quot;
objAceFlags.Add 2, &quot;ContainerInherit&quot;
objAceFlags.Add 1, &quot;ObjectInherit&quot;
</pre>
<p>Heading back to PowerShell again we can find the the names and values for these.</p>
<pre class="brush: powershell;">
[Enum]::GetValues([System.Security.AccessControl.AceFlags]) | `
  Select-Object @{n='Name';e={[String]$_} }, @{n='Value';e={$_.value__} }
</pre>
<p>A few are intentionally left out as they are composites of values more interesting to display separately.</p>
<p>Enumeration of the Access Control Entry flags is performed as follows.</p>
<pre class="brush: vb;">
' For each access control entry in the discretionary access control list
For Each objACE in objSD.DACL
  WScript.Echo &quot;ACE Flags:&quot;
    ' Read the value of ACE Flags from the Access Control Entry
  dblAceFlags = objAce.AceFlags
  ' For each possible flag
  For Each dblFlag in objAceFlags
    ' If the flag can be there then it must...
    If dblAceFlags &gt;= dblFlag Then
      ' Echo the name of the flag
      WScript.Echo &quot;  &quot; &amp; objAceFlags(dblFlag)
      ' Found it, remove it to note that it has been found.
      dblAceFlags = dblAceFlags - dblFlag
    End If
  Next
Next
</pre>
<h4>Trustee</h4>
<p>The value for the trustee (Win32_Trustee), the security principal (user, group, computer, etc) the right applies to is enumerated in the same way as the Owner above.</p>
<pre class="brush: vb;">
For Each objACE in objDACL
  WScript.Echo &quot;Domain: &quot; &amp; objACE.Trustee.Domain
  WScript.Echo &quot;User: &quot; &amp; objACE.Trustee.Name
  WScript.Echo &quot;SID: &quot; &amp; objACE.Trustee.SIDString
Next
</pre>
<h4>Type</h4>
<p>Finally, the ACEType consists of three values which define whether the ACE permits access, denies access or is an audit control.</p>
<pre class="brush: vb;">
Dim objAceTypes : Set objAceTypes = CreateObject(&quot;Scripting.Dictionary&quot;)
objAceTypes.Add 0, &quot;Allow&quot;
objAceTypes.Add 1, &quot;Deny&quot;
objAceTypes.Add 2, &quot;Audit&quot;
</pre>
<p>Once again, we can discover all of the possible values for AceFlags using PowerShell.</p>
<pre class="brush: powershell;">
[Enum]::GetValues([System.Security.AccessControl.AceType]) | `
  Select-Object @{n='Name';e={[String]$_} }, @{n='Value';e={$_.value__} }
</pre>
<p>However, this time the only values that are used in the script are 0 (Allow), 1 (Deny), and 2 (Audit).</p>
<pre class="brush: vb;">
' For each access control entry in the discretionary access control list
For Each objACE in objDACL
  ' Echo the type: Allow, Deny or Audit.
  WScript.Echo &quot;ACE Type: &quot; &amp; objAceTypes(objAce.AceType)
Next
</pre>
<h3>Listing permissions for all Shares</h3>
<p>Time to put all of that together. This sample lists the NTFS and Share permissions for each share configured on strComputer.</p>
<pre class="brush: vb;">
Option Explicit

' WMI Constants

Const WBEM_RETURN_IMMEDIATELY = &amp;h10
Const WBEM_FORWARD_ONLY = &amp;h20

' Constants and storage arrays for security settings

' GetSecurityDescriptor Return values

Dim objReturnCodes : Set objReturnCodes = CreateObject(&quot;Scripting.Dictionary&quot;)
Const SUCCESS = 0
Const ACCESS_DENIED = 2
Const UNKNOWN_FAILURE = 8
Const PRIVILEGE_MISSING = 9
Const INVALID_PARAMETER = 21

' Security Descriptor Control Flags

Dim objControlFlags : Set objControlFlags = CreateObject(&quot;Scripting.Dictionary&quot;)
objControlFlags.Add 32768, &quot;SelfRelative&quot;
objControlFlags.Add 16384, &quot;RMControlValid&quot;
objControlFlags.Add 8192, &quot;SystemAclProtected&quot;
objControlFlags.Add 4096, &quot;DiscretionaryAclProtected&quot;
objControlFlags.Add 2048, &quot;SystemAclAutoInherited&quot;
objControlFlags.Add 1024, &quot;DiscretionaryAclAutoInherited&quot;
objControlFlags.Add 512, &quot;SystemAclAutoInheritRequired&quot;
objControlFlags.Add 256, &quot;DiscretionaryAclAutoInheritRequired&quot;
objControlFlags.Add 32, &quot;SystemAclDefaulted&quot;
objControlFlags.Add 16, &quot;SystemAclPresent&quot;
objControlFlags.Add 8, &quot;DiscretionaryAclDefaulted&quot;
objControlFlags.Add 4, &quot;DiscretionaryAclPresent&quot;
objControlFlags.Add 2, &quot;GroupDefaulted&quot;
objControlFlags.Add 1, &quot;OwnerDefaulted&quot;

' ACE Access Right

Dim objAccessRights : Set objAccessRights = CreateObject(&quot;Scripting.Dictionary&quot;)
objAccessRights.Add 2032127, &quot;FullControl&quot;
objAccessRights.Add 1048576, &quot;Synchronize&quot;
objAccessRights.Add 524288, &quot;TakeOwnership&quot;
objAccessRights.Add 262144, &quot;ChangePermissions&quot;
objAccessRights.Add 197055, &quot;Modify&quot;
objAccessRights.Add 131241, &quot;ReadAndExecute&quot;
objAccessRights.Add 131209, &quot;Read&quot;
objAccessRights.Add 131072, &quot;ReadPermissions&quot;
objAccessRights.Add 65536, &quot;Delete&quot;
objAccessRights.Add 278, &quot;Write&quot;
objAccessRights.Add 256, &quot;WriteAttributes&quot;
objAccessRights.Add 128, &quot;ReadAttributes&quot;
objAccessRights.Add 64, &quot;DeleteSubdirectoriesAndFiles&quot;
objAccessRights.Add 32, &quot;ExecuteFile&quot;
objAccessRights.Add 16, &quot;WriteExtendedAttributes&quot;
objAccessRights.Add 8, &quot;ReadExtendedAttributes&quot;
objAccessRights.Add 4, &quot;AppendData&quot;
objAccessRights.Add 2, &quot;CreateFiles&quot;
objAccessRights.Add 1, &quot;ReadData&quot;

' ACE Types

Dim objAceTypes : Set objAceTypes = CreateObject(&quot;Scripting.Dictionary&quot;)
objAceTypes.Add 0, &quot;Allow&quot;
objAceTypes.Add 1, &quot;Deny&quot;
objAceTypes.Add 2, &quot;Audit&quot;

' ACE Flags

Dim objAceFlags : Set objAceFlags = CreateObject(&quot;Scripting.Dictionary&quot;)
objAceFlags.Add 128, &quot;FailedAccess&quot;
objAceFlags.Add 64, &quot;SuccessfulAccess&quot;
objAceFlags.Add 16, &quot;Inherited&quot;
objAceFlags.Add 8, &quot;InheritOnly&quot;
objAceFlags.Add 4, &quot;NoPropagateInherit&quot;
objAceFlags.Add 2, &quot;ContainerInherit&quot;
objAceFlags.Add 1, &quot;ObjectInherit&quot;

Sub ReadNTFSSecurity(objWMI, strPath)
  WScript.Echo &quot;  Displaying NTFS Security&quot;

  Dim objSecuritySettings : Set objSecuritySettings = _
    objWMI.Get(&quot;Win32_LogicalFileSecuritySetting='&quot; &amp; strPath &amp; &quot;'&quot;)
  Dim objSD : objSecuritySettings.GetSecurityDescriptor objSD

  Dim strDomain : strDomain = objSD.Owner.Domain
  If strDomain &lt;&gt; &quot;&quot; Then strDomain = strDomain &amp; &quot;\&quot;
  WScript.Echo &quot;  Owner: &quot; &amp; strDomain &amp; objSD.Owner.Name
  WScript.Echo &quot;  Owner SID: &quot; &amp; objSD.Owner.SIDString

  WScript.Echo &quot;  Basic Control Flags Value: &quot; &amp; objSD.ControlFlags
  WScript.Echo &quot;  Control Flags:&quot;

  DisplayValues objSD.ControlFlags, objControlFlags

  WScript.Echo

  Dim objACE

  ' Display the DACL

  WScript.Echo &quot;  Discretionary Access Control List:&quot;
  For Each objACE in objSD.DACL
    DisplayACE objACE
  Next

  ' Display the SACL (if there is one)

  If Not IsNull(objSD.SACL) Then
    WScript.Echo &quot;  System Access Control List:&quot;
    For Each objACE in objSD.SACL
      DisplayACE objACE
    Next
  End If
End Sub

Sub ReadShareSecurity(objWMI, strName)
  WScript.Echo &quot;  Displaying Share Security&quot;

  Dim objSecuritySettings : Set objSecuritySettings = _
    objWMI.Get(&quot;Win32_LogicalShareSecuritySetting='&quot; &amp; strName &amp; &quot;'&quot;)

  Dim objSD : objSecuritySettings.GetSecurityDescriptor objSD

  WScript.Echo &quot;  Basic Control Flags Value: &quot; &amp; objSD.ControlFlags
  WScript.Echo &quot;  Control Flags:&quot;

  DisplayValues objSD.ControlFlags, objControlFlags

  WScript.Echo

  Dim objACE

  ' Display the DACL

  WScript.Echo &quot;  Discretionary Access Control List:&quot;
  For Each objACE in objSD.DACL
    DisplayACE objACE
  Next
End Sub

Sub DisplayValues(dblValues, objSecurityEnumeration)

  Dim dblValue
  For Each dblValue in objSecurityEnumeration
    If dblValues &gt;= dblValue Then
      WScript.Echo &quot;      &quot; &amp; objSecurityEnumeration(dblValue)
      dblValues = dblValues - dblValue
    End If
  Next
End Sub

Sub DisplayACE(objACE)

  Dim strDomain : strDomain = objAce.Trustee.Domain
  If strDomain &lt;&gt; &quot;&quot; Then strDomain = strDomain &amp; &quot;\&quot;
  WScript.Echo &quot;    Trustee: &quot; &amp; UCase(strDomain &amp; objAce.Trustee.Name)
  WScript.Echo &quot;    SID: &quot; &amp; objAce.Trustee.SIDString

  WScript.Echo &quot;    Basic Access Mask Value: &quot; &amp; objACE.AccessMask

  WScript.Echo &quot;    Access Rights: &quot;
  DisplayValues objACE.AccessMask, objAccessRights

  WScript.Echo &quot;    Type: &quot; &amp; objAceTypes(objACE.AceType)

  WScript.Echo &quot;    Basic ACE Flags Value: &quot; &amp; objACE.AceFlags

  WScript.Echo &quot;    ACE Flags: &quot;
  DisplayValues objACE.AceFlags, objAceFlags
  WScript.Echo
End Sub

'
' Main Code
'

' The system to execute this script against
Dim strComputer : strComputer = &quot;.&quot;

' Connect to WMI
Dim objWMI : Set objWMI = GetObject(&quot;winmgmts:\\&quot; &amp; strComputer &amp; &quot;\root\CIMV2&quot;)

' Return all of the shares (Type = 0 means File Shares only, exclude
' are Administrative, Printer, etc)
Dim colItems : Set colItems = _
  objWMI.ExecQuery(&quot;SELECT * FROM Win32_Share WHERE Type='0'&quot;, &quot;WQL&quot;, _
  WBEM_RETURN_IMMEDIATELY + WBEM_FORWARD_ONLY)

Dim objItem
For Each objItem in colItems
  WScript.Echo
  WScript.Echo &quot;Security for &quot; &amp; objItem.Path &amp; _
    &quot; (Shared as &quot; &amp; objItem.Name &amp; &quot;)&quot;

  ReadNTFSSecurity objWMI, objItem.Path
  ReadShareSecurity objWMI, objItem.Name
Next
</pre>
<h4>References</h4>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/aa394180(VS.85).aspx">Win32_LogicalFileSecuritySetting</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/aa394188(VS.85).aspx">Win32_LogicalShareSecuritySetting</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/aa394402(VS.85).aspx">Win32_SecurityDescriptor</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/aa394063(VS.85).aspx">Win32_ACE</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/aa394501(VS.85).aspx">Win32_Trustee</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.controlflags.aspx">ControlFlags Enumeration</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesystemrights.aspx">FileSystemRights Enumeration</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.aceflags.aspx">AceFlags Enumeration</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.acetype.aspx">AceType Enumeration</a></li>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2009/02/19/reading-ntfs-and-share-security-with-vbscript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Get-MailboxStatistics for Exchange 2003</title>
		<link>http://www.indented.co.uk/index.php/2009/01/22/exchange-2003-get-mailboxstatistics/</link>
		<comments>http://www.indented.co.uk/index.php/2009/01/22/exchange-2003-get-mailboxstatistics/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 17:35:54 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Exchange]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[DirectorySearcher]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=871</guid>
		<description><![CDATA[Using PowerShell to create a version of Get-MailboxStatistics for Exchange 2003. Get-MailboxStatistics returns a set of information about a mailbox for Exchange 2007. It is possible to retrieve roughly the same information using WMI for Exchange 2003. The differences The following table notes the differences in property names between Exchange 2003 and Exchange 2007. Exchange [...]


Related posts:<ol><li><a href='http://www.indented.co.uk/index.php/2010/01/22/changing-the-primary-group-with-powershell/' rel='bookmark' title='Permanent Link: Changing the Primary Group with PowerShell'>Changing the Primary Group with PowerShell</a> <small>Exactly as the title says, an example of how to...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Using PowerShell to create a version of Get-MailboxStatistics for Exchange 2003.<br />
<span id="more-871"></span><br />
Get-MailboxStatistics returns a set of information about a mailbox for Exchange 2007. It is possible to retrieve roughly the same information using WMI for Exchange 2003.</p>
<h3>The differences</h3>
<p>The following table notes the differences in property names between Exchange 2003 and Exchange 2007.</p>
<table>
<tr>
<th>Exchange 2007</th>
<th>Exchange 2003</th>
</tr>
<tr>
<td>AssociatedItemCount</td>
<td>AssocContentCount</td>
</tr>
<tr>
<td>DeletedItemCount</td>
<td><i>Not available</i></td>
</tr>
<tr>
<td>DisconnectDate</td>
<td>DateDiscoveredAbsentInDS</td>
</tr>
<tr>
<td>DisplayName</td>
<td>MailboxDisplayName</td>
</tr>
<tr>
<td>ItemCount</td>
<td>TotalItems</td>
</tr>
<tr>
<td>ObjectClass</td>
<td>Can be assumed to be Mailbox</td>
</tr>
<tr>
<td>StorageLimitStatus</td>
<td>StorageLimitInfo</td>
</tr>
<tr>
<td>TotalDeletedItemSize</td>
<td>DeletedMessageSizeExtended</td>
</tr>
<tr>
<td>TotalItemSize</td>
<td>Size</td>
</tr>
<tr>
<td>Database</td>
<td>Composed of Server, Storage Group and Store</td>
</tr>
<tr>
<td>DatabaseName</td>
<td>StoreName</td>
</tr>
<tr>
<td>Identity</td>
<td>MailboxGuid (repeat of above included for pipeline)</td>
</tr>
<tr>
<td>IsValid</td>
<td><i>Not available</i></td>
</tr>
<tr>
<td>OriginatingServer</td>
<td>Same as ServerName</td>
</tr>
</table>
<p>In addition to these the MailboxGuid attribute is formatted slightly differently. The MailboxGuid is enclosed in curly braces, {}, these are stripped in the code (or added when a search is being performed using a GUID)</p>
<p>No formatting is applied to the output. The output from this function can be made to look like the Exchange 2007 version of Get-MailboxStatistics by using Format-Table.</p>
<pre class="brush: powershell;">
Get-2003MailboxStatistics | Format-Table MailboxDisplayName, TotalItems, `
  StorageLimitStatus, LastLogonTime
</pre>
<p>This is the code for the function, it is not as flexible as the Exchange 2007 version with regard to pipelines, but it should accept simple input and work in much the same way otherwise.</p>
<h3>Usage examples</h3>
<pre class="brush: powershell;">
# With a Mailbox Display Name
Get-2003MailboxStatistics &quot;Chris Dent&quot;
# With a Legacy Exchange DN (&quot;-Identity&quot; itself is optional)
Get-2003MailboxStatistics -Identity &quot;/O=SomeOrg/OU=AdminGroup/CN=RECIPIENTS/CN=Someone&quot;
# For a single Mailbox Database
Get-2003MailboxStatistics -Database &quot;Mailbox Database&quot;
# For a different server
Get-2003MailboxStatistics -Server &quot;ExchangeServer02&quot;
</pre>
<h3>Get-MailboxStatistics for Exchange 2003</h3>
<pre class="brush: powershell;">
Function Get-2003MailboxStatistics {
  Param(
     [String]$Identity = &quot;&quot;,
     [String]$Server = $Env:ComputerName,
     [String]$Database = &quot;&quot;
  )

  $Filter = &quot;ServerName='$Server'&quot;
  if ($Database -ne &quot;&quot; ) {
    $Filter = &quot;$Filter AND StoreName='$Database'&quot;
  }
  if ($Identity -ne &quot;&quot;) {
    $Filter = &quot;$Filter AND (MailboxGuid='{$Identity}' OR LegacyDN='$Identity'&quot;
    $Filter = &quot;$Filter OR MailboxDisplayName='$Identity')&quot;
  }

  Get-WMIObject -ComputerName $Server `
    -Namespace &quot;root/MicrosoftExchangeV2&quot; -Class &quot;Exchange_Mailbox&quot; `
    -Filter $Filter | `
  Select-Object `
    AssocContentCount, `
    @{n='DateDiscoveredAbsentInDs';e={
      If ($_.DateDiscoveredAbsentInDs -ne $Null) {
        [Management.ManagementDateTimeConverter]::ToDateTime(`
          $_.DateDiscoveredAbsentInDs)
      }} }, `
    MailboxDisplayName, TotalItems, LastLoggedOnUserAccount, `
    @{n='LastLogonTime';e={ if ($_.LastLogonTime -ne $Null) { `
      [Management.ManagementDateTimeConverter]::ToDateTime($_.LastLogonTime)}}
    }, `
    @{n='LastLogoffTime';e={ if ($_.LastLogoffTime -ne $Null) { `
      [Management.ManagementDateTimeConverter]::ToDateTime($_.LastLogoffTime)}}
    }, `
    LegacyDN, `
    @{n='MailboxGuid';e={
      ([String]$_.MailboxGuid).ToLower() -Replace &quot;\{|\}&quot; }}, `
    @{n='ObjectClass';e={ &quot;Mailbox&quot; }}, `
    @{n='StorageLimitStatus';e={ `
      Switch ($_.StorageLimitInfo) {
        1 { &quot;BelowLimit&quot; }
        2 { &quot;IssueWarning&quot; }
        4 { &quot;ProhibitSend&quot; }
        8 { &quot;NoChecking&quot; }
        16 { &quot;MailboxDisabled&quot; } }} }, `
    DeletedMessageSize, Size, `
    @{n='Database';e={
      &quot;$($_.ServerName)\$($_.StorageGroupName)\$($_.StoreName)&quot; }}, `
    ServerName, StorageGroupName, StoreName, `
    @{n='Identity';e={ ([String]$_.MailboxGuid).ToLower() -Replace &quot;\{|\}&quot; }}
}
</pre>


<p>Related posts:<ol><li><a href='http://www.indented.co.uk/index.php/2010/01/22/changing-the-primary-group-with-powershell/' rel='bookmark' title='Permanent Link: Changing the Primary Group with PowerShell'>Changing the Primary Group with PowerShell</a> <small>Exactly as the title says, an example of how to...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2009/01/22/exchange-2003-get-mailboxstatistics/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Administering Microsoft DNS in PowerShell</title>
		<link>http://www.indented.co.uk/index.php/2008/12/30/administering-microsoft-dns-in-powershell/</link>
		<comments>http://www.indented.co.uk/index.php/2008/12/30/administering-microsoft-dns-in-powershell/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 12:35:50 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Microsoft DNS]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VB .NET]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=636</guid>
		<description><![CDATA[DNS administration in PowerShell, including tasks like creating zones and adding Host (A) records, can be performed using the WMI interface. Full documentation for the interface is available from Microsoft in the DNS WMI Provider Reference. I have released a PowerShell 2.0 module using the WMI provider here. There are a few limitations of the [...]


Related posts:<ol><li><a href='http://www.indented.co.uk/index.php/2010/01/12/powershell-iis-and-log-settings/' rel='bookmark' title='Permanent Link: PowerShell, IIS and log settings'>PowerShell, IIS and log settings</a> <small>A function to retrieve IIS log settings from a local...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>DNS administration in PowerShell, including tasks like creating zones and adding Host (A) records, can be performed using the WMI interface. Full documentation for the interface is available from Microsoft in the <a href="http://msdn.microsoft.com/en-us/library/ms682128(VS.85).aspx">DNS WMI Provider Reference</a>.</p>
<p>I have released a PowerShell 2.0 module using the WMI provider <a href='http://www.indented.co.uk/index.php/dnsshell/'>here</a>.<br />
<span id="more-636"></span><br />
There are a few limitations of the interface. The properties associated with Aging are read-only and cannot be set. Several of the configuration options are not available including the option to enable GlobalNames with Windows Server 2008.</p>
<h3>Common variables</h3>
<p>The examples below use two common variables. Both should be updated to reflect the environment used to execute any command.</p>
<pre class="brush: powershell;">
$ServerName = &quot;dns01&quot;
$ContainerName = &quot;somedomain.example&quot;
</pre>
<h3>Management Class vs Management Object</h3>
<p>Two different classes from the .NET Framework are used below. The ManagementObject, created using Get-WMIObject, and the ManagementClass created using [WMIClass].</p>
<p>[WMIClass] creates the same object as the following example.</p>
<pre class="brush: powershell;">
$Scope = New-Object Management.ManagementScope(&quot;\\$ServerName\root\MicrosoftDNS&quot;)
$Path = New-Object Management.ManagementPath(&quot;MicrosoftDNS_Zone&quot;)
$Options = New-Object Management.ObjectGetOptions($Null, `
  [System.TimeSpan]::MaxValue, $True)

$ZoneClass = New-Object Management.ManagementClass($Scope, $Path, $Options)
</pre>
<p>In general terms, to change something that already exists use the properties and methods of a ManagementObject via Get-WMIObject. To add something new use the methods associated with a ManagementClass.</p>
<h4>Creating an instance of a Management Object</h4>
<pre class="brush: powershell;">
$Zones = Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_Zone&quot;
</pre>
<h4>Exploring the Management Object</h4>
<p>Showing the object type:</p>
<pre class="brush: plain;">
PS C:\Stuff\Scripts\PowerShell&gt; $Zones.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array
</pre>
<p>Showing the properties and methods:</p>
<pre class="brush: plain;">
PS C:\Stuff\Scripts\PowerShell&gt; $Zones | Get-Member

   TypeName: System.Management.ManagementObject#rootMicrosoftDNSMicrosoftDNS_Zone

Name                      MemberType   Definition
----                      ----------   ----------
AgeAllRecords             Method       Management.ManagementBaseObject AgeAllRec...
ChangeZoneType            Method       Management.ManagementBaseObject ChangeZon...
ForceRefresh              Method       Management.ManagementBaseObject ForceRefr...
GetDistinguishedName      Method       Management.ManagementBaseObject GetDistin...
PauseZone                 Method       Management.ManagementBaseObject PauseZone()
ReloadZone                Method       Management.ManagementBaseObject ReloadZone()
ResetSecondaries          Method       Management.ManagementBaseObject ResetSeco...
ResumeZone                Method       Management.ManagementBaseObject ResumeZone()
UpdateFromDS              Method       Management.ManagementBaseObject UpdateFro...
WriteBackZone              Method       Management.ManagementBaseObject WriteBack...
Aging                     Property     Boolean Aging {get;set;}
AllowUpdate               Property     UInt32 AllowUpdate {get;set;}
AutoCreated               Property     Boolean AutoCreated {get;set;}
AvailForScavengeTime       Property     UInt32 AvailForScavengeTime {get;set;}
Caption                   Property     String Caption {get;set;}
ContainerName             Property     String ContainerName {get;set;}
DataFile                  Property     String DataFile {get;set;}
Description               Property     String Description {get;set;}
DisableWINSRecordReplicat Property     Boolean DisableWINSRecordReplication {ge...
DnsServerName             Property     String DnsServerName {get;set;}
DsIntegrated              Property     Boolean DsIntegrated {get;set;}
ForwarderSlave            Property     Boolean ForwarderSlave {get;set;}
ForwarderTimeout          Property     UInt32 ForwarderTimeout {get;set;}
InstallDate               Property     String InstallDate {get;set;}
LastSuccessfulSoaCheck    Property     UInt32 LastSuccessfulSoaCheck {get;set;}
LastSuccessfulXfr         Property     UInt32 LastSuccessfulXfr {get;set;}
LocalMasterServers        Property     String[] LocalMasterServers {get;set;}
MasterServers             Property     String[] MasterServers {get;set;}
Name                      Property     String Name {get;set;}
NoRefreshInterval         Property     UInt32 NoRefreshInterval {get;set;}
Notify                    Property     UInt32 Notify {get;set;}
NotifyServers             Property     String[] NotifyServers {get;set;}
Paused                    Property     Boolean Paused {get;set;}
RefreshInterval           Property     UInt32 RefreshInterval {get;set;}
Reverse                   Property     Boolean Reverse {get;set;}
ScavengeServers           Property     String[] ScavengeServers {get;set;}
SecondaryServers          Property     String[] SecondaryServers {get;set;}
SecureSecondaries         Property     UInt32 SecureSecondaries {get;set;}
Shutdown                  Property     Boolean Shutdown {get;set;}
Status                    Property     String Status {get;set;}
UseNBStat                 Property     Boolean UseNBStat {get;set;}
UseWins                   Property     Boolean UseWins {get;set;}
ZoneType                  Property     UInt32 ZoneType {get;set;}
...
</pre>
<p>Showing a subset of the properties within the object:</p>
<pre class="brush: plain;">
PS C:\Stuff\Scripts\PowerShell&gt; $Zones | Select-Object Name,DsIntegrated,ZoneType,Reverse

Name                            DsIntegrated            ZoneType             Reverse
----                            ------------            --------             -------
1.2.3.in-addr.arpa                     False                   1                True
1.2.4.in-addr.arpa                     False                   1                True
1.2.5.in-addr.arpa                     False                   1                True
</pre>
<h4>Creating an instance of a Management Class</h4>
<pre class="brush: powershell;">
$ZoneClass = [WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_Zone&quot;
</pre>
<h4>Exploring the Management Class</h4>
<p>Showing the object type:</p>
<pre class="brush: plain;">
PS C:\Stuff\Scripts\PowerShell&gt; $ZoneClass.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     ManagementClass                          System.Management.ManagementObject
</pre>
<p>Showing the properties and methods:</p>
<pre class="brush: plain;">
PS C:\Stuff\Scripts\PowerShell&gt; $ZoneClass | Get-Member

   TypeName: System.Management.ManagementClass#ROOTMicrosoftDNSMicrosoftDNS_Zone

Name                   MemberType    Definition
----                   ----------    ----------
Name                   AliasProperty Name = __Class
CreateZone             Method        System.Management.ManagementBaseObject CreateZone(Sys...
...
</pre>
<h4>Listing the parameters required for a method</h4>
<p>The output above truncates the strings detailing the parameters used for each method. The following shows how the full list can be displayed.</p>
<pre class="brush: powershell;">
([WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_AType&quot;) | `
  Get-Member -Name CreateInstanceFromPropertyData | Format-List
</pre>
<p>Note that while this shows the parameter type it does not show whether or not the parameter is required or optional. For full details refer to the <a href="http://msdn.microsoft.com/en-us/library/ms682128(VS.85).aspx">DNS WMI Provider Reference</a>.</p>
<h3>Creating Zones</h3>
<p>The following values represent the Zone Types available with Microsoft DNS.</p>
<pre class="brush: plain;">
0 Primary zone
1 Secondary zone
2 Stub zone
 * Windows Server 2003:  This zone type is introduced in Windows Server 2003.
3 Zone forwarder
 * Windows Server 2003:  This zone type is introduced in Windows Server 2003.
</pre>
<h4>Create a Forward  or Reverse Lookup Zone</h4>
<p>This example shows all of the possible parameters, this can be reduced to a single line by dropping the comments and use of variables. Note that any optional variable can be set to $Null or &#8220;&#8221;.</p>
<pre class="brush: powershell;">
# Forward Lookup zone name (example)
$Name = &quot;somedomain.example&quot;
# Reverse Lookup zone name (example for 1.2.3.x Subnet)
$Name = &quot;3.2.1.in-addr.arpa&quot;
# See above
$Type = 0
# AD Integration (only valid on Active Directory Domain Controllers)
$IsDSIntegrated = $False
# FileName (Optional and only valid for zones with AD integrated set to $False)
# File must exist if specified and have size greater than 0b.
$Filename = $Null
# Master IP (Optional and only valid for Secondary, Stub and Forwarder zones)
$MasterIP = $Null
# AdminEmail (Optional and only valid for Primary zones, writes into SOA record)
$AdminEmail = $Null

$NewZone = ([WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_Zone&quot;).CreateZone( `
  $Name, $Type, $IsDSIntegrated, $FileName, $MasterIP, $AdminEmail)
</pre>
<h4>Examples</h4>
<pre class="brush: powershell;">
# New Standard Primary Forward Lookup Zone
$NewZone = ([WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_Zone&quot;).CreateZone( `
  &quot;standardprimary.example&quot;, 0, $False)
# New Standard Primary Forward Lookup Zone using existing zone file
$NewZone = ([WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_Zone&quot;).CreateZone( `
  &quot;standardprimary-existing.example&quot;, 0, $False, &quot;standardprimary-existing.example.dns&quot;)
# New Active Directory Integrated Forward Lookup Zone
$NewZone = ([WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_Zone&quot;).CreateZone( `
  &quot;adprimary.example&quot;, 0, $True)
# New Standard Primary Reverse Lookup Zone
$NewZone = ([WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_Zone&quot;).CreateZone( `
  &quot;1.168.192.in-addr.arpa&quot;, 0)
# New Active Directory Integrated Reverse Lookup Zone
$NewZone = ([WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_Zone&quot;).CreateZone( `
  &quot;2.168.192.in-addr.arpa&quot;, 0, $True)
# New Secondary Forward Lookup Zone
$NewZone = ([WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_Zone&quot;).CreateZone( `
  &quot;standardsecondary.example&quot;, 1, $False, &quot;&quot;, `
  @(&quot;192.168.0.1&quot;, &quot;192.168.0.2&quot;))
# New Stub Zone
$NewZone = ([WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_Zone&quot;).CreateZone( `
  &quot;stub.example&quot;, 2, $False, &quot;&quot;, @(&quot;192.168.0.1&quot;, &quot;192.168.0.2&quot;))
# New Conditional Forwarder
$NewZone = ([WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_Zone&quot;).CreateZone( `
  &quot;conditionalforwarder.example&quot;, 3, $False, &quot;&quot;, @(&quot;192.168.0.1&quot;, &quot;192.168.0.2&quot;))
# New AD Integrated Conditional Forwarder
$NewZone = ([WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_Zone&quot;).CreateZone( `
  &quot;adconditionalforwarder.example&quot;, 3, $True, &quot;&quot;, @(&quot;192.168.0.1&quot;, &quot;192.168.0.2&quot;))
</pre>
<h3>Creating resource records with CreateInstanceFromPropertyData</h3>
<p>CreateInstanceFromPropertyData is available on each individual record class. For example, the method can be invoked from MicrosoftDNS_AType, or MicrosoftDNS_MXType, and so on. Note that the syntax for the method varies slightly depending on the record type.</p>
<h4>Create an A record</h4>
<pre class="brush: powershell;">
# Record Name (Owner Name). Should include full suffix to prevent the method
# throwing an error.
$OwnerName = &quot;www.$ContainerName&quot;
# Class, as in IN, CS, CH or HS. Normally only care about IN (Internet: 1) which
# is the default. (Optional)
$RecordClass = $Null
# Time To Live in seconds (Optional)
$TTL = $Null
# IP Address is required
$IPAddress = &quot;1.2.3.4&quot;

$NewATypeClass = [WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_AType&quot;
$NewARecord = $NewATypeClass.CreateInstanceFromPropertyData( `
  $ServerName, $ContainerName, $OwnerName, $RecordClass, $TTL, $IPAddress)
</pre>
<h4>Create an MX record</h4>
<pre class="brush: powershell;">
# Record Name (Owner Name). Normally the SMTP domain, in this case it matches
# ContainerName.
$OwnerName = $ContainerName
$RecordClass = $Null
$TTL = $Null
# Preference, numeric value used to determine the preferred server(s)
$Preference = 10
# The server used to handle the mail
$MailExchange = &quot;mail.somedomain.example&quot;

$NewMXTypeClass = [WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_MXType&quot;
$NewMXRecord = $NewMXTypeClass.CreateInstanceFromPropertyData( `
  $ServerName, $ContainerName, $OwnerName, $RecordClass, $TTL, $Preference, $MailExchange)
</pre>
<h3>Creating resource records with CreateInstanceFromTextRepresentation</h3>
<p>CreateInstanceFromTextRepresentation is available from the MicrosoftDNS_ResourceRecord class. It takes fewer parameters than the previous method but ultimately requires exactly the same information.</p>
<h4>Create an NS record</h4>
<pre class="brush: powershell;">
# The text version of the record. Must include Class (IN) or this will fail.
# @ represents the origin, or zone / domain name.
$TextRepresentation = &quot;@ IN NS ns1.somedomain.net&quot;

$NewRRClass = [WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord&quot;
$NewRR = $NewRRClass.CreateInstanceFromTextRepresentation( `
  $ServerName, $ContainerName, $TextRepresentation)
</pre>
<h4>Create a TXT record</h4>
<pre class="brush: powershell;">
# Using @ with the TXT record here will cause an error when executing the method.
# Instead, this uses the $ContainerName variable.
# Unlike the zone file itself the method does not require a terminating
# period following each name.
$TextRepresentation = &quot;$ContainerName IN TXT `&quot;hello world`&quot;&quot;

$NewRRClass = [WMIClass]&quot;\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord&quot;
$NewRR = $NewRRClass.CreateInstanceFromTextRepresentation( `
  $ServerName, $ContainerName, $TextRepresentation)
</pre>
<h3>Update server data file</h3>
<p>DNS zones are held in memory, any change to the zone is performed in memory rather than as a direct alteration of the zone file. The following method can be used to force the updated zone to write back to the file.</p>
<pre class="brush: powershell;">
(Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_Zone&quot; `
  -Filter &quot;ContainerName='$ContainerName'&quot;).WriteBackZone()
</pre>
<h3>Reload a zone</h3>
<p>Changes made to the zone file can be loaded into memory immediately using the ReloadZone method.</p>
<pre class="brush: powershell;">
(Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_Zone&quot; `
  -Filter &quot;ContainerName='$ContainerName'&quot;).ReloadZone()
</pre>
<h3>Enabling and starting scavenging on a server</h3>
<p>Enabling scavenging requires setting the ScavengingInterval property to a non-zero value. The value representing the interval uses Hours.</p>
<pre class="brush: powershell;">
# Connecting to the Server Management Object
$Server = Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_Server&quot;
# Setting a new Scavenging Interval
$Server.ScavengingInterval = 24
$Server.Put()
# Start Scavenging
$Server.StartScavenging()
</pre>
<h3>Clear the cache</h3>
<p>Any cached entries on a server can be cleared using the ClearCache method of the MicrosoftDNS_Cache class.</p>
<pre class="brush: powershell;">
(Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_Cache&quot;).ClearCache()
</pre>
<h3>Displaying the DNS server statistics</h3>
<p>Each DNS server holds a variety of statistics that can help to evaluate server performance.</p>
<pre class="brush: powershell;">
Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_Statistic&quot; | `
    Select-Object Name, StringValue, Value
</pre>


<p>Related posts:<ol><li><a href='http://www.indented.co.uk/index.php/2010/01/12/powershell-iis-and-log-settings/' rel='bookmark' title='Permanent Link: PowerShell, IIS and log settings'>PowerShell, IIS and log settings</a> <small>A function to retrieve IIS log settings from a local...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2008/12/30/administering-microsoft-dns-in-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Modifying DNS records with WMI</title>
		<link>http://www.indented.co.uk/index.php/2008/10/23/modifying-dns-records-with-wmi/</link>
		<comments>http://www.indented.co.uk/index.php/2008/10/23/modifying-dns-records-with-wmi/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 11:40:19 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Microsoft DNS]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VbScript]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=252</guid>
		<description><![CDATA[Using WMI it is possible to modify any existing record hosted on a Microsoft DNS Server. The method used varies slightly depending on which record type we want to change. References for each version of the Modify method can be found in the DNS WMI Provider Reference. These are the most common: A Type CNAME [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Using WMI it is possible to modify any existing record hosted on a Microsoft DNS Server. The method used varies slightly depending on which record type we want to change.<br />
<span id="more-252"></span><br />
References for each version of the Modify method can be found in the <a href="http://msdn.microsoft.com/en-us/library/ms682128(VS.85).aspx">DNS WMI Provider Reference</a>. These are the most common:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms682181(VS.85).aspx">A Type</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms682669(VS.85).aspx">CNAME Type</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms682703(VS.85).aspx">MX Type</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms682706(VS.85).aspx">NS Type</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms682712(VS.85).aspx">PTR Type</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms682738(VS.85).aspx">SRV Type</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms682744(VS.85).aspx">TXT Type</a></li>
</ul>
<p>The examples below show modification of Host or A records, but it is possible to extend the example to use any of the types above.</p>
<h3>Using VbScript to modify records</h3>
<p>This example demonstrates the use of WMI in VbScript to modify a record. The first value for Modify is the TTL, by using objItem.TTL we just reinsert the existing value, only changing the IP address.</p>
<pre class="brush: vb;">
' Connect to the WMI Service
Set objWMIService = GetObject(&quot;winmgmts:\\dc01\root\MicrosoftDNS&quot;)
' Run a query to get the record we want to change
Set colItems = objWMIService.ExecQuery(&quot;SELECT * FROM MicrosoftDNS_AType&quot; &amp; _
  &quot; WHERE ContainerName='thezone.net' AND OwnerName='test.thezone.net'&quot;,,48)

' Loop through the results
For Each objItem in colItems
  ' Modify the record
  objItem.Modify objItem.TTL, &quot;1.2.3.4&quot;
Next
</pre>
<p>If the TTL must be changed it is important to exclude the IP Address parameter, failure to do so will result in the record being deleted. Any attempt to use Modify without making any changes will result in a &#8220;SWbemObjectEx: Generic failure&#8221; exception.</p>
<h3>Using PowerShell to modify records</h3>
<p>The same failure reasons and restrictions apply with PowerShell (including the obscure deletion). Otherwise changing the record can be performed like this.</p>
<pre class="brush: powershell;">
$ServerName = &quot;dns01&quot;
$ContainerName = &quot;somedomain.example&quot;
$RecordName = &quot;test.somedomain.example&quot;

$Record = Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_AType&quot; `
  -Filter &quot;ContainerName='$ContainerName' AND OwnerName='$RecordName'&quot;
# Using the existing TTL value (in seconds)
$ModifiedRecord = $Record.Modify($Record.TTL, &quot;2.3.4.5&quot;)
</pre>
<p>In both VbScript and PowerShell the method call returns an object representing the updated record if further processing is required.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2008/10/23/modifying-dns-records-with-wmi/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>NTFS, WMI, VbScript &amp; listing explicit rights</title>
		<link>http://www.indented.co.uk/index.php/2008/10/22/listing-explicit-rights/</link>
		<comments>http://www.indented.co.uk/index.php/2008/10/22/listing-explicit-rights/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 15:04:02 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[VbScript]]></category>
		<category><![CDATA[acl]]></category>
		<category><![CDATA[ntfs]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[securitydescriptor]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=423</guid>
		<description><![CDATA[This script uses WMI to enumerate each access control entry in an NTFS access control list, looking for explicit entries, that is, entries that are not inherited. If SECURITY_PRINCIPAL is blank the script will return all explicit rights beneath granted from base path down. The script attempts to provide a summary for common rights. The [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This script uses WMI to enumerate each access control entry in an NTFS access control list, looking for explicit entries, that is, entries that are not inherited.<br />
<span id="more-423"></span><br />
If SECURITY_PRINCIPAL is blank the script will return all explicit rights beneath granted from base path down. The script attempts to provide a summary for common rights.</p>
<p>The PowerShell version of this script is considerably better for granular reporting of rights assigned. This one is more of a demonstration of security descriptor enumeration.</p>
<pre class="brush: vb;">
Option Explicit

' Looks for a Trustee containing the SECURITY_PRINCIPAL string on
' the file system. Recurses from BASE_PATH down (file and folders).

' Set these values for the search.

Const BASE_PATH = &quot;C:\&quot;
Const SECURITY_PRINCIPAL = &quot;Chris&quot;

Sub FSRecurse(strPath)
  ' Simple FS recursion

  Dim objFolder, objFile, objSubFolder

  Set objFolder = objFileSystem.GetFolder(strPath)

  For Each objFile in objFolder.Files
    CheckDescriptor objFile.Path
  Next
  For Each objSubFolder in objFolder.SubFolders
    CheckDescriptor objSubFolder.Path

    FSRecurse objSubFolder.Path
  Next

  Set objFolder = Nothing
End Sub

Sub CheckDescriptor(strPath)
  ' Look for the Trustee in the Security Descriptor and filter out
  ' inherited ACEs

  Const ACE_FLAG_INHERITED = &amp;H10 ' 16

  Dim objSecuritySettings, objSecurityDescriptor, objACE, objTrustee

  Set objSecuritySettings = objWMIService.Get _
    (&quot;Win32_LogicalFileSecuritySetting.Path='&quot; &amp; strPath &amp; &quot;'&quot;)
  objSecuritySettings.GetSecurityDescriptor objSecurityDescriptor

  For Each objACE in objSecurityDescriptor.dACL
    If InStr(1, objACE.Trustee.Name, _
        SECURITY_PRINCIPAL, VbTextCompare) &gt; 0 Then

      ' ACEFlags is binary. Must perform binary comparison.
      If objACE.ACEFlags And ACE_FLAG_INHERITED Then
        ' Problems with negation of the above.
        ' This is just easier.
      Else
        EnumAccess strPath, objACE
      End If
    End If
  Next
End Sub

Sub EnumAccess(strPath, objACE)
  ' Most access mask values have matching Folder versions. These are not
  ' numerically different, they only differ when interpreted.

  ' ACE Type

  Const ACCESS_ALLOWED_ACE_TYPE = &amp;h0
  Const ACCESS_DENIED_ACE_TYPE  = &amp;h1

  ' Base Access Mask values

  Const FILE_READ_DATA = &amp;h1
  Const FILE_WRITE_DATA = &amp;h2
  Const FILE_APPEND_DATA = &amp;h4
  Const FILE_READ_EA = &amp;h8
  Const FILE_WRITE_EA = &amp;h10
  Const FILE_EXECUTE = &amp;h20
  Const FILE_DELETE_CHILD = &amp;h40
  Const FILE_READ_ATTRIBUTES = &amp;h80
  Const FILE_WRITE_ATTRIBUTES = &amp;h100
  Const FOLDER_DELETE = &amp;h10000
  Const READ_CONTROL = &amp;h20000
  Const WRITE_DAC = &amp;h40000
  Const WRITE_OWNER = &amp;h80000
  Const SYNCHRONIZE = &amp;h100000

  ' Constructed Access Masks

  Dim FULL_CONTROL
  FULL_CONTROL = FILE_READ_DATA + FILE_WRITE_DATA + FILE_APPEND_DATA + _
    FILE_READ_EA + FILE_WRITE_EA + FILE_EXECUTE + FILE_DELETE_CHILD + _
    FILE_READ_ATTRIBUTES + FILE_WRITE_ATTRIBUTES + FOLDER_DELETE + _
    READ_CONTROL + WRITE_DAC + WRITE_OWNER + SYNCHRONIZE

  Dim READ_ONLY
  READ_ONLY = FILE_READ_DATA + FILE_READ_EA + FILE_EXECUTE + _
    FILE_READ_ATTRIBUTES + READ_CONTROL + SYNCHRONIZE

  Dim MODIFY
  MODIFY = FILE_READ_DATA + FILE_WRITE_DATA + FILE_APPEND_DATA + _
    FILE_READ_EA + FILE_WRITE_EA + FILE_EXECUTE + _
    FILE_READ_ATTRIBUTES + _
    FILE_WRITE_ATTRIBUTES + FOLDER_DELETE + READ_CONTROL + SYNCHRONIZE

  Dim strRights
  Dim intAccessMask

  WScript.Echo &quot;Path: &quot; &amp; strPath
  WScript.Echo &quot;Username: &quot; &amp; objACE.Trustee.Name
  WScript.Echo &quot;Domain: &quot; &amp; objACE.Trustee.Domain
  WScript.Echo &quot;ACE Flags (Decimal): &quot; &amp; objACE.ACEFlags

  ' ACE Type

  If objACE.ACEType = ACCESS_ALLOWED_ACE_TYPE Then
    WScript.Echo &quot;ACE Type: Allow&quot;
  Else
    WScript.Echo &quot;ACE Type: Deny&quot;
  End If

  ' Attempt to generate a basic summary of access rights

  strRights = &quot;&quot;
  intAccessMask = objACE.AccessMask

  If intAccessMask = FULL_CONTROL Then
    strRights = &quot; (FullControl)&quot;
  ElseIf intAccessMask = MODIFY Then

    strRights = &quot; (Modify)&quot;
  ElseIf intAccessMask = READ_ONLY Then
    strRights = &quot; (ReadOnly)&quot;
  End If

  ' Echo the decimal mask with any summarised rights

  WScript.Echo &quot;Access Mask (Decimal): &quot; &amp; intAccessMask &amp; strRights

  WScript.Echo
End Sub

'
' Main code block
'

Dim objFileSystem, objWMIService

Set objFileSystem = CreateObject(&quot;Scripting.FileSystemObject&quot;)
' WMI Connection to the local machine
Set objWMIService = GetObject(&quot;winmgmts:\\.&quot;)

FSRecurse BASE_PATH

Set objWMIService = Nothing
Set objFileSystem = Nothing
</pre>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2008/10/22/listing-explicit-rights/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft DNS &amp; stale records</title>
		<link>http://www.indented.co.uk/index.php/2008/10/10/microsoft-dns-stale-records/</link>
		<comments>http://www.indented.co.uk/index.php/2008/10/10/microsoft-dns-stale-records/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 11:18:56 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Microsoft DNS]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VbScript]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[reporting]]></category>
		<category><![CDATA[Stale Records]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[Windows 2003]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=199</guid>
		<description><![CDATA[This post explains how to identify and report on stale records in a dynamically updated Microsoft DNS zone. The time stamp taken from a DNS record represents the numbers of hours since 01/01/1601 00:00. The value can be converted into a useful date within a script. By default, all times are reported and tested in [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This post explains how to identify and report on stale records in a dynamically updated Microsoft DNS zone.<br />
<span id="more-199"></span><br />
The time stamp taken from a DNS record represents the numbers of hours since 01/01/1601 00:00. The value can be converted into a useful date within a script. By default, all times are reported and tested in UTC.</p>
<p>A stale record is a record where both the No-Refresh Interval and Refresh Interval have passed without the time stamp updating. Ordinarily stale records would be removed by a Scavenging process. These scripts may be useful if trying to asses the impact of enabling Scavenging or reducing Aging intervals.</p>
<h3>Listing stale records with VbScript</h3>
<p>This script uses a WMI query to return all A records for a domain, then it sorts through each record, echoing when the time stamp is older than our pre-defined maximum age. The script will work best when run with cscript.</p>
<pre class="brush: vb;">
' No-Refresh + Refresh (in Days)
Const MAXIMUM_AGE = 4

' Connect to the MicrosoftDNS Namespace
Set objWMIService = _
  GetObject(&quot;winmgmts:\\dc01.internal.highorbit.co.uk\root\MicrosoftDNS&quot;)

' Query A records with MicrosoftDNS_AType class where the record is not static
Set colItems = objWMIService.ExecQuery(&quot;SELECT * FROM MicrosoftDNS_AType &quot; &amp;_
  &quot; WHERE ContainerName='internal.highorbit.co.uk' AND TimeStamp&lt;&gt;0&quot;)

For Each objItem In colItems
  ' Convert the timestamp into a date and time
  dtmTimeStamp = DateAdd(&quot;h&quot;, objItem.TimeStamp, &quot;01/01/1601 00:00:00&quot;)
  ' Compare the date and time with MAXIMUM_AGE
  If dtmTimeStamp &lt;= (Date() - MAXIMUM_AGE) Then
    ' Echo the record details if it is older than the MAXIMUM_AGE
    WScript.Echo objItem.OwnerName &amp; VbTab &amp; objItem.IPAddress &amp;_
      VbTab &amp; dtmTimeStamp
  End If
Next
</pre>
<h3>Listing stale records with PowerShell</h3>
<p>This snippet uses Get-WMIObject and a improved query to return only stale records rather than sorting after returning all dynamic records.</p>
<p>A timespan value is generated to represent the minimum value of TimeStamp for valid records.</p>
<pre class="brush: powershell;">
# No-Refresh + Refresh (in Days)
$TotalAgingInterval = 4

$ServerName = &quot;dc01.internal.highorbit.co.uk&quot;
$ContainerName = &quot;internal.highorbit.co.uk&quot;

$MinTimeStamp = [Int](New-TimeSpan `
  -Start $(Get-Date(&quot;01/01/1601 00:00&quot;)) `
  -End $((Get-Date).AddDays(-$TotalAgingInterval))).TotalHours

Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_AType&quot; `
  -Filter `
  &quot;ContainerName='$ContainerName' AND TimeStamp&lt;$MinTimeStamp AND TimeStamp&lt;&gt;0&quot; `
 | Select-Object OwnerName, `
  @{n=&quot;TimeStamp&quot;;e={(Get-Date(&quot;01/01/1601&quot;)).AddHours($_.TimeStamp)}}
</pre>
<h3>Reading Aging intervals with PowerShell</h3>
<p>The Aging intervals and the date the zone can be scavenged set on a zone can be read using WMI using the MicrosoftDNS_Zone class. As with the TimeStamp the .AddHours method must be used to return a date.</p>
<pre class="brush: powershell;">
$ServerName = &quot;dc01.internal.highorbit.co.uk&quot;
$ContainerName = &quot;internal.highorbit.co.uk&quot;

Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_Zone&quot; `
  -Filter &quot;ContainerName='$ContainerName'&quot; `
 | Select-Object NoRefreshInterval, RefreshInterval, `
  @{n=&quot;AvailForScavengeTime&quot;;e={
    (Get-Date(&quot;01/01/1601&quot;)).AddHours($_.AvailForScavengeTime)}}
</pre>
<h3>Localisation</h3>
<p>As mentioned at the beginning of this post, all times are reported in UTC by default. By calling a the ToLocalTime method the date returned can be converted to local time, using the time zone configured on the system executing the query.</p>
<pre class="brush: powershell;">
$ServerName = &quot;dc01.internal.highorbit.co.uk&quot;
$ContainerName = &quot;internal.highorbit.co.uk&quot;

$MinTimeStamp = [Int](New-TimeSpan `
  -Start $(Get-Date(&quot;01/01/1601 00:00&quot;)) `
  -End $((Get-Date).AddDays(-$TotalAgingInterval))).TotalHours

Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_AType&quot; `
  -Filter `
  &quot;ContainerName='$ContainerName' AND TimeStamp&lt;$MinTimeStamp AND TimeStamp&lt;&gt;0&quot; `
 | Select-Object OwnerName, `
  @{n=&quot;TimeStamp&quot;;e={
    ((Get-Date(&quot;01/01/1601&quot;)).AddHours($_.TimeStamp)).ToLocalTime()}}
</pre>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2008/10/10/microsoft-dns-stale-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft DNS &amp; static records</title>
		<link>http://www.indented.co.uk/index.php/2008/10/02/microsoft-dns-static-records/</link>
		<comments>http://www.indented.co.uk/index.php/2008/10/02/microsoft-dns-static-records/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 11:59:32 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Microsoft DNS]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VbScript]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[reporting]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[Windows 2003]]></category>
		<category><![CDATA[wmi]]></category>
		<category><![CDATA[wmic]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=28</guid>
		<description><![CDATA[Windows 2008 has an improved user interface for DNS. The main console includes details of a records time stamp and whether or not the record is Static. Life isn&#8217;t quite so easy with Windows 2003. However, as each static record has a time stamp set to 0 they can be found with a little work. [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Windows 2008 has an improved user interface for DNS. The main console includes details of a records time stamp and whether or not the record is Static. Life isn&#8217;t quite so easy with Windows 2003. However, as each static record has a time stamp set to 0 they can be found with a little work.<br />
<span id="more-28"></span><br />
When using an Active Directory Integrated zone records are stored within Active Directory as dnsNode objects. The Time Stamp value is encoded along with the rest of the record properties (TTL, etc) in the dnsRecord attribute on the dnsNode. The attribute is a Binary Large Object (BLOB), Microsoft do not currently publish references or maps for these attributes. WMI queries can be used as an alternative.</p>
<h3>The DNS management console</h3>
<p>To see the current time stamp, and whether a record is dynamic or not first enable View / Advanced in the DNS console. For each record that makes an additional tick box and text box visible.</p>
<p>The record below is dynamic, if the box is not ticked, and the time stamp field is blank the record is static. That means that unticking the box stating the record can be scavenged changes the record to static.</p>
<p><a href="http://69.164.211.174/wp-content/uploads/2008/10/dynamicrecord.jpg"><img class="aligncenter size-medium wp-image-52" title="Dynamic Record" src="http://www.highorbit.co.uk/wp-content/uploads/2008/10/dynamicrecord-270x300.jpg" alt="" width="270" height="300" /></a></p>
<h3>DNSCMD</h3>
<p>DNSCMD installs along with the Windows Support Tools. It can be used to identify static records, although it can be very difficult pulling the results out of a list like this.</p>
<p><em>For example:</em></p>
<pre class="brush: plain;">
dnscmd /ZonePrint somedomain.example
</pre>
<h3>WMIC</h3>
<p>WMIC, Windows Management Instrumentation Command-Line, will install the first time it is run. As the name suggests, it allows execution of WMI queries on the command line.</p>
<pre class="brush: plain;">
WMIC /NAMESPACE:&quot;\\root\MicrosoftDNS&quot; PATH &quot;MicrosoftDNS_AType&quot; WHERE &quot;ContainerName='somedomain.example’ AND TimeStamp=0&quot; GET &quot;OwnerName,TTL,TimeStamp&quot;
</pre>
<p>Or</p>
<pre class="brush: plain;">
WMIC /NAMESPACE:&quot;\\root\MicrosoftDNS&quot; PATH &quot;MicrosoftDNS_AType&quot; WHERE &quot;TimeStamp=0&quot; GET &quot;OwnerName,TTL,TimeStamp&quot;
</pre>
<h3>VbScript</h3>
<p>This VbScript snippet echoes each static record, it is works best when run with cscript.</p>
<pre class="brush: vb;">
strServerName = &quot;dc01.somedomain.example&quot;
strContainerName = &quot;somedomain.example&quot;

Set objWMIService = GetObject(&quot;winmgmts:\\&quot; &amp; strServerName &amp; _
  &quot;\root\MicrosoftDNS&quot;)
Set colItems = objWMIService.ExecQuery(&quot;SELECT * FROM MicrosoftDNS_AType &quot; &amp;_
  &quot; WHERE ContainerName='&quot; &amp; strContainerName &amp; &quot;' AND TimeStamp=0&quot;)

For Each objItem In colItems
  WScript.Echo objItem.OwnerName &amp; VbTab &amp; objItem.IPAddress &amp; VbTab &amp; &quot;Static&quot;
Next

Set colItems = Nothing
Set objWMIService = Nothing
</pre>
<h3>PowerShell</h3>
<pre class="brush: powershell;">
$ServerName = &quot;dc01.somedomain.example&quot;
$ContainerName = &quot;somedomain.example&quot;

Get-WMIObject -Computer $ServerName `
    -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_AType&quot; `
    -Filter &quot;ContainerName='$ContainerName' AND TimeStamp=0&quot; `
  | Select-Object OwnerName,TTL, @{n=&quot;TimeStamp&quot;;e={&quot;Static&quot;}}
</pre>
<p>The same search can be used for any record type, by changing the WMI class. The options most likely to be useful are:</p>
<ul>
<li>MicrosoftDNS_AType &#8211; Address or Host records</li>
<li>MicrosoftDNS_CNAMEType &#8211; Alias records</li>
<li>MicrosoftDNS_MXType &#8211; Mail Exchanger records</li>
<li>MicrosoftDNS_NSType &#8211; Name Server records</li>
<li>MicrosoftDNS_SRVType &#8211; Service records</li>
<li>MicrosoftDNS_PTRType &#8211; Pointer records (Reverse Lookup zone)</li>
</ul>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2008/10/02/microsoft-dns-static-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
