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

<channel>
	<title>Glo Networks Technical Blog (Glo Blog) &#187; NTFS permission changes using powershell</title>
	<atom:link href="http://blog.glo-networks.com/tag/ntfs-permission-changes-using-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.glo-networks.com</link>
	<description>Glo Networks team sharing their technical experiences and thoughts.</description>
	<lastBuildDate>Wed, 18 Jan 2012 17:35:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Fixing redirected My Docs permissions, using Powershell</title>
		<link>http://blog.glo-networks.com/2008/07/30/fixing-redirected-my-docs-permissions-using-powershell/</link>
		<comments>http://blog.glo-networks.com/2008/07/30/fixing-redirected-my-docs-permissions-using-powershell/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 15:38:43 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Desktops and Laptops]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[my documents]]></category>
		<category><![CDATA[NTFS permission changes using powershell]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://blog.glo-net.net/?p=29</guid>
		<description><![CDATA[For many of our customers we redirect a user&#8217;s My Documents to a directory of the same name, on a Windows share. For example, the user &#8216;JMcMuffin&#8217; may have their My Docs redirected to &#8220;\\FILESERVER\Home\JMcMuffin\My Documents&#8221;, which are stored in a local path of D:\Data\Users\JMcMuffin, on FILESERVER. Obviously you can switch \\FILESERVER\Home for a DFS [...]]]></description>
			<content:encoded><![CDATA[<p>For many of our customers we redirect a user&#8217;s My Documents to a directory of the same name, on a Windows share. For example, the user &#8216;JMcMuffin&#8217; may have their My Docs redirected to &#8220;\\FILESERVER\Home\JMcMuffin\My Documents&#8221;, which are stored in a local path of D:\Data\Users\JMcMuffin, on FILESERVER. Obviously you can switch \\FILESERVER\Home for a DFS share, etc.</p>
<p>In some instances you might have a significant number and for whatever reason the permissions may have been altered, and the Group Policy defaults don&#8217;t quite suit your requirements. Or maybe you&#8217;re transfering these files to a new server, in a different domain. I can&#8217;t image you want to do the whole thing by hand.</p>
<p>In days of old we&#8217;d sort this with a batch script and it would be ok, but might take a while to run. Powershell has changed things though. The script we&#8217;ve popped together (below) runs lightning quick in comparison, and we thought someone else might also find it useful.</p>
<p>Just save it in a ps1 file, and invoke it from powershell, providing your directory path that you want to &#8220;fix&#8221;.</p>
<p>To use our example from above, you&#8217;d call the script on FILESERVER, from powershell:</p>
<blockquote><p>PS C:\Users\Karl&gt; C:\path\to\scripts\fix-perms.ps1 &#8220;D:\Data\Users&#8221;</p></blockquote>
<p>The script would then go over each directory and try and add that user to the ACL with Modify rights &#8211; i.e. the JcMcMuffin user to the D:\Data\Users\JMcMuffin directory.</p>
<p>In our scenario we required ourselves, another group, SYSTEM and each user to have access only &#8211; So we pushed the common permissions from the parent, and then ran the script to add the individual users.</p>
<blockquote><p># Fix-Perms<br />
# Iterates over all child directories, and adds the user, with the same name as the directory, to the ACL with modify rights<br />
# Usage:<br />
# Fix-Perms &#8220;C:\Path\To\Directory&#8221;<br />
# Or, for the current directory<br />
# Fix-Perms &#8220;.&#8221;</p>
<p># our parameters, throw a warning if we get none<br />
param (<br />
[string] $dirpath = $(throw &#8220;Please specify the full path to the directory!&#8221;)<br />
)</p>
<p># get list of all child directories, in the current directory<br />
$directories = dir $dirpath | where {$_.PsIsContainer}</p>
<p># iterate over the directories<br />
foreach ($dir in $directories)<br />
{<br />
# echo out what the full directory is that we&#8217;re working on now<br />
write-host Working on $dir.fullname using $dir.name</p>
<p># setup the inheritance and propagation as we want it<br />
$inheritance = [system.security.accesscontrol.InheritanceFlags]&#8220;ContainerInherit, ObjectInherit&#8221;<br />
$propagation = [system.security.accesscontrol.PropagationFlags]&#8220;None&#8221;</p>
<p># get the existing ACLs for the directory<br />
$acl = get-acl $dir.fullname</p>
<p># add our user (with the same name as the directory) to have modify perms<br />
$aclrule = new-object System.Security.AccessControl.FileSystemAccessRule($dir.name, &#8220;Modify&#8221;, $inheritance, $propagation, &#8220;Allow&#8221;)</p>
<p># check if given user is Valid, this will barf if not<br />
$sid = $aclrule.IdentityReference.Translate([System.Security.Principal.securityidentifier])</p>
<p># add the ACL to the ACL rules<br />
$acl.AddAccessRule($aclrule)</p>
<p># set the acls<br />
set-acl -aclobject $acl -path $dir.fullname<br />
}</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.glo-networks.com/2008/07/30/fixing-redirected-my-docs-permissions-using-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

