<?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>The NetFlow &#187; Microsoft Windows</title>
	<atom:link href="http://www.thenetflow.com/tag/microsoft-windows/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thenetflow.com</link>
	<description>Excited? You shouldn&#039;t be... A blog about everything. Technology Travel Life</description>
	<lastBuildDate>Wed, 04 Jan 2012 14:03:34 +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>Mass update of Active Directory using PowerShell</title>
		<link>http://www.thenetflow.com/2010/mass-update-of-active-directory-using-powershell/</link>
		<comments>http://www.thenetflow.com/2010/mass-update-of-active-directory-using-powershell/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 08:37:21 +0000</pubDate>
		<dc:creator>Dan O'Neill</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[AD]]></category>
		<category><![CDATA[Microsoft Windows]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://www.thenetflow.com/?p=657</guid>
		<description><![CDATA[PowerShell is a very handy scripting language if you need to play around with Microsoft technologies. It's gotten me out of more than one difficult situation. The thing that comes up most at the minute for me is updating AD or Active Directory en masse. <a href="http://www.thenetflow.com/2010/mass-update-of-active-directory-using-powershell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>PowerShell is a very handy scripting language if you need to play around with Microsoft technologies. It&#8217;s gotten me out of more than one difficult situation. The thing that comes up most at the minute for me is updating AD or Active Directory en masse.</p>
<p>Say you update your phone system or you merge with another company and have to update phone numbers in your AD address book without having to do it manually. PowerShell to the rescue.</p>
<p>First you need to create a .csv file with all the names and new phone numbers that you want the users to be updated to. It should look something like this:</p>
<pre>
user,phonenumber
Dan O'Neill,+353 1 234 5678
Brad Pitt,+353 1 123 4567
Frank Bruno,+353 1 235 6789</pre>
<p>This will be read by the PowerShell script. Reading in files in PowerShell is simple to understand. All you really need to know is that it reads files line by line and sometimes there are even cmdlets that will look after the import for you. In this case we can use Import-CSV.</p>
<pre>$userlist = "C:\temp\import.csv"
$UserDetails=Import-CSV $userlist</pre>
<p>Nice and easy &#8211; then we need to iterate through this list and actually do what we&#8217;re looking to do &#8211; Update a large list of users in AD with PowerShell &#8211; in this example, update everyones phone number.</p>
<p>So, as we&#8217;ve imported the csv file we&#8217;re then able to iterate through it line by line. As we move through it, we assign the value to a variable. Like so:</p>
<pre>
foreach($UD in $UserDetails) {
	$user = $UD.user
	$phnumber = $UD.phonenumber
</pre>
<p>The next stage is the first time we connect with AD and it&#8217;s quite an important part of the script. We want to check that the user in the file is an actual user in AD. In this case, I&#8217;ve been given names &#8211; so I check this against the CN in AD. However, you could check against any unique field in AD like username(SAMaccountname) or something like that. The following line assigns TRUE or FALSE to our variable $UserN:</p>
<pre>
$UserN=[ADSI]::Exists("LDAP://ad.domain.com/cn=$user,ou=Users,dc=ad,dc=domain,dc=com")
</pre>
<p>Then comes the actual interesting bit. We check whether that has come back with false&#8230;</p>
<pre>
if($UserN -ne $FALSE){
</pre>
<p>&#8230;and if it hasn&#8217;t then we apply the changes that we need to.</p>
<pre>
$UserN=[ADSI]"LDAP://ad.domain.com/cn=$user,ou=Users,dc=ad,dc=domain,dc=com"
$UserN.Put("telephoneNumber",$phnumber)
$UserN.SetInfo()
write-host $user "has been modified"
</pre>
<p>Very simple and straight forward. And since we want to be able to tell afterwards which users worked and which didn&#8217;t, the other part of that if&#8230;else loop looks like this:</p>
<pre>
}
else{
        write-host $user "object does not exist" -foregroundcolor red -backgroundcolor yellow
}
</pre>
<p>This prints out to your console in nice red font and yellow background which users failed to update. </p>
<p>In full the script looks like this:</p>
<pre>
$userlist = "C:\temp\import.csv"
$UserDetails=Import-CSV $userlist
foreach($UD in $UserDetails) {
	$user = $UD.user
	$phnumber = $UD.phonenumber
        $UserN=[ADSI]::Exists("LDAP://ad.domain.com/cn=$user,ou=Users,dc=ad,dc=domain,dc=com")
        if($UserN -ne $FALSE){
		$UserN=[ADSI]"LDAP://ad.domain.com/cn=$user,ou=Users,dc=ad,dc=domain,dc=com"
		$UserN.Put("telephoneNumber",$phnumber)
	   	$UserN.SetInfo()
		write-host $user "has been modified"
	}
        else{
            	write-host $user "object does not exist" -foregroundcolor red -backgroundcolor yellow
        }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thenetflow.com/2010/mass-update-of-active-directory-using-powershell/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Hidden traverse folder permissions</title>
		<link>http://www.thenetflow.com/2010/hidden-traverse-folder-permissions/</link>
		<comments>http://www.thenetflow.com/2010/hidden-traverse-folder-permissions/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 17:35:46 +0000</pubDate>
		<dc:creator>Dan O'Neill</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[Bypass traverse checking]]></category>
		<category><![CDATA[GPO]]></category>
		<category><![CDATA[Microsoft Windows]]></category>
		<category><![CDATA[NTFS permissions]]></category>
		<category><![CDATA[traverse permissions]]></category>

		<guid isPermaLink="false">http://www.thenetflow.com/?p=619</guid>
		<description><![CDATA[Recently, I found users bypassing the top level NTFS security permissions on a folder via a nice piece of group policy that I'd never heard of. The previously unknown - to me - Bypass traverse checking policy. <a href="http://www.thenetflow.com/2010/hidden-traverse-folder-permissions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We all folder permission projects, you&#8217;re going to get odd situations where users have access to resources that you hadn&#8217;t planned. Usually minor and easy to fix like an active directory grouping error. Or some inheritance that you forgot to force.</p>
<p>One thing that I&#8217;ve come across recently from a bit of a odd situation is the <strong>Bypass traverse checking</strong> group policy object.</p>
<p>Basically, what this allows users to do, is traverse folders that they should have no access to&#8230;</p>
<p>This is how it is explained in <a href="http://technet.microsoft.com/en-us/library/cc739389(WS.10).aspx">Microsoft&#8217;s technet article</a> about it&#8230;</p>
<blockquote><p>This user right determines which users can traverse directory trees even though the user may not have permissions on the traversed directory. This privilege does not allow the user to list the contents of a directory, only to traverse directories.</p></blockquote>
<p>This normally would bother anyone, unless during a very sensitive data move that requires you leave the permissions of the underlying data alone. In this case, you have a top level folder with a certain set of permissions but because of an audit rule you have to leave the permissions on the lower level folders alone for a period of time.</p>
<p>You would expect the users not to be able to get to the data below the top level folder &#8211; why should they? You&#8217;ve set the permissions correctly on the top of the folder and then the <strong>Bypass traverse checking</strong> group policy object steps in. And ruins your day.</p>
<p>Slight exaggeration, and easily dealt with since we don&#8217;t knowingly use this GPO for anything else in the server. This is the default user set that can, by default, gain access via this group policy:</p>
<ul>
<li>Administrators</li>
<li>Backup Operators</li>
<li>Power Users</li>
<li>Users</li>
<li>Everyone</li>
</ul>
<p>Out comes the &#8220;everyone&#8221; group, and now we&#8217;re nicely audit compliant.</p>
<p>Normally this would not be a problem as most of you will force replication after a folder move, thus inherit the permissions of the top level folder and block the user from traversing the folder as they will have no access to the folder below the top level.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thenetflow.com/2010/hidden-traverse-folder-permissions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Search all the computers in your domain</title>
		<link>http://www.thenetflow.com/2009/search-computers-domain/</link>
		<comments>http://www.thenetflow.com/2009/search-computers-domain/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 15:53:52 +0000</pubDate>
		<dc:creator>Dan O'Neill</dc:creator>
				<category><![CDATA[Bat]]></category>
		<category><![CDATA[bat]]></category>
		<category><![CDATA[Batch file]]></category>
		<category><![CDATA[Command-line interface]]></category>
		<category><![CDATA[computers]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[Mark Russinovich]]></category>
		<category><![CDATA[Microsoft Windows]]></category>
		<category><![CDATA[Operating system]]></category>
		<category><![CDATA[psexec]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[System administrator]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.thenetflow.com/?p=370</guid>
		<description><![CDATA[Sometimes, as part of an IT team, you&#8217;ll get a strange request to search every PC in your domain for a particular file, or files containing particular information. Also, you couldn&#8217;t just search for a file name as someone might &#8230; <a href="http://www.thenetflow.com/2009/search-computers-domain/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes, as part of an IT team, you&#8217;ll get a strange request to search every PC in your domain for a particular file, or files containing particular information. Also, you couldn&#8217;t just search for a file name as someone might have renamed the file. At first I would have said that it was an impossibly hard task but in the end it turned out to be not as hard as it seems, with a little scripting knowledge.</p>
<p>Obviously, the first suggestion was to go to each PC and start a search. Ouch. That would have taken an age and would have to be done when no-one is at the desk. And with hundred&#8217;s of PC&#8217;s to look after this really wasn&#8217;t a good idea.</p>
<p>So, wanting to show off my meagre scripting skills (but mostly to avoid walking around the entire office) I said that I would be able to script a solution to search every PC remotely. Although, I&#8217;m pretty good at scripting  pretty simple tasks, I had no idea if I could do this.</p>
<p>First, I had to see if I could search my own PC with a command line tool. I considered a couple of options &#8211; either FIND or FINDSTR. I decided to go with FINDSTR as there are loads of options and useful switches. I also wanted to reduce the time it would take to search my PC. I took a look at the security settings and basically decided that it would be a waste of resources to search every file and folder on the PC as our PCs are locked down so that users only have write permission on certain folders. So I could narrow the search down to those folders. So part 1 of my script became:</p>
<blockquote><p><em>findstr /s /M /D:c:\Temp\;c:\docume~1\; /C:&#8221;Phrase to Search For&#8221; *.xls</em></p></blockquote>
<p>Let me explain the switches in use here:</p>
<ul>
<li>/s &#8211; Search all subfolders</li>
<li>/M &#8211; Only print out the filename of files that contain the phrase. The default is to display where in the file it is too.</li>
<li>/D: &#8211; The directories to search in a list separated by semi-colons.</li>
<li>/C: &#8211; The literal search string</li>
<li>and the last option is the files to search. In this case &#8211; all files that have the .xls suffix. i.e. Excel files.</li>
</ul>
<p>This line worked excellently and produced the following output:</p>
<blockquote><p><em>c:\Temp\:<br />
c:\docume~1\:<br />
username\Local Settings\Temporary Internet Files\OLK10\stupidfile.xls</em></p></blockquote>
<p>This shows that it found a file in my documents and settings folder with the above phrase in it. Excellent, so now I could move onto the next task &#8211; running this script on every PC and with admin rights, so that every folder could be searched.</p>
<p>In steps the <a class="zem_slink" title="System administrator" rel="wikipedia" href="http://en.wikipedia.org/wiki/System_administrator">Systems Administrator</a>&#8216;s best friend &#8211; <a title="PSTools" href="http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx">PSTOOLS</a>. Literally the best selection of admin tools for the <a class="zem_slink" title="Microsoft Windows" rel="wikipedia" href="http://en.wikipedia.org/wiki/Microsoft_Windows">Windows</a> Systems Administrator, from the legendary <a class="zem_slink" title="Mark Russinovich" rel="wikipedia" href="http://en.wikipedia.org/wiki/Mark_Russinovich">Mark Russinovich</a>. One of them &#8211; psexec.exe &#8211; does exactly what I need it to do. It allowed me to send out the above bat file to a huge list of machines and run it remotely using whatever user account I need to.</p>
<blockquote><p><em>psexec @list.txt -u domain\adminadccount -d -c search.bat</em></p></blockquote>
<p>Let me explain the switches in use here:</p>
<ul>
<li>@list.txt &#8211; basically this list contains every machine that you want to run the command on.</li>
<li>-u &#8211; this allows out to stipulate the account to run the command under. In this case the fictional <em>domain\adminaccount</em> account</li>
<li>-d &#8211; dont wait for the command to finish before carrying on. I was able to do this by using the bat file to output to a cetral location.</li>
<li>-c &#8211; this switch copies the following bat file locally to the machines in question before running it. This is important because I had local drives specified in the bat script.</li>
</ul>
<p>This ran on the test machines fine. Next stage was to pipe the output to somewhere nice and central and in manner that would allow us to differentiate the output from each machine. You couldn&#8217;t output everything to one file or you would have different machines outputting to the file at different times so depending on when the search was started it would output at different times and the file would become unreadable and full of meaningless data.  To avoid this I did a little roundabout way of outputting to files. I did this by getting the bat file to create a txt file based on the PC name:</p>
<blockquote><p><em>echo %COMPUTERNAME% &gt;&gt; \\centrallocation\%COMPUTERNAME%.txt<br />
findstr /s /M /D:c:\Temp\;c:\docume~1\; /C:&#8221;Phrase to Search For&#8221; *.xls &gt;&gt; \\centrallocation\%COMPUTERNAME%.txt<br />
If %ERRORLEVEL% EQU 0 ECHO %COMPUTERNAME% had a copy of the file &gt;&gt; \\centrallocation\overall.txt</em></p></blockquote>
<p>Note &#8211; The above should only be three lines. This was the full search.bat file but let me explain it:</p>
<p>First line created a file called computer name and on the first line of that file wrote the computername. You may not need this but for peice of mind I did this to be able to show management that it actually ran on the machine.</p>
<p>Next line outputs the findstr command from above to that same file. Often this would just output two lines with the directories searched as nothing would be found on the machine. However if the file was found it would also output that information.</p>
<p>The next line is very important. It is what the entire bat file relies on to make it simple for you to find the machines with the file. Even though the line above has created files for every PC, and all the information is held within them, it would be a very timeconsuming task to go through each one. Basically if findstr <strong>doesn&#8217;t</strong> find a file that you&#8217;re looking for it will change <strong>%ERRORLEVEL% to greater than 0</strong>. If it <strong>does </strong>find it however find a file the <strong>%ERRORLEVEL% will be 0</strong>. So if that is so then we output the computername to a file called overall.txt. This then gives us a list of PC&#8217;s where the file was found and we can then go to the corresponding computername.txt and find the location where the file was found.</p>
<p>So that&#8217;s how I did it. I wouldn&#8217;t mind hearing any different ways to do it from anyone out there so get in touch in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thenetflow.com/2009/search-computers-domain/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Console switch for mstsc?</title>
		<link>http://www.thenetflow.com/2009/console-switch-for-mstsc/</link>
		<comments>http://www.thenetflow.com/2009/console-switch-for-mstsc/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 13:16:15 +0000</pubDate>
		<dc:creator>Dan O'Neill</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Microsoft Windows]]></category>
		<category><![CDATA[Remote Desktop Protocol]]></category>
		<category><![CDATA[Windows Server 2008]]></category>
		<category><![CDATA[Windows Vista]]></category>
		<category><![CDATA[Windows XP]]></category>

		<guid isPermaLink="false">http://www.thenetflow.com/?p=352</guid>
		<description><![CDATA[As a Systems Administrator, I do a lot of troubleshooting every day for end-users. I also look after a number of servers and often have to complete very long tasks on these servers. One particular job that I&#8217;m working on &#8230; <a href="http://www.thenetflow.com/2009/console-switch-for-mstsc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As a <a class="zem_slink" title="System administrator" rel="wikipedia" href="http://en.wikipedia.org/wiki/System_administrator">Systems Administrator</a>, I do a lot of troubleshooting every day for end-users. I also look after a number of servers and often have to complete very long tasks on these servers. One particular job that I&#8217;m working on at the minute is importing users <a class="zem_slink" title="Personal Storage Table" rel="wikipedia" href="http://en.wikipedia.org/wiki/Personal_Storage_Table">.pst</a> files into <a class="zem_slink" title="Enterprise Vault" rel="homepage" href="http://www.symantec.com/enterprisevault">Enterprise Vault</a> archives. This is a time consuming process that requires you to be logged in all the time.</p>
<p>So normally, I&#8217;d open up a console <a class="zem_slink" title="Remote Desktop Protocol" rel="wikipedia" href="http://en.wikipedia.org/wiki/Remote_Desktop_Protocol">RDP</a> session to the win2003 server using <strong><a class="zem_slink" title="Terminal Services" rel="wikipedia" href="http://en.wikipedia.org/wiki/Terminal_Services">mstsc</a> /v: <em>servername</em> /console. </strong>This connects to session 0 on the box and allows me to disconnect the session and leave it running overnight and not have my session time out and cause the job to fail. However recently I updated mstsc.exe on my machine to version 6.0 to resolve another problem I was having remoting to my <a class="zem_slink" title="Windows XP" rel="homepage" href="http://www.microsoft.com/windows/products/windowsxp/">XP</a> machine from my <a class="zem_slink" title="Windows Vista" rel="homepage" href="http://www.microsoft.com/windows/windows-vista/default.aspx">Vista</a> PC at home. However it appeared that the <strong>/console</strong> switch no longer worked. Also when the <strong>/?</strong> switch was used, it wasn&#8217;t even mentioned.<span id="more-352"></span></p>
<p><img class="alignleft size-full wp-image-353" title="questionswitch" src="http://www.thenetflow.com/wp-content/uploads/2009/06/questionswitch.jpg" alt="The Question Switch" width="454" height="445" /></p>
<p>This creates a problem in that I couldn&#8217;t connect to console sessions to complete long tasks. However, while looking at the above instructions I noticed the <strong>/admin</strong> switch. Did they just rename it? I tried it and excellently I was able to log on to a console session created with the old mstsc application using the <strong>/console</strong> switch. Brilliant news. So to connect to any console session on a win2003 box all I had to do was <strong>mstsc /v: <em>servername</em> /admin. </strong>I decided to follow it up however to see why the change was made and if indeed if any change was made. I came across the following article <a href="http://blog.shijaz.com/2008/01/no-more-mstscexe-console.html">http://blog.shijaz.com/2008/01/no-more-mstscexe-console.html</a> which explained the situation with the application and why the change was made. Also, this is going to come up even more with the increased uptake of <a class="zem_slink" title="Windows Server 2008" rel="wikipedia" href="http://en.wikipedia.org/wiki/Windows_Server_2008">windows server 2008</a>, as explained in the above article. It makes for an interesting read and explains Microsofts thinking about how console sessions will work in future (i.e. not at all <img src='http://www.thenetflow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ).</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/bccb4c1e-3ef0-4835-8a25-c51dba786830/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_e.png?x-id=bccb4c1e-3ef0-4835-8a25-c51dba786830" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.thenetflow.com/2009/console-switch-for-mstsc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

