<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Summut you might not have known</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/carlh/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/carlh/feed.xml</link>
    <description />
    <lastBuildDate>Tue, 16 Apr 2019 05:59:22 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Get User Profiles and Last User that Logged on to Desktop Computers</title>
      <link>https://docs.microsoft.com/archive/blogs/carlh/get-user-profiles-and-last-user-that-logged-on-to-desktop-computers</link>
      <pubDate>Tue, 03 Jul 2012 03:52:00 GMT</pubDate>
      <dc:creator><![CDATA[carl h2]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/carlh/2012/07/03/get-user-profiles-and-last-user-that-logged-on-to-desktop-computers/</guid>
      <description><![CDATA[Another Powershell script that helps with a migration. In this instance the requirement was for a...]]></description>
      <content:encoded><![CDATA[<p>Another Powershell script that helps with a migration. In this instance the requirement was for a way of understanding the accounts that had previously logged onto desktop systems and the credentials of the last logged on user, for either all desktop systems in a Domain\OU structure or all desktop systems listed in a text file. Additionally, in this instance, there was a requirement to add a delay between each iteration of the data gathering to minimise impact on the script running system and to the network.</p>
<p>The challenge was that this information is stored differently in XP and Vista\Win7 in the registry and the Profile information is accessible on Vista\Win7 systems using Get-Profiles, but needs some registry scripting jiggery-pokery for XP\Win2k3 systems. Additionally, I could not find any script out there that did both these things, so I decided to use functions from other peoples work and stitch them together to get what is attached.</p>
<p>To understand what can be done with the script, read the header. If the script is run without parameters it will just get Profile information for all desktop systems in the currently logged on domain. The output is stored in 3 csv files that are suffixed with Date\Time stamps in the same location that the script is run from.</p>
<p>&nbsp;The Syntax for running the script is this and none of the parameters are required.</p>
<p><span style="color: #000000;"><strong><span style="font-family: arial,helvetica,sans-serif;">.\Get-PCUserProfilePath.ps1 -srcDomainPath &lt;SearchPathdnOrDNSName&gt; -IterationDelay &lt;TimeInSeconds&gt; -ComputerType &lt;ServerOrDesktop&gt; -ComputerListFile &lt;sAMAccountNameTextList&gt;<br /></span></strong></span>&nbsp;</p>
<p><span style="color: #000000;"><span style="font-family: arial,helvetica,sans-serif;">I have not included a listing of the script here because it is too large, but the script can be downloaded at the bottom of this posting.</span></span></p>
<p><span style="color: #000000;"><span style="font-family: arial,helvetica,sans-serif;">HTH</span></span></p>
<p><span style="color: #000000;"><strong><span style="font-family: arial,helvetica,sans-serif;"></span></strong></span>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/telligent.evolution.components.attachments/01/7148/00/00/03/50/71/84/Get-PCsUserProfileInfo.ps1.txt" original-url="https://blogs.technet.com/cfs-filesystemfile.ashx/__key/telligent-evolution-components-attachments/01-7148-00-00-03-50-71-84/Get_2D00_PCsUserProfileInfo.ps1.txt">Get-PCsUserProfileInfo.ps1.txt</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Compare AD Object Direct Group Membership</title>
      <link>https://docs.microsoft.com/archive/blogs/carlh/compare-ad-object-direct-group-membership</link>
      <pubDate>Mon, 02 Jul 2012 08:14:00 GMT</pubDate>
      <dc:creator><![CDATA[carl h2]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/carlh/2012/07/02/compare-ad-object-direct-group-membership/</guid>
      <description><![CDATA[Who can guess I am working on an AD migration project at the moment? And it presents an opportunity...]]></description>
      <content:encoded><![CDATA[<p>Who can guess I am working on an AD migration project at the moment? And it presents an opportunity to cut my teeth further on Powershell scripting. Yes the AD Powershell scripts I have produced so far could have been done much easier if I had used the AD module provided with AD in Windows Server 2008 R2, but unfortunately not everyone is in a situation where they can take advantage of that module or even the Quest Modules that are also available. Hence some of the long winded scripts I have been producing.</p>
<p>Back to this problemette I was presented with. Following a user migration process\procedure the AD support team had discovered that a number of users were not able to access some resources and as one of the checks during remediation, wanted a quick way of comparing a users Group Membership with that of the source account. The following script is what I came up with for them. Basically, it gets all the direct Group memberships for the source object and destination objects (as specified at the command line) and runs a compare operation. The on screen output is of a table that displays the Group Memberships that are different between the objects with an arrow indicator showing what side of the evaluation the Group Membership exists. So for example if you ran the following command :</p>
<p><strong>.\Compare-UserGroups.ps1 -srcDomain domain1.local -destDomain woodgrovebank.com -srcsAMAccountName carlh1 -destsAMAccountName carlh2</strong></p>
<p>You would get 2 files that list each objects Group Membership and something like the table below, which shows that the entry for destsAMAccountName (carlh2) is a member of a group named "Password Policy Group", which the entry for srcsAMAccountName (carlh) is not a member of and vice versa for the other groups.<strong></strong></p>
<p><span style="font-family: arial,helvetica,sans-serif;">&nbsp;InputObject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SideIndicator&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: arial,helvetica,sans-serif;">-----------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;-------------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: arial,helvetica,sans-serif;">Password Policy Group&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: arial,helvetica,sans-serif;">EventLogAccess&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;=&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: arial,helvetica,sans-serif;">DnsAdmins&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&lt;=&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: arial,helvetica,sans-serif;">Backup Operators&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;=&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: arial,helvetica,sans-serif;"></span></p>
<p><span style="font-family: arial,helvetica,sans-serif;">It is true this is just a "like for like" sAMAccountName comparison and not a true SID to SID\SIDHistory comparison and it only compares Direct membership, but the requirement was for a quick check to ensure nothing was awry for odd troubleshooting instances and suits the needs where Groups have been migrated wholesale. If you need anything more funky that does Group Nesting then&nbsp;I advise you pop over to here <a href="https://www.rlmueller.net/freecode1.htm">https://www.rlmueller.net/freecode1.htm</a>&nbsp;. Richards scripts are awesome.</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&lt;#</span><br /><span style="color: #000080; font-family: courier new,courier;">####################################################################</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;Compare-UserGroups.ps1</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp;Syntax:&nbsp; Compare-UserGroups.ps1 -srcDomain &lt;SourceDomain&gt; -destDomain &lt;DestinationDomain&gt; -srcsAMAccountName &lt;UserNetbiosName&gt; -destsAMAccountName &lt;UserNetbiosName&gt;</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp;Example: Compare-UserGroups.ps1 -srcDomain domain1.local -destDomain woodgrovebank.com -srcsAMAccountName carlh -destsAMAccountName carlh</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp;Purpose: Compares the DIRECT Group Membership of 2 user accounts.</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Be aware that it compares the Netbios names (sAMAccountName) of the groups</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and is only useful either within a domain\forest or after a migration</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; of a user account between domains where the group names have not been changed</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; as a consequence of the migration.</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp;Params:&nbsp; As shown in syntax above or by typing the script name at the command prompt</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp;Req:&nbsp;&nbsp;&nbsp;&nbsp; Windows 2003 SP2 or above, Powershell V2.</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; run "set-executionpolicy remotesigned" in Powershell</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://blogs.technet.com/b/carlh"><span style="color: #000080;">https://blogs.technet.com/b/carlh</span></a></span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp;Author:&nbsp; Carl Harrison</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; This script is provided "AS IS" with no warranties, confers no rights and </span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; is not supported by the authors or authors employer. </span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Use of this script sample is subject to the terms specified at </span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; <a href="https://www.microsoft.com/info/copyright.mspx"><span style="color: #000080;">https://www.microsoft.com/info/copyright.mspx</span></a>.</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp;Version: 1.0 - First cut</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">####################################################################</span><br /><span style="color: #000080; font-family: courier new,courier;">#&gt;</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Param (</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;[Parameter()][string]$srcDomain='',</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;[Parameter()][String]$destDomain='',</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; [Parameter()][String]$srcsAMAccountName='',</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; [Parameter()][String]$destsAMAccountName='')</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Function Compare-GroupsHelp () {</span><br /><span style="color: #000080; font-family: courier new,courier;">$helptext=@"</span><br /><span style="color: #000080; font-family: courier new,courier;">NAME: Compare-UserGroups.ps1</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Compares the DIRECT Group Membership of 2 user accounts</span><br /><span style="color: #000080; font-family: courier new,courier;">Be aware that it compares the Netbios names (sAMAccountName) of the groups</span><br /><span style="color: #000080; font-family: courier new,courier;">and is only useful either within a domain\forest or after a migration</span><br /><span style="color: #000080; font-family: courier new,courier;">of a user account between domains where the group names have not been changed</span><br /><span style="color: #000080; font-family: courier new,courier;">as a consequence of the migration.</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">PARAMETERS:</span><br /><span style="color: #000080; font-family: courier new,courier;">-srcDomain&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Source Domain (Required)</span><br /><span style="color: #000080; font-family: courier new,courier;">-destDomain&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Destination Domain (Required)</span><br /><span style="color: #000080; font-family: courier new,courier;">-srcsAMAccountName&nbsp; Netbios name of the user account in the source domain (Required)</span><br /><span style="color: #000080; font-family: courier new,courier;">-destsAMAccountName Netbios name of the user account in the destination domain (Required)</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">SYNTAX:</span><br /><span style="color: #000080; font-family: courier new,courier;">Compare-UserGroups.ps1 -srcDomain domain1.local -destDomain woodgrovebank.com -srcsAMAccountName carlh -destsAMAccountName carlh2</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Thsi compares the group memberships that carlh from domain1.local has in domain1.local</span><br /><span style="color: #000080; font-family: courier new,courier;">with the group memberships that carlh from woodgrovebank.com has in woodgrovebank.com</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">"@</span><br /><span style="color: #000080; font-family: courier new,courier;">$helptext</span><br /><span style="color: #000080; font-family: courier new,courier;">exit</span><br /><span style="color: #000080; font-family: courier new,courier;">}</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Function Get-LDAPUser ($UserName, $SourceDomain) {</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $domain1 = new-object DirectoryServices.DirectoryEntry ("<a href="ldap://$SourceDomain"><span style="color: #000080;">LDAP://$SourceDomain</span></a>")</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $searcher = new-object DirectoryServices.DirectorySearcher($domain1)</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $searcher.filter = "(&amp;(objectClass=user)(sAMAccountName= $UserName))"</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $searcher.findone().getDirectoryEntry()</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $domain1 =""</span><br /><span style="color: #000080; font-family: courier new,courier;">}</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">if(!($srcDomain)) {"Source Domain Required";Compare-GroupsHelp}</span><br /><span style="color: #000080; font-family: courier new,courier;">if(!($destDomain)) {"Destination Domain Required";Compare-GroupsHelp}</span><br /><span style="color: #000080; font-family: courier new,courier;">if(!($srcsAMAccountName)) {"Netbios Name or Source Account Required";Compare-GroupsHelp}</span><br /><span style="color: #000080; font-family: courier new,courier;">if(!($destsAMAccountName)) {"Netbios Name or Destination Account Required";Compare-GroupsHelp}</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">$srcUserGroupsFile = '.\srcUserGroupsFile.txt'</span><br /><span style="color: #000080; font-family: courier new,courier;">$destUserGroupsFile = '.\destUserGroupsFile.txt'</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Write-Host</span><br /><span style="color: #000080; font-family: courier new,courier;">$srcUser = get-ldapuser $srcsAMAccountName $srcDomain</span><br /><span style="color: #000080; font-family: courier new,courier;">Write-Host $srcUser.displayName "is a member of" $srcUser.memberOf.Count " groups in domain $srcDomain. The groups are:"</span><br /><span style="color: #000080; font-family: courier new,courier;">$srcUser.memberOf | ft</span><br /><span style="color: #000080; font-family: courier new,courier;">Write-Host</span><br /><span style="color: #000080; font-family: courier new,courier;">$destUser = get-ldapuser $destsAMAccountName $destDomain</span><br /><span style="color: #000080; font-family: courier new,courier;">Write-Host $destUser.displayName "is a member of" $destUser.memberOf.Count " groups in domain $destDomain. The groups are:"</span><br /><span style="color: #000080; font-family: courier new,courier;">$destUser.memberOf | ft</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Write-Host</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">$srcUserGroups = @()</span><br /><span style="color: #000080; font-family: courier new,courier;">$srcGroupsDN = @()</span><br /><span style="color: #000080; font-family: courier new,courier;">$destUserGroups = @()</span><br /><span style="color: #000080; font-family: courier new,courier;">$destGroupsDN = @()</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Foreach($Group in $srcUser.memberOf)</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $GroupsAMAccountName = ([ADSI]"<a href="ldap://$Group&quot;).sAMAccountName.value"><span style="color: #000080;">LDAP://$Group").sAMAccountName.value</span></a></span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #$GroupsAMAccountName</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $srcUserGroups += "$GroupsAMAccountName"</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $srcGroupsDN += $Group.tostring()</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #000080; font-family: courier new,courier;">Foreach($Group in $destUser.memberOf)</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $GroupsAMAccountName = ([ADSI]"<a href="ldap://$Group&quot;).sAMAccountName.value"><span style="color: #000080;">LDAP://$Group").sAMAccountName.value</span></a></span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #$GroupsAMAccountName</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $destUserGroups += "$GroupsAMAccountName"</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $destGroupsDN += $Group.tostring()</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">$srcGroupsDN | Out-File $srcUserGroupsFile</span><br /><span style="color: #000080; font-family: courier new,courier;">$destGroupsDN | Out-File $destUserGroupsFile</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Compare-Object $srcUserGroups $destUserGroups -SyncWindow 100</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">$destUser = ""</span><br /><span style="color: #000080; font-family: courier new,courier;">$srcUser = ""</span></p>
<p><span style="font-family: arial,helvetica,sans-serif;">&nbsp;</span></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/telligent.evolution.components.attachments/01/7148/00/00/03/50/70/18/Compare-UserGroups.ps1.txt" original-url="https://blogs.technet.com/cfs-filesystemfile.ashx/__key/telligent-evolution-components-attachments/01-7148-00-00-03-50-70-18/Compare_2D00_UserGroups.ps1.txt">Compare-UserGroups.ps1.txt</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Copy AD User Profile Path etc between Domain User Objects</title>
      <link>https://docs.microsoft.com/archive/blogs/carlh/copy-ad-user-profile-path-etc-between-domain-user-objects</link>
      <pubDate>Mon, 02 Jul 2012 07:19:00 GMT</pubDate>
      <dc:creator><![CDATA[carl h2]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/carlh/2012/07/02/copy-ad-user-profile-path-etc-between-domain-user-objects/</guid>
      <description><![CDATA[Here's a weird one, you are migrating users from multiple domains to a single domain and your...]]></description>
      <content:encoded><![CDATA[<p>Here's a weird one, you are migrating users from multiple domains to a single domain and your migration process\procedure had determined that the primary domain of a user was not what it actually is, so the settings (Profile Path, Home Drive\Directory, and Script Path) for the new user are for the wrong account.&nbsp;For various reasons you don't want or cannot merge the user objects attributes. This was one of the queries posed to me recently by a customer.</p>
<p>&nbsp;</p>
<p>The script below gives&nbsp;a remedy to this by taking as a command line parameter the name and domain of one domain user and copying profile settings (the Profile Path, Home Drive &amp; Directory, and Script Path) to relevant attributes of another command line parameter specified user name (in another domain). I even included the ability to prefix the ScriptPath Attribute (in case you use a different folder tree in the new domain).</p>
<p>&nbsp;</p>
<p>Before using the script read the header to give you a clue as to the syntax. I have attached a copy of the code in a text file at the bottom of this post.</p>
<p><span style="color: #000080; font-family: courier new,courier;">&lt;#</span><br /><span style="color: #000080; font-family: courier new,courier;">####################################################################</span><br /><span style="color: #000080; font-family: courier new,courier;">Copy-UserProfile.ps1</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Syntax:&nbsp; Copy-UserProfile.ps1 -srcDomain &lt;SourceDomain&gt; -destDomain &lt;DestinationDomain&gt; -scriptPathPrefix &lt;ScriptPrefix&gt; -srcsAMAccountName &lt;UserNetbiosName&gt; -</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">destsAMAccountName &lt;UserNetbiosName&gt;</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Example: Copy-UserProfile.ps1 -srcDomain domain1.local -destDomain woodgrovebank.com -scriptPathPrefix domain1\ -srcsAMAccountName carlh -destsAMAccountName carlh2</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Purpose: This Sets the ProfilePath, ScriptPath, HomeDrive and HomeDirectory of the user carlh2 in the</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Woodgrovebank.com domain to the same settings as those for carlh in domain.local. Additionally,</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the scriptPath attribute content is prefixed with the word domin1\</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Params:&nbsp; As shown in syntax above or by typing the script name at the command prompt</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Req:&nbsp;&nbsp;&nbsp;&nbsp; Windows 2003 SP2 or above, Powershell V2.</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp; run "set-executionpolicy remotesigned" in Powershell</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp; <a href="https://blogs.technet.com/b/carlh"><span style="color: #000080;">https://blogs.technet.com/b/carlh</span></a></span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Author:&nbsp; Carl Harrison</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; This script is provided "AS IS" with no warranties, confers no rights and </span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; is not supported by the authors or Microsoft Corporation. </span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Use of this script sample is subject to the terms specified at </span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; <a href="https://www.microsoft.com/info/copyright.mspx"><span style="color: #000080;">https://www.microsoft.com/info/copyright.mspx</span></a>.</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Version: 1.0 - First cut</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">####################################################################</span><br /><span style="color: #000080; font-family: courier new,courier;">#&gt;</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Param (</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;[Parameter()][string]$srcDomain='',</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;[Parameter()][String]$destDomain='',</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Parameter()][String]$scriptPathPrefix='',</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Parameter()][String]$srcsAMAccountName='',</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Parameter()][String]$destsAMAccountName='')</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Function GetSetUserHelp () {</span><br /><span style="color: #000080; font-family: courier new,courier;">$helptext=@"</span><br /><span style="color: #000080; font-family: courier new,courier;">NAME: Copy-UserPofile.ps1</span><br /><span style="color: #000080; font-family: courier new,courier;">Used to copy User Profile, Logon Script and Home details of user</span><br /><span style="color: #000080; font-family: courier new,courier;">from one domain to the next.</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">PARAMETERS:</span><br /><span style="color: #000080; font-family: courier new,courier;">-srcDomain&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Source Domain (Required)</span><br /><span style="color: #000080; font-family: courier new,courier;">-destDomain&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Destination Domain (Required)</span><br /><span style="color: #000080; font-family: courier new,courier;">-scriptPathPrefix&nbsp;&nbsp; Prefix to add to Script Path attribute (include any back slashes or forward slashes as required)</span><br /><span style="color: #000080; font-family: courier new,courier;">-srcsAMAccountName&nbsp; Netbios name of the user account in the source domain (Required)</span><br /><span style="color: #000080; font-family: courier new,courier;">-destsAMAccountName Netbios name of the user account in the destination domain (Required)</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">SYNTAX:</span><br /><span style="color: #000080; font-family: courier new,courier;">Copy-UserProfile.ps1 -srcDomain domain1.local -destDomain woodgrovebank.com -scriptPathPrefix domain1\ -srcsAMAccountName carlh -destsAMAccountName carlh2</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">This Sets the ProfilePath, ScriptPath, HomeDrive and HomeDirectory of the user carlh2 in the</span><br /><span style="color: #000080; font-family: courier new,courier;">Woodgrovebank.com domain to the same settings as those for carlh in domain.local. Additionally,</span><br /><span style="color: #000080; font-family: courier new,courier;">the scriptPath attribute content is prefixed with the word domin1\</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">"@</span><br /><span style="color: #000080; font-family: courier new,courier;">$helptext</span><br /><span style="color: #000080; font-family: courier new,courier;">exit</span><br /><span style="color: #000080; font-family: courier new,courier;">}</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Function Get-LDAPUser ($UserName, $SourceDomain) {</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $domain1 = new-object DirectoryServices.DirectoryEntry ("<a href="ldap://$SourceDomain"><span style="color: #000080;">LDAP://$SourceDomain</span></a>")</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $searcher = new-object DirectoryServices.DirectorySearcher($domain1)</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $searcher.filter = "(&amp;(objectClass=user)(sAMAccountName= $UserName))"</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $searcher.findone().getDirectoryEntry()</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $domain1 =""</span><br /><span style="color: #000080; font-family: courier new,courier;">}</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Function Set-LDAPUser ($UserName2, $DestinationDomain) {</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $domain2 = new-object DirectoryServices.DirectoryEntry ("<a href="ldap://$DestinationDomain"><span style="color: #000080;">LDAP://$DestinationDomain</span></a>")</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $searcher = new-object DirectoryServices.DirectorySearcher($domain2)</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $searcher.filter = "(&amp;(objectClass=user)(sAMAccountName= $UserName2))"</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $destUser = $searcher.findone().getDirectoryEntry()</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $destUser.scriptPath = "$Global:ScriptPathPrefix" + $Global:srcUser.scriptPath</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $destUser.profilePath = $Global:srcUser.profilePath</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $destUser.homeDrive = $Global:srcUser.homeDrive</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $destUser.homeDirectory = $Global:srcUser.homeDirectory</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $destUser.setinfo() </span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $domain2 = ""</span><br /><span style="color: #000080; font-family: courier new,courier;">}</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">if(!($srcDomain)) {"Source Domain Required";GetSetUserHelp}</span><br /><span style="color: #000080; font-family: courier new,courier;">if(!($destDomain)) {"Destination Domain Required";GetSetUserHelp}</span><br /><span style="color: #000080; font-family: courier new,courier;">if(!($srcsAMAccountName)) {"Netbios Name or Source Account Required";GetSetUserHelp}</span><br /><span style="color: #000080; font-family: courier new,courier;">if(!($destsAMAccountName)) {"Netbios Name or Destination Account Required";GetSetUserHelp}</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">$Global:ScriptPathPrefix = $ScriptPathPrefix</span><br /><span style="color: #000080; font-family: courier new,courier;">$Global:srcUser = get-ldapuser $srcsAMAccountName $srcDomain</span><br /><span style="color: #000080; font-family: courier new,courier;">Write-Host $Global:srcUser.displayName "in domain $srcDomain settings are:"</span><br /><span style="color: #000080; font-family: courier new,courier;">$Global:srcUser.scriptPath</span><br /><span style="color: #000080; font-family: courier new,courier;">$Global:srcUser.profilePath</span><br /><span style="color: #000080; font-family: courier new,courier;">$Global:srcUser.homeDrive</span><br /><span style="color: #000080; font-family: courier new,courier;">$Global:srcUser.homeDirectory</span><br /><span style="color: #000080; font-family: courier new,courier;">set-ldapuser $destsAMAccountName $destDomain</span><br /><span style="color: #000080; font-family: courier new,courier;">$Global:destUser = get-ldapuser $destsAMAccountName $destDomain</span><br /><span style="color: #000080; font-family: courier new,courier;">Write-Host ""</span><br /><span style="color: #000080; font-family: courier new,courier;">Write-Host $Global:destUser.displayName "in domain $destDomain settings are now:"</span><br /><span style="color: #000080; font-family: courier new,courier;">$Global:destUser.scriptPath</span><br /><span style="color: #000080; font-family: courier new,courier;">$Global:destUser.profilePath</span><br /><span style="color: #000080; font-family: courier new,courier;">$Global:destUser.homeDrive</span><br /><span style="color: #000080; font-family: courier new,courier;">$Global:destUser.homeDirectory</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">$Global:destUser = ""</span><br /><span style="color: #000080; font-family: courier new,courier;">$Global:srcUser = ""</span><br /><span style="color: #000080; font-family: courier new,courier;">$ScriptPathPrefix = ""</span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/telligent.evolution.components.attachments/01/7148/00/00/03/50/70/06/Copy-UserProfile.ps1.txt" original-url="https://blogs.technet.com/cfs-filesystemfile.ashx/__key/telligent-evolution-components-attachments/01-7148-00-00-03-50-70-06/Copy_2D00_UserProfile.ps1.txt">Copy-UserProfile.ps1.txt</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Powershell Script to find if Domain Admins is a member of Computer Local Administrators</title>
      <link>https://docs.microsoft.com/archive/blogs/carlh/powershell-script-to-find-if-domain-admins-is-a-member-of-computer-local-administrators</link>
      <pubDate>Mon, 02 Jul 2012 05:09:26 GMT</pubDate>
      <dc:creator><![CDATA[carl h2]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/carlh/2012/07/02/powershell-script-to-find-if-domain-admins-is-a-member-of-computer-local-administrators/</guid>
      <description><![CDATA[So here's another script that I quickly&nbsp;knocked up. Basically, I was asked whether there was a...]]></description>
      <content:encoded><![CDATA[<p>So here's another script that I quickly&nbsp;knocked up. Basically, I was asked whether there was a way of finding out whether the Domain Admins&nbsp;group was a member of the Local Administrators group on a list of computers.&nbsp;Powershell to the rescue; I'm really getting into this Powershell Malarkey.</p>
<p>It is rather rudimentary and could actually be made a bit more usable by getting it to search AD and even specific OU structures in AD. Examples of this follow later in my TechNet Blog.</p>
<p>Script attached to blog below (requires removal&nbsp;of txt extension to work).</p>
<p>&nbsp;</p>
<p><span style="color: #000080; font-family: courier new,courier;">&lt;#</span><br /><span style="color: #000080; font-family: courier new,courier;">#####################################################################</span><br /><span style="color: #000080; font-family: courier new,courier;">SCRIPT IsADMemberOfLocalAdmins.ps1</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">SYNTAX</span><br /><span style="color: #000080; font-family: courier new,courier;">.\IsADMemberOfLocalAdmins.ps1 -InputFile &lt;.\ComputerList.txt&gt; -OutputFile &lt;.\OutPutFile.txt&gt;</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">-InputFile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text file containing list of Computers to query</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /><span style="color: #000080; font-family: courier new,courier;">-OutputFile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text File containing results from script</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">SYNOPSIS</span><br /><span style="color: #000080; font-family: courier new,courier;">Queries the Local Administrators group on the computers listed in the</span><br /><span style="color: #000080; font-family: courier new,courier;">text file provided as a parameter, to determine if Domain Admins is</span><br /><span style="color: #000080; font-family: courier new,courier;">listed as a member.</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">NOTE</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Script requires no parameters or arguments, but does have some.</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; I recommend you have the relevant permissions in the domain and</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; on the computers being queried for optimal results.</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; This script is provided "AS IS" with no warranties, confers no rights and </span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; is not supported by the authors or employer.</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">AUTHOR</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Carl Harrison</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">VERSION: 1.0 - First cut</span><br /><span style="color: #000080; font-family: courier new,courier;">#####################################################################</span><br /><span style="color: #000080; font-family: courier new,courier;">#&gt;</span></p>
<p><span style="color: #000080; font-family: courier new,courier;"># Change these two to suit your needs</span><br /><span style="color: #000080; font-family: courier new,courier;">Param (</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;[Parameter()][string]$InputFile='.\computers.txt',</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;[Parameter()][String]$OutputFile='.\IsDAMemberOfAdminsOutput.txt')</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">$ChildGroups = "Domain Admins"</span><br /><span style="color: #000080; font-family: courier new,courier;">$LocalGroup = "Administrators"</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">$MemberNames = @()</span><br /><span style="color: #000080; font-family: courier new,courier;">$OutPutResults = @()</span><br /><span style="color: #000080; font-family: courier new,courier;">$Computers = Get-Content $InputFile</span><br /><span style="color: #000080; font-family: courier new,courier;">foreach ( $Computer in $Computers ) {</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;$Group= [ADSI]"WinNT://$Computer/$LocalGroup,group"</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;$Members = @($Group.psbase.Invoke("Members"))</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;$Members | ForEach-Object {</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;$MemberNames += $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;} </span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;$ChildGroups | ForEach-Object {</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;$output = "" | Select-Object Computer, Group, InLocalAdmin</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;$output.Computer = $Computer</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;$output.Group = $_</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;$output.InLocalAdmin = $MemberNames -contains $_</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;Write-Output $output</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $OutputResults += $output</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $MemberNames = @()</span><br /><span style="color: #000080; font-family: courier new,courier;">}</span><br /><span style="color: #000080; font-family: courier new,courier;">$OutputResults | Export-CSV -NoTypeInformation $OutputFile</span></p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/telligent.evolution.components.attachments/01/7148/00/00/03/50/69/86/IsDAMemberOflocalAdmins.ps1.txt" original-url="https://blogs.technet.com/cfs-filesystemfile.ashx/__key/telligent-evolution-components-attachments/01-7148-00-00-03-50-69-86/IsDAMemberOflocalAdmins.ps1.txt">IsDAMemberOflocalAdmins.ps1.txt</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Delete Stuff in AD</title>
      <link>https://docs.microsoft.com/archive/blogs/carlh/delete-stuff-in-ad</link>
      <pubDate>Mon, 02 Jul 2012 04:48:08 GMT</pubDate>
      <dc:creator><![CDATA[carl h2]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/carlh/2012/07/02/delete-stuff-in-ad/</guid>
      <description><![CDATA[Once again another script to help one of my colleagues in need of a method of bulk deleting objects...]]></description>
      <content:encoded><![CDATA[<p>Once again another script to help one of my colleagues in need of a method of bulk deleting objects in AD taken from a list in CSV file. In this instance he need it for deletion of groups that they had determined as no longer useful. Bizarrely, this&nbsp;type of script did not exist when he searched for it (I would have thought someone would have written something like this previously). Actually I had some written some of this code already over 8 years ago and decided to repurpose it for my colleague.</p>
<p>Below is a listing of the VBScript. It reads in a file named Groups.csv that contains a list of all groups (sAMAccountName's) to be deleted (the original CSV file also had a second column that had the group type integer, but the script strips this). The script works in the domain of the currently logged on credentials, so you need the necessary permissions in AD for it to work.</p>
<p>Normally, I comment my scripts a lot more, but this was a rush order :-) and I haven't had the time to revisit it (and I an trying to move from VBScript now).</p>
<p>&nbsp;</p>
<p>My colleague has proven, the script is easily altered to enable it t delete any type of object and these scripts have been posted to Microsoft Script Center.</p>
<p>&nbsp;</p>
<p><span style="color: #000080; font-family: courier new,courier;">'Script deletes security groups from a csv file.</span><br /><span style="color: #000080; font-family: courier new,courier;">'csv format is strsAMGroupName,Whatever</span><br /><span style="color: #000080; font-family: courier new,courier;">'This script is offered with no warranty</span><br /><span style="color: #000080; font-family: courier new,courier;">'On Error Resume Next 'used in case group not found</span><br /><span style="color: #000080; font-family: courier new,courier;">Option Explicit</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Const ForReading = 1</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Dim strL, spl1, strOU, strGroupCN, strGroupName</span><br /><span style="color: #000080; font-family: courier new,courier;">Dim objFSO, objInputFile</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Set objFSO = CreateObject("Scripting.FileSystemObject")</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Set objInputFile = objFSO.OpenTextFile(".\groups.csv", ForReading) 'your csv file</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">wscript.echo "script started"</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">'extract from csv file</span><br /><span style="color: #000080; font-family: courier new,courier;">Do until objInputFile.AtEndOfStream</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;strL = objInputFile.ReadLine</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;spl1 = Split(strL, ",")</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;strGroupName = (spl1(0))</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;If GroupExists(strGroupName) = True Then</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;'WScript.Echo strGroupName &amp; " exists."</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;DelGroup</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;End If&nbsp;&nbsp;&nbsp;</span><br /><span style="color: #000080; font-family: courier new,courier;">Loop</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Set objFSO = Nothing</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objInputFile = Nothing</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">wscript.echo "script finished"</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">'group exist check</span><br /><span style="color: #000080; font-family: courier new,courier;">Function GroupExists(strsAMGroupName)</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Dim strDNSDomain, strFilter, strQuery</span><br /><span style="color: #000080; font-family: courier new,courier;">Dim objConnection, objCommand, objRootLDAP, objLDAPGroup, objRecordSet</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">GroupExists = False</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objConnection = CreateObject("ADODB.Connection")</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objCommand =&nbsp;&nbsp; CreateObject("ADODB.Command")</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objRootLDAP = GetObject("<a href="ldap://RootDSE"><span style="color: #000080;">LDAP://RootDSE</span></a>")</span><br /><span style="color: #000080; font-family: courier new,courier;">objConnection.Provider = "ADsDSOObject"</span><br /><span style="color: #000080; font-family: courier new,courier;">objConnection.Open "Active Directory Provider"</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objCommand.ActiveConnection = objConnection</span><br /><span style="color: #000080; font-family: courier new,courier;">objCommand.Properties("Page Size") = 1000</span><br /><span style="color: #000080; font-family: courier new,courier;">'objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">strDNSDomain = objRootLDAP.Get("DefaultNamingContext")</span><br /><span style="color: #000080; font-family: courier new,courier;">strFilter = "(&amp;(objectCategory=group)(sAMAccountName=" &amp; strsAMGroupName &amp; "))"</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">strQuery = "&lt;LDAP://" &amp; strDNSDomain &amp; "&gt;;" &amp; strFilter &amp; ";sAMAccountName,adspath,CN;subTree"</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">objCommand.CommandText = strQuery</span><br /><span style="color: #000080; font-family: courier new,courier;">'WScript.Echo strFilter</span><br /><span style="color: #000080; font-family: courier new,courier;">'WScript.Echo strQuery</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objRecordSet = objCommand.Execute</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">If objRecordSet.RecordCount = 1 Then</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">objRecordSet.MoveFirst</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; 'WScript.Echo "We got here " &amp; strsAMGroupName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;'WScript.Echo objRecordSet.Fields("sAMAccountname").Value</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;'WScript.Echo objRecordSet.Fields("adspath").Value</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;If objRecordSet.Fields("sAMAccountname").Value = strsAMGroupName Then</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;GroupExists = True</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;Set objLDAPGroup = GetObject(objRecordSet.Fields("adspath").Value)</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;strOU = objLDAPGroup.Parent</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;&nbsp;strGroupCN = objRecordSet.Fields("CN").Value</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;End If</span><br /><span style="color: #000080; font-family: courier new,courier;">Else</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;WScript.Echo strsAMGroupName &amp; " Group doesn't exist or Duplicate sAMAccountName"</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;GroupExists = False</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;strGroupCN = ""</span><br /><span style="color: #000080; font-family: courier new,courier;">&nbsp;strOU = ""</span><br /><span style="color: #000080; font-family: courier new,courier;">End If</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">objRecordSet.Close</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objConnection = Nothing</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objCommand = Nothing</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objRootLDAP = Nothing</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objLDAPGroup = Nothing</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objRecordSet = Nothing</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">end function</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Sub DelGroup</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Dim objOU</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">'WScript.Echo strOU</span><br /><span style="color: #000080; font-family: courier new,courier;">'WScript.Echo strGroupCN</span><br /><span style="color: #000080; font-family: courier new,courier;">Set objOU = GetObject(strOU)</span><br /><span style="color: #000080; font-family: courier new,courier;">objOU.Delete "Group", "cn=" &amp; strGroupCN &amp; ""</span><br /><span style="color: #000080; font-family: courier new,courier;">WScript.Echo strGroupName &amp; " (CN=" &amp; strGroupCN &amp; ") has been deleted."</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">Set ObjOU = Nothing</span><br /><span style="color: #000080; font-family: courier new,courier;">strGroupCN = ""</span></p>
<p><span style="color: #000080; font-family: courier new,courier;">End Sub</span></p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/telligent.evolution.components.attachments/01/7148/00/00/03/50/69/69/Bulkdeletegroups.vbs.txt" original-url="https://blogs.technet.com/cfs-filesystemfile.ashx/__key/telligent-evolution-components-attachments/01-7148-00-00-03-50-69-69/Bulkdeletegroups.vbs.txt">Bulkdeletegroups.vbs.txt</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Ever wanted to know what shares are on all your Servers</title>
      <link>https://docs.microsoft.com/archive/blogs/carlh/ever-wanted-to-know-what-shares-are-on-all-your-servers</link>
      <pubDate>Mon, 02 Jul 2012 03:56:00 GMT</pubDate>
      <dc:creator><![CDATA[carl h2]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/carlh/2012/07/02/ever-wanted-to-know-what-shares-are-on-all-your-servers/</guid>
      <description><![CDATA[I have been scripting using VBScript for some time now, and only on occasion have I had the...]]></description>
      <content:encoded><![CDATA[<p>I have been scripting using VBScript for some time now, and only on occasion have I had the motivation and\or reason to write a script using Powershell, but&nbsp;I have decided in the last 9 months to make a concerted effort to utilise the Power of Powershell as my main scripting technology. In this time period I have produced a number of scripts and I will be adding them to my blog in case anybody finds them useful.</p>
<p>So my first offering is something I wrote for a colleague of mine, that queries all the Windows Servers in your domain and gathers their Shares, the permissions set on the shares and the permissions set on the NTFS file system at the share level (not lower). All this is output to 2 CSV files in the same folder that the script is run from. There are no Parameters for the script, and I hadn't written it to specifically search in specific OU structures or to read from text file&nbsp;based list of computers. I have since written another script that I will be posting here, that has this functionality, so if you need it that functionality it can be done.</p>
<p>The script requires that you have the necessary Rights on all the Servers you will be querying to get back all the information.</p>
<p>Below is a listing of the script, but I have attached the code in a text file as well (obviously remove the txt extension to use)..</p>
<p><span style="color: #333399; font-family: courier new,courier;">&lt;#</span><br /><span style="color: #333399; font-family: courier new,courier;">#####################################################################</span><br /><span style="color: #333399; font-family: courier new,courier;">SCRIPT GetPermissions.ps1</span><br /><span style="color: #333399; font-family: courier new,courier;">SYNOPSIS</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Gets all Servers from the domain from which the script is run in</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; (i.e. the domain you are logged in to).</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Then uses the server list to query each servers Share permissions</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; and the NTFS permissions of each share root folder.</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; The Script creates 2 files in the same location the script is</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; run from (sharereport.csv and ntfsreport.csv).</span><br /><span style="color: #333399; font-family: courier new,courier;">NOTE</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Script requires no parameters or arguments</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; I recommend you have the relevant permissions in the domain and</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; on the servers being queried for optimal results.</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Myself or my employer do not warrantee this script in any way and</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; use of it is entirely at the users own risk.</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; The working functions of this script are taken from examples found</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; at Microsoft Script Center web site and are written by Boe Prox.</span><br /><span style="color: #333399; font-family: courier new,courier;">AUTHOR</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Carl Harrison</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; The script utilises 2 functions written by Boe Prox and publically</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; available at Microsoft Script Center. They have been altered slightly</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; to work with this script.</span><br /><span style="color: #333399; font-family: courier new,courier;">VERSION: 1.0 - First cut</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.1 - Sorted FQDN Ping instead of netbios ping </span><br /><span style="color: #333399; font-family: courier new,courier;">#####################################################################</span><br /><span style="color: #333399; font-family: courier new,courier;">#&gt;</span></p>
<p><span style="color: #333399; font-family: courier new,courier;">function Get-SharePermissions{</span><br /><span style="color: #333399; font-family: courier new,courier;">&lt;#&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">.SYNOPSIS&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Retrieves share permissions. This function was extracted from a </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Powershell Module written by Boe Prox named FileSharePermissions.psm1</span><br /><span style="color: #333399; font-family: courier new,courier;">.DESCRIPTION</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Retrieves share permissions.</span><br /><span style="color: #333399; font-family: courier new,courier;">.PARAMETER computer</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Name of server to test.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">.EXAMPLE&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Get-SharePermissions -computer Test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">#&gt; </span><br /><span style="color: #333399; font-family: courier new,courier;">[cmdletbinding(</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;DefaultParameterSetName = 'computer',</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;ConfirmImpact = 'low'</span><br /><span style="color: #333399; font-family: courier new,courier;">)]</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Param(</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Parameter(</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mandatory = $True,</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Position = 0,</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ParameterSetName = 'computer',</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ValueFromPipeline = $True)]</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [array]$computer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span><br /><span style="color: #333399; font-family: courier new,courier;">Begin</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #Process Share report</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $sharereport = @()</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">Process</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #Iterate through comptuers</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; ForEach ($c in $computer)</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Write-Verbose "Computer: $($c)"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Retrieve share information from comptuer</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ShareSec = Get-WmiObject -Class Win32_LogicalShareSecuritySetting -ComputerName $c -ea stop</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ForEach ($Shares in $sharesec)</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Write-Verbose "Share: $($Shares.name)"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Try to get the security descriptor</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;$SecurityDescriptor = $ShareS.GetSecurityDescriptor()</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Iterate through each descriptor</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;ForEach ($DACL in $SecurityDescriptor.Descriptor.DACL)</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrshare = New-Object PSObject</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrshare | Add-Member NoteProperty Computer $c</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arrshare | Add-Member NoteProperty Name $Shares.Name</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arrshare | Add-Member NoteProperty ID $DACL.Trustee.Name</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Convert the current output into something more readable</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Switch ($DACL.AccessMask)</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;2032127 {$AccessMask = "FullControl"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1179785 {$AccessMask = "Read"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1180063 {$AccessMask = "Read, Write"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1179817 {$AccessMask = "ReadAndExecute"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;-1610612736 {$AccessMask = "ReadAndExecuteExtended"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1245631 {$AccessMask = "ReadAndExecute, Modify, Write"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1180095 {$AccessMask = "ReadAndExecute, Write"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;268435456 {$AccessMask = "FullControl (Sub Only)"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;default {$AccessMask = $DACL.AccessMask}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arrshare | Add-Member NoteProperty AccessMask $AccessMask</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Convert the current output into something more readable</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Switch ($DACL.AceType)</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;0 {$AceType = "Allow"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1 {$AceType = "Deny"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;2 {$AceType = "Audit"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arrshare | Add-Member NoteProperty AceType $AceType</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Add to existing array</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sharereport += $arrshare</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Catch any errors&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrshare = New-Object PSObject</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrshare | Add-Member NoteProperty Computer $c</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arrshare | Add-Member NoteProperty Name "NA"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$arrshare | Add-Member NoteProperty ID "NA" </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrshare | Add-Member NoteProperty AccessMask "NA"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Add to existing array</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sharereport += $arrshare</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Finally</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Do Nothing Currently</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">End {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #Display report</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #$ShareReport</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #$ShareReport | Export-Csv -notypeinformation "sharereport.csv"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; return $sharereport</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">}&nbsp;&nbsp;&nbsp;</span></p>
<p><span style="color: #333399; font-family: courier new,courier;">function Get-ShareNTFSPermissions{</span><br /><span style="color: #333399; font-family: courier new,courier;">&lt;#&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">.SYNOPSIS&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Retrieves NTFS permissions on a share. This function was extracted from a </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Powershell Module written by Boe Prox named FileSharePermissions.psm1</span><br /><span style="color: #333399; font-family: courier new,courier;">.DESCRIPTION</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp; Retrieves NTFS permissions on a share.</span><br /><span style="color: #333399; font-family: courier new,courier;">.PARAMETER computer</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Name of server to test.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">.EXAMPLE&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Get-ShareNTFSPermissions -computer Test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">#&gt; </span><br /><span style="color: #333399; font-family: courier new,courier;">[cmdletbinding(</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;DefaultParameterSetName = 'computer',</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;ConfirmImpact = 'low'</span><br /><span style="color: #333399; font-family: courier new,courier;">)]</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Param(</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Parameter(</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mandatory = $True,</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Position = 0,</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ParameterSetName = 'computer',</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ValueFromPipeline = $True)]</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [array]$computer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">Begin</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #Process NTFS Share report&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $ntfsreport = @()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Process</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #Iterate through each computer</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; ForEach ($c in $computer)</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose "Computer: $($c)" </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Gather share information</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $shares = Gwmi -comp $c Win32_Share -ea stop | ? {$_.Name -ne 'ADMIN$'-AND $_.Name -ne 'C$' -AND $_.Name -ne 'IPC$'} | Select Name,Path</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ForEach ($share in $shares)</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Iterate through shares</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write-Verbose "Share: $($share.name)"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ($share.path -ne "")</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Retrieve ACL information from Share&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $remoteshare = $share.path -replace ":","$" </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Gather NTFS security information from each share</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $acls = Get-ACL "<a href="file://\\$computer\$remoteshare"><span style="color: #333399;">\\$computer\$remoteshare</span></a>"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #iterate through each ACL</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ForEach ($acl in $acls.access)</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ($acl.FileSystemRights -match "\d")</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Switch ($acl.FileSystemRights)</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;2032127 {$AccessMask = "FullControl"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1179785 {$AccessMask = "Read"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1180063 {$AccessMask = "Read, Write"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1179817 {$AccessMask = "ReadAndExecute"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;-1610612736 {$AccessMask = "ReadAndExecuteExtended"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1245631 {$AccessMask = "ReadAndExecute, Modify, Write"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1180095 {$AccessMask = "ReadAndExecute, Write"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;268435456 {$AccessMask = "FullControl (Sub Only)"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;default {$AccessMask = "Unknown"}</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $AccessMask = $acl.FileSystemRights</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs = New-Object PSObject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Process NTFS Report&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty Computer $c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty ShareName $Share.name</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty Path $share.path</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty NTFS_User $acl.IdentityReference</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty NTFS_Rights $AccessMask</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ntfsreport += $arrntfs</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs = New-Object PSObject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Process NTFS Report&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty Computer $c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty ShareName "NA"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty Path "NA"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty NTFS_User "NA"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty NTFS_Rights "NA"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Add to existing array</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ntfsreport += $arrntfs</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Finally</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Do nothing currently</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs = New-Object PSObject</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty Computer $c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty ShareName "NA" </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty Path "NA" </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty NTFS_User "NA" </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $arrntfs | Add-Member NoteProperty NTFS_Rights "NA"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Add to existing array</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ntfsreport += $arrntfs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Finally</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Do Nothing Currently</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; End</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #Display report</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #$ntfsreport</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; #$ntfsreport | Export-Csv -notypeinformation "ntfsreport.csv"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; return $ntfsreport</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="color: #333399; font-family: courier new,courier;">}</span></p>
<p><span style="color: #333399; font-family: courier new,courier;">#THIS IS THE START OF THE SCRIPT</span></p>
<p><span style="color: #333399; font-family: courier new,courier;">#Define Some variables and Arrays</span><br /><span style="color: #333399; font-family: courier new,courier;">$strOperatingSystem = "*Server*" </span><br /><span style="color: #333399; font-family: courier new,courier;">$Servers = @() </span><br /><span style="color: #333399; font-family: courier new,courier;">$ServersShareReport = @()</span><br /><span style="color: #333399; font-family: courier new,courier;">$ServersNTFSReport = @()</span></p>
<p><span style="color: #333399; font-family: courier new,courier;">#Set up the Directory Search parameters</span><br /><span style="color: #333399; font-family: courier new,courier;">$objDomain = New-Object System.DirectoryServices.DirectoryEntry </span><br /><span style="color: #333399; font-family: courier new,courier;">$objSearcher = New-Object System.DirectoryServices.DirectorySearcher </span><br /><span style="color: #333399; font-family: courier new,courier;">$objSearcher.SearchRoot = $objDomain </span><br /><span style="color: #333399; font-family: courier new,courier;">$objSearcher.Filter = ("OperatingSystem=$strOperatingSystem") </span><br /><span style="color: #333399; font-family: courier new,courier;">$objSearcher.PageSize = 1000</span><br />&nbsp;<br /><span style="color: #333399; font-family: courier new,courier;">#Define the Attributes we need from the search</span><br /><span style="color: #333399; font-family: courier new,courier;">$colProplist = "name","dnshostname","operatingsystemversion"</span><br /><span style="color: #333399; font-family: courier new,courier;">#Do the Search</span><br /><span style="color: #333399; font-family: courier new,courier;">foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)} </span><br /><span style="color: #333399; font-family: courier new,courier;">$colResults = $objSearcher.FindAll() </span><br /><span style="color: #333399; font-family: courier new,courier;">$Ping = New-Object System.Net.NetworkInformation.Ping</span><br /><span style="color: #333399; font-family: courier new,courier;">ForEach ($objResult in $colResults)</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $Server = $objResult.Properties.name</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $ServerDNS = $objResult.Properties.dnshostname</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Write-Host "Pinging $ServerDNS"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $errorActionPreference="SilentlyContinue"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $Pingy = $ping.send($ServerDNS,5000)</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $ServerShareOutput = $Null</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; $ServerNTFSOutput = $Null</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Try</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #This is where we go get the information</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ($Pingy.status.tostring() &ndash;eq &ldquo;Success&rdquo;) </span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Cool we can get to the server now lets gather some information</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host &ldquo;$Server Available&rdquo;</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $errorActionPreference="Continue"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ServerShareOutput = Get-SharePermissions -computer $ServerDNS</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ServerNTFSOutput = Get-ShareNTFSPermissions -computer $ServerDNS</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ServersShareReport += $ServerShareOutput</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ServersNTFSReport += $ServerNTFSOutput</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #oh-oh either WMI is restricted or we cannot get to the current server</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host &ldquo;$Server Not Available"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedShareServer = New-Object PSObject</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedShareServer | Add-Member NoteProperty Computer "$Server"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedShareServer | Add-Member NoteProperty Name "Server No Available"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ServersShareReport += $FailedShareServer</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedNTFSServer = New-Object PSObject</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedNTFSServer | Add-Member NoteProperty Computer "$Server"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedNTFSServer | Add-Member NoteProperty ShareName "Server No Available"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ServersNTFSReport += $FailedNTFSServer</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Catch</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #And this just catches any weird error events</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host &ldquo;$Server Not Available"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedShareServer = New-Object PSObject</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedShareServer | Add-Member NoteProperty Computer "$Server"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedShareServer | Add-Member NoteProperty Name "Server Not Available"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ServersShareReport += $FailedShareServer</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedNTFSServer = New-Object PSObject</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedNTFSServer | Add-Member NoteProperty Computer "$Server"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $FailedNTFSServer | Add-Member NoteProperty ShareName "Server Not Available"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ServersNTFSReport += $FailedNTFSServer</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; Finally</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $errorActionPreference="Continue"</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $pingy = $null</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Server = $Null</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br /><span style="color: #333399; font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /><span style="color: #333399; font-family: courier new,courier;">#Now we have the data let's save it to file - in the same location the script is run from</span><br /><span style="color: #333399; font-family: courier new,courier;">$ServersShareReport | Export-Csv -notypeinformation ".\sharereport.csv"</span><br /><span style="color: #333399; font-family: courier new,courier;">$ServersShareReport = @()</span><br /><span style="color: #333399; font-family: courier new,courier;">$ServersNTFSReport | Export-Csv -notypeinformation ".\ntfsreport.csv"</span><br /><span style="color: #333399; font-family: courier new,courier;">$ServersNTFSReport = @()</span></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/telligent.evolution.components.attachments/01/7148/00/00/03/50/69/44/GetPermissions.ps1.txt" original-url="https://blogs.technet.com/cfs-filesystemfile.ashx/__key/telligent-evolution-components-attachments/01-7148-00-00-03-50-69-44/GetPermissions.ps1.txt">GetPermissions.ps1.txt</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Script to Recover a Hyper-V Guest</title>
      <link>https://docs.microsoft.com/archive/blogs/carlh/script-to-recover-a-hyper-v-guest</link>
      <pubDate>Tue, 14 Dec 2010 16:15:00 GMT</pubDate>
      <dc:creator><![CDATA[carl h2]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/carlh/2010/12/14/script-to-recover-a-hyper-v-guest/</guid>
      <description><![CDATA[Recently,&nbsp;a colleague of mine had a customer that had a Hyper-V server whose operating system...]]></description>
      <content:encoded><![CDATA[<p>Recently,&nbsp;a colleague of mine had a customer that had a Hyper-V server whose operating system had failed. They did not have any backups of the Operating system and had not taken any backups of the Hyper-V guests using Export\Import (I won't bang on about Best Practices here; I think you probably guess what I would say if I did though :-)). They had access to the disks on which the Hyper-V guest VHD's and configuration xml files&nbsp;were located and intended re-installing the the OS and Hyper-V Role. They were asking whether there is a method of recovering the Hyper-V guests to the new server. Fortunately another one of my colleagues suggested the method detailed on this great blog here&nbsp;<a href="https://blogs.msdn.com/b/robertvi/archive/2008/12/19/howto-manually-add-a-vm-configuration-to-hyper-v.aspx">https://blogs.msdn.com/b/robertvi/archive/2008/12/19/howto-manually-add-a-vm-configuration-to-hyper-v.aspx</a>&nbsp;which I am led to believe worked.</p>
<p>Funnily enough, I had to use parts of this same method to recover a couple of Hyper-V guests on my PC&nbsp;when I had done some disk volume management and moved the VHD's and config files around a bit, which caused permissions changes obviously; honestly guv'nor I had forgotten I had these guests running from the said volume (I know Best&nbsp;Practice and all that ;-) , but it is just my laptop and not a production service providing environment).</p>
<p>My colleague then commented that it would be cool if such a process were to be scripted. Tada ...... "his wish was my command". To be honest I had put this on my list of things to do, to get me to extend my scripting skills from VBScript to Powershell and having to actually go through the process myself made me agree with my colleague a script would be so much easier and useful to anybody else having to do it. There may actually be another script out there that does this, but at least I actually got to do some Powershell scripting :-) . It may not be the most correctly written script, but it is my first crack of the whip (as the saying goes). There is currently no error trapping and\or exception handling, but I have provided some command line markers that should make it easier to determine at which points it fails (if it does). I intend adding error handling later, but if I didn't share the script now it would always be sat on my laptop as a work in progress without being used (and tested).</p>
<p>What I must say is, that after recovering the Hyper-V Guest using this script, the Hyper-V Guest is in an unsupported state and it is highly recommended that before starting the guest OS, you should use Hyper-V Manager to Export the Guest, remove it from Hyper-V Manager and then Import again into Hyper-V Manager. This will set all the permissions on all files as they should be.</p>
<p>This script definitely works with Windows Server 2008 R2 Hyper-V and I suspect it also works on Windows Server 2008 (I don't have a n environment to check this though). The script utilises icacls and mklink (both provided as command line applications with the OS), because I was unable to use inbuilt Powershell functionality without some deep coding knowledge (not quite there yet) requiring that I write some additional libraries that someone has actually already made available here <a href="https://pscx.codeplex.com/">https://pscx.codeplex.com/</a>&nbsp;. Basically, the Powershell cmdlet Set-ACL is not able to change owner when setting&nbsp;permissions on certain types of files and folders, this requires some special jiggery-pockery of which I am not yet averse. You may ask why I didn't decide to use the PSCX myself; well I thought it best to produce a script that is standalone and does not require anything that is not already available through Powershell.</p>
<p>Additionally, the script will only work correctly if the volume paths (i.e. drive letters) are the same as from before the issue that caused the Hyper-V guests to be disconnected from the Hyper-V Host Management Services.</p>
<p>The only other thing you will need to do when using this script is to open Powershell with elevated privileges and to run "set-executionpolicy remotesigned".</p>
<p>It may be worth checking the formatting of the code if you copy and paste it from this page as some of the lines have wrapped to the next line on this page. Alternatively, just download the txt file at the bottom of this post.</p>
<p>Enjoy. Oh and please provide feedback if it works or not for you.</p>
<p><span style="font-family: courier new,courier;"></span></p>
<p><span style="font-family: courier new,courier;"></span><span style="font-family: courier new,courier;">####################################################################<br /># Recover-VM.ps1<br />#<br /># Syntax:&nbsp; Recover-VM.ps1 "&lt;drive:\path\VM_Config_File_as_GUID.xml&gt;" <br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Use quotes in the argument)<br />#<br /># Example: Recover-VM.ps1 "v:\VirtualMachine1\Virtual Machines\7660AA46-BA41-4171-8820-CDD7C71050A0.xml"<br />#<br /># Purpose: Creates Symbolic Links and sets the required permissions<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to make a Hyper-V Virtual Machine available in Hyper-V<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Management Console. This script is intended for use in<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recovery scenario where a Virtual Guests files have been<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; manually moved to another Virtual Server, but the volume<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; drive mappings are the same, only.<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The methodology that this script employs is as discussed<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; in the below blog.<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; It should be noted that once this script has been used<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the Virtual Guest is in an unsupported state and should<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; be exported and re-imported in Hyper-V Manager to<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; correctly set all the Virtual Machines permissions.<br />#<br /># Params:&nbsp; The drive, folder and filename of the Virtual Machine<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xml configuration file.<br />#<br /># Req:&nbsp;&nbsp;&nbsp;&nbsp; Windows 2008 or above, Powershell V2, mklink, icacls.<br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; run "set-executionpolicy remotesigned" in Powershell<br />#<br /># Ref:&nbsp;&nbsp;&nbsp;&nbsp; https://blogs.msdn.com/b/robertvi/archive/2008/12/19/howto-manually-add-a-vm-configuration-to-<span style="font-family: courier new,courier;">hyper-v.aspx</span><br />#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; https://blogs.technet.com/b/carlh<br />#<br /># Author:&nbsp; CarlH<br />#<br /># Myself or my employer do not warantee this script in any way and use<br /># of it is entirely at the users own risk. The script is intended to<br /># Recover Virtual Machines only in a recovery scenario, and such VM's<br /># should be exported and imported onto the Hyper-V server to ensure<br /># a supported state.<br />#<br /># Version: 1.0 - First cut<br />#<br />####################################################################</span></p>
<p><span style="font-family: courier new,courier;"></span><span style="font-family: courier new,courier;">Param($VMConfigFile)</span></p>
<p><span style="font-family: courier new,courier;">Write-Host ""<br />Write-Host "---------------Recover-VM Script Start"<br />$SystemDrive = (Get-item env:systemdrive).Value<br />$VMFolder = (Get-Item $VMConfigFile).directoryname<br />$VMFolder = (Get-Item $VMFolder).parent<br />$VMFolderName = $VMFolder.fullname<br />Write-Host ""</span></p>
<p><span style="font-family: courier new,courier;">#Read from the VM Configuration file. VM GUID for Service account. VM Name.<br />Write-Host "---------------Reading VM Configuration File"<br />[xml]$VMXML = Get-Content $VMConfigFile<br />$VMSvcAccount = $VMXML.configuration.properties.global_id."#text"<br />$VMName = $VMXML.configuration.properties.name."#text"<br />Write-Host "---------------Completed reading VM Configuration File"<br />Write-Host ""</span></p>
<p><span style="font-family: courier new,courier;">#This function takes a file name including the full path as a ThisItem string parameter and gets the current ACL.<br />#It adds the VM Service account to the current ACL and then Sets the new ACL<br />function SetACL<br />{<br />&nbsp;&nbsp;&nbsp; Param($ThisItem)<br />&nbsp;&nbsp;&nbsp; Write-Host ""<br />&nbsp;&nbsp;&nbsp; Write-Host "---------------Setting Permissions for $ThisItem"<br />&nbsp;&nbsp;&nbsp; Write-Host ""<br />&nbsp;&nbsp;&nbsp; $Acl = Get-Acl $ThisItem<br />&nbsp;&nbsp;&nbsp; $AccessRule = New-Object&nbsp; system.security.accesscontrol.filesystemaccessrule("NT VIRTUAL MACHINE\$VMSvcAccount","FullControl","Allow")<br />&nbsp;&nbsp;&nbsp; $Acl.SetAccessRule($AccessRule)<br />&nbsp;&nbsp;&nbsp; Set-Acl $ThisItem $Acl&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; Write-Host ""<br />&nbsp;&nbsp;&nbsp; Write-Host "---------------Finished Permissions for $ThisItem"<br />}</span></p>
<p><span style="font-family: courier new,courier;">#This Function uses the cmd line utility mklink to create a symbolic link of the physical file passed to it in the HardFile parameter as a string<br />#The LinkLocation string parameter defines what folder the link will be created in under systemdrive\programdata\Microsoft\Windows\Hyper-V\</span></p>
<p><span style="font-family: courier new,courier;">function MkSymLink<br />{<br />&nbsp;&nbsp;&nbsp; Param($HardFile, $LinkLocation)<br />&nbsp;&nbsp;&nbsp; Write-Host ""<br />&nbsp;&nbsp;&nbsp; Write-Host "---------------Creating Symbolic Link for $HardFile"<br />&nbsp;&nbsp;&nbsp; Write-Host ""<br />&nbsp;&nbsp;&nbsp; $LinkFile = (get-item $HardFile).name<br />&nbsp;&nbsp;&nbsp; #Write-Host "%systemdrive%\programdata\Microsoft\Windows\Hyper-V\$LinkLocation\$LinkFile" $HardFile<br />&nbsp;&nbsp;&nbsp; cmd /c mklink "%systemdrive%\programdata\Microsoft\Windows\Hyper-V\$LinkLocation\$LinkFile" $HardFile<br />&nbsp;&nbsp;&nbsp; Write-Host ""<br />&nbsp;&nbsp;&nbsp; Write-Host "---------------Finished Symbolic Link for $HardFile"<br />}</span></p>
<p><span style="font-family: courier new,courier;">#Get the VM config xml Fully Qualified Name and pass it to the MKSymLink function with the location for the for storing the Symbolic Link<br />$VMFileString = (get-item $VMConfigFile).name<br />MkSymLink -HardFile $VMConfigFile -LinkLocation "Virtual Machines"</span></p>
<p><span style="font-family: courier new,courier;">#Call the SetACL function and pass it the FQN of the Symbolic Link to which we need to set the ACL <br />$ConfigFileSymLink = "$SystemDrive\programdata\Microsoft\Windows\Hyper-V\Virtual Machines\$VMFileString"<br />SetACL -ThisItem $ConfigFileSymLink</span></p>
<p><span style="font-family: courier new,courier;">#Get the FQN of the boot VHD from the VM Config xml file passed into the script. Then pass this to the SetACL function <br />$VMVHDBootFile = $VMXML.configuration.'_83f8638b-8dca-4152-9eda-2ca8b33039b4_'.controller0.drive0.pathname."#text"<br />SetACL -ThisItem $VMVHDBootFile</span></p>
<p><span style="font-family: courier new,courier;">#Build a string that defines the VM Service Account and use it with the cmd line utility icacls to set the permissions for all folders and files of the VM <br />Write-Host ""<br />Write-Host "---------------Setting Permissions for Folder $VMFolderName"<br />Write-Host ""<br />$VMSvcAccountFQN = 'NT VIRTUAL MACHINE\'+$VMSvcAccount<br />cmd /c icacls ""$VMFolderName"" /T /grant ""$VMSvcAccountFQN""':(F)'<br />Write-Host ""<br />Write-Host "---------------Finished Permissions for Folder $VMFolderName"</span></p>
<p><br /><span style="font-family: courier new,courier;">#Discover if there are any Snapshots. If so, for each one, create a Symbolic link for each by passing the FQN of the snapshot and snapsot link location<br />#Also, call SetACL to set permissions for the VM Services account on the Symbolic Link<br />foreach ($Thing in (Get-ChildItem $VMFolderName))<br />{<br />&nbsp;&nbsp;&nbsp; If ($Thing.name -eq "Snapshots")<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp; $SnapshotsFolder = $Thing.Fullname<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach ($Thing2 in (Get-ChildItem $SnapshotsFolder))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ($Thing2.extension -eq ".xml")<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $VMSnapshotFileString = $Thing2.name<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MkSymLink -HardFile $Thing2.fullname -LinkLocation "Snapshots"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $SnapshotFileSymLink = "$SystemDrive\programdata\Microsoft\Windows\Hyper-V\Snapshots\$VMSnapshotFileString"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetACL -ThisItem $SnapshotFileSymLink<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br />Write-Host ""<br />Write-Host "----------------End Script Recover-VM.ps1"</span></p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/prod.evol.blogs.technet.com/telligent.evolution.components.attachments/01/7148/00/00/03/37/50/94/Recover-VM.ps1.txt" original-url="https://blogs.technet.com/cfs-filesystemfile.ashx/__key/telligent-evolution-components-attachments/01-7148-00-00-03-37-50-94/Recover_2D00_VM.ps1.txt">Recover-VM.ps1.txt</a></p>]]></content:encoded>
    </item>
    <item>
      <title>FRS Problem when Virtualising a Domain Controller</title>
      <link>https://docs.microsoft.com/archive/blogs/carlh/frs-problem-when-virtualising-a-domain-controller</link>
      <pubDate>Tue, 22 Jun 2010 07:41:00 GMT</pubDate>
      <dc:creator><![CDATA[carl h2]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/carlh/2010/06/22/frs-problem-when-virtualising-a-domain-controller/</guid>
      <description><![CDATA[I recently had to assist&nbsp;someone who had virtualised a single Windows 2003 Domain Controller...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: small;">I recently had to assist&nbsp;someone who had virtualised a single Windows 2003 Domain Controller from physical hardware to a virtualised Virtual Guest file using a third party (Non Microsoft) utility (not that I am saying this issue would be any different using a Microsoft utility).&nbsp;This is not an advised\recommended practice for Domain Controllers, but in this instance they had no choice and the DC concerned was in fact a single DC (once again; Bad Practice, I know, but we work with what we have sometimes) in a test environment. Ignoring the list of&nbsp;bad practices, the resulting DC was producing Event ID 13559 errors in the NTFRS log (see description below)</span></span></p>
<p class="MsoNormal"><span style="mso-fareast-font-family: 'Times New Roman';"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;"><span style="font-family: courier new,courier;"><span style="font-size: small;">The File Replication Service has detected that the replica root path has changed from "x:\windows\sysvol\domain" to "x:\windows\sysvol\domain". If this is an intentional move then a file with the name NTFRS_CMD_FILE_MOVE_ROOT needs to be created under the new root path. This was detected for the following replica set: "DOMAIN SYSTEM VOLUME (SYSVOL SHARE)" <o:p></o:p></span></span></span></span></span></span></p>
<p class="MsoNormal"><span style="font-size: 12pt; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-GB; mso-fareast-language: EN-GB; mso-bidi-language: AR-SA;"><span style="font-family: arial,helvetica,sans-serif;"><span style="font-size: x-small;"><span style="font-family: courier new,courier;"><span style="font-size: small;">Changing the replica root path is a two step process which is triggered by the creation of the NTFRS_CMD_FILE_MOVE_ROOT file. [1] At the first poll which will occur in 5 minutes this computer will be deleted from the replica set. [2] At the poll following the deletion this computer will be re-added to the replica set with the new root path. This re-addition will trigger a full tree sync for the replica set. At the end of the sync all the files will be at the new location. The files may or may not be deleted from the old location depending on whether they are needed or not.</span></span></span></span></span></p>
<p><span style="font-size: small;">Indeed the description is also discussed in this KB article </span><a href="https://support.microsoft.com/kb/887440"><span style="font-size: small;">https://support.microsoft.com/kb/887440</span></a><span style="font-size: small;"> and it&nbsp;would appear that the disk signatures for the volumes that host the SYSVOL folder structure are changed during the conversion of the system from physical to virtual. Following the procedures detailed in the error event and in the article did in fact remedy the situation and the NTFRS event logs showed this fact by logging 13560, 13553 and 13516 (which effectively proves the DC is functioning correctly from and FRS\SYSVOL perspective) over a period of time.</span></p>
<p><span style="font-size: small;">This issue has also been seen during the Restore of a Domain Controller from backup or during a failed attempt to move SYSVOL to another volume as per this article&nbsp;</span><a href="https://support.microsoft.com/kb/842162"><span style="font-size: small;">https://support.microsoft.com/kb/842162</span></a></p>]]></content:encoded>
    </item>
    <item>
      <title>Windows 2008 R2 Domain Controller Backup Lifetime advice</title>
      <link>https://docs.microsoft.com/archive/blogs/carlh/windows-2008-r2-domain-controller-backup-lifetime-advice</link>
      <pubDate>Wed, 23 Dec 2009 06:21:00 GMT</pubDate>
      <dc:creator><![CDATA[carl h2]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/carlh/2009/12/23/windows-2008-r2-domain-controller-backup-lifetime-advice/</guid>
      <description><![CDATA[I was asked why we recommend not using backups older than the lesser of TSL and Deleted Lifetime...]]></description>
      <content:encoded><![CDATA[<P><I></I></P>
<P>I was asked why we recommend not using backups older than the lesser of TSL and Deleted Lifetime and below is my interpretation of the answer I got from a reputable source.</P>
<P>There are 2 main reasons we advise not using backups longer than the lesser of Deleted Lifetime and Tombstone Lifetime.</P>
<P>The first reason is very much the same as it has always been. We don’t want the possibility of introducing Lingering Objects. Basically, if you do a restore older than TSL this will introduce what the replication engine perceives as Lingering Objects and Strict Replication Consistency will kick in and stop Replication. Although the objects should disappear and not cause an issue in most circumstances, you still have replication failed and will have to use non recommended methods of getting it going again (i.e. “Allow Replication with Divergent or Corrupt Partner” registry Hack).</P>
<P>The second reason is more to do with the way group memberships are stored in the Link Table for Deleted objects in Windows 2008 R2 with the Recycle Bin feature enabled. Basically, when an object is removed from a group, the Link table (in the database) is updated with a flag and date stamp marking the object that has been removed as “De-activated”. When an object is deleted the groups to which it was a member retain the object as a member, but another flag “Deleted” is added with the time stamp. Both the “Deleted” and “De-activated” flags effectively make the objects not visible as members of the group. In other words the Link table still has some knowledge that an object was a member of a group (remember, group membership is stored by the group not the object that is a member of a group). This enables the ability to ensure that when an object is undeleted it gets added back to any groups it used to be a member of. The “De-activated” and “Deleted” flag is removed from the Link Table after Deleted Lifetime (i.e. as an object becomes a Recycled object; Tombstoned in previous versions). If a backup older than Deleted Lifetime is used then we will not get group membership back of objects as expected (at best), at worst we could have inconsistent link tables across DC’s (although this is a slim chance and needs certain circumstances to occur. Of which I am not sure if I totally understand).</P>]]></content:encoded>
    </item>
    <item>
      <title>Online Kernel Memory Dump using LiveKd.exe</title>
      <link>https://docs.microsoft.com/archive/blogs/carlh/online-kernel-memory-dump-using-livekd-exe</link>
      <pubDate>Mon, 30 Nov 2009 08:14:00 GMT</pubDate>
      <dc:creator><![CDATA[carl h2]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/carlh/2009/11/30/online-kernel-memory-dump-using-livekd-exe/</guid>
      <description><![CDATA[How many times have you had to acquire a kernel memory dump, but you or your customer (quite...]]></description>
      <content:encoded><![CDATA[<p style="margin: 0cm 0cm 10pt" class="MsoNormal"><span style="color: black; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: calibri; mso-fareast-font-family: &#39;Times New Roman&#39;"><font face="tahoma,arial,helvetica,sans-serif">How many times have you had to acquire a kernel memory dump, but you or your customer (quite rightly) refuses to have the target system attached to the internet (which usually needed to download the symbol files). Well, I have had the dubious pleasure 3 times in the past 3 months. So, to remind me of the process I decided to write it down for future reference. If you know this already, sorry to waste your time, but for everyone else it’s one for your cerebral index.            </font></span></p>  <p style="margin: 0cm 0cm 10pt" class="MsoNormal"><font face="tahoma,arial,helvetica,sans-serif"><span style="color: black; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-bidi-font-family: calibri; mso-fareast-font-family: &#39;Times New Roman&#39;">Firstly you need to get the correct symbols files for the kernel memory dump, and just downloading the ones from WHDC or MSDN for the OS version and Service Pack version is not quite good enough, because the symbols change for each version of the kernel files that are released. There may be kernel files that have changed with Updates since the Service Pack was released.</span><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; color: black; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">            </span></font></p>  <p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoListParagraph"><font face="tahoma,arial,helvetica,sans-serif"><span style="font-size: 10pt; mso-bidi-font-family: calibri; mso-fareast-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-theme-font: minor-latin"><span style="mso-list: ignore">1.<span style="font: 7pt &#39;Times New Roman&#39;"><font size="2">&#160;&#160;&#160; </font></span></span></span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">Install the Windows Debugging Tools </span></font><a href="https://www.microsoft.com/whdc/DevTools/Debugging/default.mspx" mce_href="https://www.microsoft.com/whdc/DevTools/Debugging/default.mspx"><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt"><font face="tahoma,arial,helvetica,sans-serif">https://www.microsoft.com/whdc/DevTools/Debugging/default.mspx</font></span></a><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt"><font face="tahoma,arial,helvetica,sans-serif"> on the computer from which you require a kernel memory dump.            </font></span></p>  <p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoListParagraph"><font face="tahoma,arial,helvetica,sans-serif"><span style="font-size: 10pt; mso-bidi-font-family: calibri; mso-fareast-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-theme-font: minor-latin"><span style="mso-list: ignore">2.&#160;&#160; </span></span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">Download LiveKd from </span></font><a href="https://www.microsoft.com/technet/sysinternals/SystemInformation/LiveKd.mspx" mce_href="https://www.microsoft.com/technet/sysinternals/SystemInformation/LiveKd.mspx"><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt"><font color="#0000ff" face="tahoma,arial,helvetica,sans-serif">https://www.microsoft.com/technet/sysinternals/SystemInformation/LiveKd.mspx</font></span></a><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt"><font face="tahoma,arial,helvetica,sans-serif"> and on the computer that you require a Kernel Memory Dump from, uncompress it to the location that the Windows Debug Tools have been installed to (the default is &quot;C:\Program Files\Debugging Tools for Windows (X86)\&quot;).            </font></span></p>  <p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoListParagraph"><font face="tahoma,arial,helvetica,sans-serif"><span style="font-size: 10pt; mso-bidi-font-family: calibri; mso-fareast-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-theme-font: minor-latin"><span style="mso-list: ignore">3.<span style="font: 7pt &#39;Times New Roman&#39;"><font size="2">&#160;&#160;&#160; </font></span></span></span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">Copy ntoskrnl.exe, ntkrnlpa.exe, kernel32.dll and ntdll.dll files (not sure if all of these are required every time, but I do it just in case) from the System32 folder of the computer to be debugged (without internet access) and copy them to a folder (e.g. c:\debugsymbols\system32) on a computer with internet access. (If the internet facing computer has the same versions of these files to the non internet facing then there is no need for this part, but the Symbol cache will be enormous and all we want is the symbol files for the kernel).            </span></font></p>  <p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoListParagraph"><font face="tahoma,arial,helvetica,sans-serif"><span style="font-size: 10pt; mso-bidi-font-family: calibri; mso-fareast-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-theme-font: minor-latin"><span style="mso-list: ignore">4.<span style="font: 7pt &#39;Times New Roman&#39;"><font size="2">&#160;&#160;&#160; </font></span></span></span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">Install the Debugging tools on the internet facing system (or copy the installed folder from the server you installed them on previously; the default is “C:\Program Files\Debugging Tools for Windows”).            </span></font></p>  <p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoListParagraph"><font face="tahoma,arial,helvetica,sans-serif"><span style="font-size: 10pt; mso-bidi-font-family: calibri; mso-fareast-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-theme-font: minor-latin"><span style="mso-list: ignore">5.<span style="font: 7pt &#39;Times New Roman&#39;"><font size="2">&#160;&#160;&#160; </font></span></span></span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">From a command prompt on the Internet facing server, run this command:            </span></font></p>  <p style="margin: 0cm 0cm 10pt 36pt" class="MsoNormal"><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin">     <p><font face="tahoma,arial,helvetica,sans-serif">&#160;</font></p>   </span></p>  <p style="margin: 0cm 0cm 10pt 36pt" class="MsoNormal"><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin">        </span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"><font face="tahoma,arial,helvetica,sans-serif">C:\&lt;path to debugging tools&gt;\<b style="mso-bidi-font-weight: normal">Symchk.exe<span style="mso-spacerun: yes">&#160;&#160; </span>/if &lt;path to copied file&gt;\*.*<span style="mso-spacerun: yes">&#160;&#160; </span>/s srv*&lt;path to folder to store symbols locally&gt;*https://msdl.microsoft.com/download/symbols</b>             </font></span></p>  <p style="margin: 0cm 0cm 10pt 36pt" class="MsoNormal"><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"><font face="tahoma,arial,helvetica,sans-serif">e.g. C:\Program Files\Debugging Tools for Windows (x86)&gt;<b style="mso-bidi-font-weight: normal">Symchk.exe /if c:\debugsymbols\system32\*.* /s srv*c:\debugsymbols*https://msdl.microsoft.com/download/symbols</b></font></span></p>  <p style="margin: 0cm 0cm 10pt 36pt" class="MsoNormal"><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin">        </span><font face="tahoma,arial,helvetica,sans-serif">&#160;</font></p>  <p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoListParagraph"><font face="tahoma,arial,helvetica,sans-serif"><span style="font-size: 10pt; mso-bidi-font-family: calibri; mso-fareast-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-theme-font: minor-latin"><span style="mso-list: ignore">6.<font face="tahoma,arial,helvetica,sans-serif">&#160;&#160; </font></span></span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">Copy the cached symbols (i.e. the c:\debugsymbols folder and its new contents, minus the \system32 folder with the 4 exe\dll’s in it) from the internet facing server to the original server.            </span></font></p>  <p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoListParagraph"><font face="tahoma,arial,helvetica,sans-serif"><span style="font-size: 10pt; mso-bidi-font-family: calibri; mso-fareast-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-theme-font: minor-latin"><span style="mso-list: ignore">7.&#160;&#160; </span></span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">On the computer that you require a Kernel Memory Dump from, Open <b style="mso-bidi-font-weight: normal">WinDbg</b>, click on the <span style="mso-spacerun: yes">&#160;</span><b style="mso-bidi-font-weight: normal">&quot;File&quot;</b> menu, and choose <b style="mso-bidi-font-weight: normal">&quot;Symbol Search Path&quot;</b>. Enter the following path <b style="mso-bidi-font-weight: normal">SRV*c:\debugsymbols*</b> and click Ok. Close Windbg.exe.             </span></font></p>  <p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoListParagraph"><font face="tahoma,arial,helvetica,sans-serif"><span style="font-size: 10pt; mso-bidi-font-family: calibri; mso-fareast-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-theme-font: minor-latin"><span style="mso-list: ignore">8.<span style="font: 7pt &#39;Times New Roman&#39;"><font size="2">&#160;&#160;&#160; </font></span></span></span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">With Administrator privileges, open a Command prompt and navigate to the WinDbg installation folder (e.g<b style="mso-bidi-font-weight: normal">. C:\Program Files\Debugging Tools for Windows (X86)\</b>) if this is where you expanded LiveKd to and run <b style="mso-bidi-font-weight: normal">livekd.exe</b>.              </span></font></p>  <p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoListParagraph"><font face="tahoma,arial,helvetica,sans-serif"><span style="font-size: 10pt; mso-bidi-font-family: calibri; mso-fareast-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-theme-font: minor-latin"><span style="mso-list: ignore">9.<span style="font: 7pt &#39;Times New Roman&#39;"><font size="2">&#160;&#160;&#160; </font></span></span></span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">Type “<b style="mso-bidi-font-weight: normal">.dump<span style="mso-spacerun: yes">&#160; </span>-f c:\memory.dmp”</b> (without the quotes) to generate the Complete Memory Dump on the C: drive (you will need to make sure there is enough space on this drive).              </span></font></p>  <p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoListParagraph"><font face="tahoma,arial,helvetica,sans-serif"><span style="font-size: 10pt; mso-bidi-font-family: calibri; mso-fareast-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-theme-font: minor-latin"><span style="mso-list: ignore">10.<span style="font: 7pt &#39;Times New Roman&#39;"><font size="2">&#160; </font></span></span></span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">Type <b style="mso-bidi-font-weight: normal">q</b> to quit LiveKD.             </span></font></p>  <p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoListParagraph"><font face="tahoma,arial,helvetica,sans-serif"><span style="font-size: 10pt; mso-bidi-font-family: calibri; mso-fareast-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-fareast-theme-font: minor-latin"><span style="mso-list: ignore">11.<span style="font: 7pt &#39;Times New Roman&#39;"><font size="2">&#160; </font></span></span></span><span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">You should find memory.dmp in the root of c:\</span></font></p>  <p style="margin: 0cm 0cm 10pt" class="MsoNormal">   <p><font face="tahoma,arial,helvetica,sans-serif">&#160;</font></p> </p>  <p style="margin: 0cm 0cm 10pt" class="MsoNormal"><font face="tahoma,arial,helvetica,sans-serif">Your work is now complete and you can compress and deliver the kernel dump for analysis.</font></p>]]></content:encoded>
    </item>
  </channel>
</rss>