<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>PFE Ireland : Scripting</title><link>http://blogs.technet.com/pfe-ireland/archive/tags/Scripting/default.aspx</link><description>Tags: Scripting</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>PowerShell – Read an XML configuration file</title><link>http://blogs.technet.com/pfe-ireland/archive/2009/10/27/powershell-read-an-xml-configuration-file.aspx</link><pubDate>Tue, 27 Oct 2009 11:44:46 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3289459</guid><dc:creator>gmcshera</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/pfe-ireland/comments/3289459.aspx</comments><wfw:commentRss>http://blogs.technet.com/pfe-ireland/commentrss.aspx?PostID=3289459</wfw:commentRss><description>I was recently asked a question about PowerShells ability to read in an XML configuration file at a Virtual Academy I ran last week. One of the strengths of PowerShell is its ability to perform lots of time saving tasks … one of which is reading in an...(&lt;a href="http://blogs.technet.com/pfe-ireland/archive/2009/10/27/powershell-read-an-xml-configuration-file.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3289459" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Events/default.aspx">Events</category><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>Scripting: Hyper-V - Mount VHDs by right clicking</title><link>http://blogs.technet.com/pfe-ireland/archive/2008/07/25/scripting-hyper-v-mount-vhds-by-right-clicking.aspx</link><pubDate>Fri, 25 Jul 2008 18:20:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3093718</guid><dc:creator>gmcshera</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.technet.com/pfe-ireland/comments/3093718.aspx</comments><wfw:commentRss>http://blogs.technet.com/pfe-ireland/commentrss.aspx?PostID=3093718</wfw:commentRss><description>&lt;P&gt;There are plenty of posts on the interweb&amp;nbsp;that show you how to mount and unmount vhds via powershell.&amp;nbsp; I downloaded the Hyper-V PowerShell management library from CodePlex.com &lt;A title="PowerShell mgt library" target=_blank href="http://www.codeplex.com/PSHyperv" mce_href="http://www.codeplex.com/PSHyperv"&gt;here&lt;/A&gt;&amp;nbsp;as created by&amp;nbsp;&lt;A title="James O'Neils blog" target=_blank href="http://blogs.technet.com/jamesone/" mce_href="http://blogs.technet.com/jamesone/"&gt;James O'Neil&lt;/A&gt;.&amp;nbsp; In it he kindly provides two scripts (mount-VHD.ps1 and Unmount-VHD.ps1) along with a REG file.&amp;nbsp; Assuming you have PowerShell 1.0 installed (available feature in Windows Server 2008) these scripts and registry settings work fine.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I ran into problems once I downloaded and installed the &lt;A title="PowerShell 2.0 CTP" target=_blank href="http://www.microsoft.com/downloadS/details.aspx?familyid=60DEAC2B-975B-41E6-9FA0-C2FD6AA6BC89&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloadS/details.aspx?familyid=60DEAC2B-975B-41E6-9FA0-C2FD6AA6BC89&amp;amp;displaylang=en"&gt;Windows PowerShell 2.0 Community Technology Preview (CTP)&lt;/A&gt;.&amp;nbsp; Powershells execution policy wouldnt&amp;nbsp;let&amp;nbsp;the scripts run anymore.&lt;/P&gt;
&lt;P&gt;You can change the executionPolicy a number of ways:&lt;/P&gt;
&lt;P&gt;Registry:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Change the key: &lt;EM&gt;REG_SZ ExecutionPolicy &lt;/EM&gt;to&lt;EM&gt; Unrestricted&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PowerShell:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;set-executionpolicy unrestricted&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note: By changing the execution policy you are technically opening your system up to remote execution of PowerShell scripts from unsigned/untrusted sources.&amp;nbsp; I want to be able to mount vhds easily coz Im a lazy kinda guy.&amp;nbsp;&amp;nbsp; Im running Hyper-V on my laptop so Im not too concerned about security in this instance.&amp;nbsp; You should think carefully about making this change in a production environment.&lt;/P&gt;
&lt;P&gt;The second thing I noticed was that the registry settings provided by James no longer worked.&amp;nbsp; So I came up with a slight modification as follows:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;Windows Registry Editor Version 5.00&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[HKEY_CLASSES_ROOT\Virtual.Machine.HD]&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[HKEY_CLASSES_ROOT\Virtual.Machine.HD\DefaultIcon]&lt;BR&gt;@="%SystemRoot%\\system32\\imageres.dll,26"&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[HKEY_CLASSES_ROOT\Virtual.Machine.HD\shell]&lt;BR&gt;@="Mount"&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[HKEY_CLASSES_ROOT\Virtual.Machine.HD\shell\Mount]&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[HKEY_CLASSES_ROOT\Virtual.Machine.HD\shell\Mount\command]&lt;BR&gt;@="cmd /k \"powershell -NoProfile -Command \"&amp;amp; 'c:\\Program Files\\Hyper-V\\Mount-VHD.ps1' '%1'\"\""&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[HKEY_CLASSES_ROOT\Virtual.Machine.HD\shell\Unmount]&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[HKEY_CLASSES_ROOT\Virtual.Machine.HD\shell\Unmount\command]&lt;BR&gt;@="cmd /k \"powershell -NoProfile -Command \"&amp;amp; 'c:\\Program Files\\Hyper-V\\Unmount-VHD.ps1' '%1'\"\""&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[HKEY_CLASSES_ROOT\.vhd]&lt;BR&gt;@="Virtual.Machine.HD"&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I've used cmd/k instead of cmd/c so I can see what the PowerShell script reports when its finished along with a couple of changes to get PowerShell to accept the string after the -Command.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://null/technet/scriptcenter/hubs/msh.mspx"&gt;&lt;/A&gt;&lt;A id=ctl00_ctl00_WideContent_ProjectTitleControl1_ProjectTitleLink class=NoUnderline href="http://www.codeplex.com/PsObject"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Now all is great in the land of Hyper-V on my laptop.&lt;/P&gt;
&lt;P&gt;&lt;A id=ctl00_ctl00_WideContent_ProjectTitleControl1_ProjectTitleLink class=NoUnderline href="http://www.codeplex.com/PsObject"&gt;&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3093718" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Windows+Server+2008/default.aspx">Windows Server 2008</category><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Hyper-V/default.aspx">Hyper-V</category></item><item><title>Scripting: Check if a W2K3 box is running Terminal Server in Application Mode</title><link>http://blogs.technet.com/pfe-ireland/archive/2008/06/06/scripting-check-if-a-w2k3-box-is-running-terminal-server-in-application-mode.aspx</link><pubDate>Fri, 06 Jun 2008 16:48:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3067032</guid><dc:creator>gmcshera</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/pfe-ireland/comments/3067032.aspx</comments><wfw:commentRss>http://blogs.technet.com/pfe-ireland/commentrss.aspx?PostID=3067032</wfw:commentRss><description>&lt;P&gt;I was recently asked (two hours ago) how to tell if a server was running Terminal Services in Application Mode.&amp;nbsp; The customer wanted to run a different script if users were logged into a Terminal Server.&lt;/P&gt;
&lt;P&gt;They had looked through the registry and came across the &lt;STRONG&gt;TSEnabled&lt;/STRONG&gt; value in :&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;HKLM\Software\System\CurrentControlSet\Control\Terminal Server&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;While this key does indicate whether or not TS is enabled, it does not tell you if the server is in Application Mode.&amp;nbsp; To compound the issue this key is also set to 1 by default on Windows XP.&amp;nbsp; So, surely there was a more appropriate way to check?&amp;nbsp; Indeed there is … the Win32_TerminalServiceSetting WMI class will allow you to check.&amp;nbsp; See the code below:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;Dim strComputer, objWMIService, colClass, objClass, strTSMode&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;strComputer = "."&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Set objWMIService = GetObject("winmgmts:\\" &amp;amp; strComputer &amp;amp; "\root\cimv2")&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Set colClass = objWMIService.ExecQuery("Select * from Win32_TerminalServiceSetting")&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;For Each objClass in colClass&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; strTSMode = objClass.TerminalServerMode&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If strTSMode = 1 Then&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Wscript.Echo "Terminal Server is in Application Server mode."&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Wscript.Echo "Terminal Server is in Remote Administration mode."&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Next&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note: This will &lt;U&gt;not&lt;/U&gt; work under Windows 2000 as the WMI class does not exist.&amp;nbsp; I have not checked it in Windows 2008.&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3067032" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Windows+Server+2003/default.aspx">Windows Server 2003</category><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Terminal+Server/default.aspx">Terminal Server</category></item><item><title>Scripting: How to edit an INI file from a script</title><link>http://blogs.technet.com/pfe-ireland/archive/2008/05/08/scripting-how-to-edit-an-ini-file-from-a-script.aspx</link><pubDate>Thu, 08 May 2008 19:37:20 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3052490</guid><dc:creator>gmcshera</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/pfe-ireland/comments/3052490.aspx</comments><wfw:commentRss>http://blogs.technet.com/pfe-ireland/commentrss.aspx?PostID=3052490</wfw:commentRss><description>&lt;p&gt;I was asked how to modify an INI from a script.&amp;#160; Its quite straight forward.&amp;#160; Firstly have a read of the Scripting Guy article &lt;a href="http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1130.mspx"&gt;here&lt;/a&gt;.&amp;#160; It explains the process quite well actually.&amp;#160; However, I wanted to go a step further and setup arguments to make the script re-useable.&amp;#160; So here is the modified script:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;'Usage: modini.vbs &amp;lt;full path to ini&amp;gt;, Parameter to change, New Value        &lt;br /&gt;'Example: modini.vbs c:\folder\my.ini, Script, change&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;Const ForReading = 1        &lt;br /&gt;Const ForWriting = 2&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;strINIFile = WScript.Arguments.Item(0)        &lt;br /&gt;strParam = WScript.Arguments.Item(1)         &lt;br /&gt;strValue = WScript.Arguments.Item(2)&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;If WScript.Arguments.Count &amp;lt;&amp;gt; 3 Then WScript.Quit &lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;Set objFSO = CreateObject(&amp;quot;Scripting.FileSystemObject&amp;quot;)        &lt;br /&gt;Set objTextFile = objFSO.OpenTextFile(strINIFile, ForReading)&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;Do Until objTextFile.AtEndOfStream        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; strNextLine = objTextFile.Readline&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;&amp;#160;&amp;#160;&amp;#160; intLineFinder = InStr(strNextLine, strParam)        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; If intLineFinder &amp;lt;&amp;gt; 0 Then         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; strNextLine = strParam &amp;amp; &amp;quot;=&amp;quot; &amp;amp; strValue         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End If&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;&amp;#160;&amp;#160;&amp;#160; strNewFile = strNewFile &amp;amp; strNextLine &amp;amp; vbCrLf        &lt;br /&gt;Loop&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;objTextFile.Close&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;Set objTextFile = objFSO.OpenTextFile(strINIFile, ForWriting)&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;objTextFile.WriteLine strNewFile        &lt;br /&gt;objTextFile.Close&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here is a sample batch file calling the VBS script:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;cscript //nologo modini.vbs &amp;quot;c:\my.ini&amp;quot; &amp;quot;Blog&amp;quot; &amp;quot;sometimes&amp;quot;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;And thats it!&amp;#160; Short and sweet.&lt;/p&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3052490" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>Batch Files : Date Stamp in a filename</title><link>http://blogs.technet.com/pfe-ireland/archive/2008/05/08/batch-files-date-stamp-in-a-filename.aspx</link><pubDate>Thu, 08 May 2008 19:35:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3052489</guid><dc:creator>gmcshera</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/pfe-ireland/comments/3052489.aspx</comments><wfw:commentRss>http://blogs.technet.com/pfe-ireland/commentrss.aspx?PostID=3052489</wfw:commentRss><description>&lt;P&gt;Ive been asked this a number of times this past month....&amp;nbsp; How do I get the date into a filename in a batch file?&lt;/P&gt;
&lt;P&gt;Most people try using the %date% variable.&amp;nbsp; Which will not work as you cannot have /'s in the filename.&lt;/P&gt;
&lt;P&gt;So, try this:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;for /f "tokens=1-4 delims=/ " %%i in ("%date%") do set datestring=%%i%%j%%k&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can now use %datestring%.txt as the filename&lt;/P&gt;
&lt;P&gt;Note: The delim character changes depending on your locale.&amp;nbsp; Eg. deliims=. for Germany.&amp;nbsp; You may want to change the filename to %%k%%j%%i to get multiple logs sorted in order within Windows Explorer sorted by YearMonthDate&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3052489" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Scripting/default.aspx">Scripting</category></item><item><title>Windows 2000 Terminal Server : Modify RDP-tcp permissions via script</title><link>http://blogs.technet.com/pfe-ireland/archive/2008/05/08/windows-2000-terminal-server-modify-rdp-tcp-permissions-via-script.aspx</link><pubDate>Thu, 08 May 2008 19:30:36 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3052484</guid><dc:creator>gmcshera</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/pfe-ireland/comments/3052484.aspx</comments><wfw:commentRss>http://blogs.technet.com/pfe-ireland/commentrss.aspx?PostID=3052484</wfw:commentRss><description>&lt;p&gt;I was recently asked how to modify the rdp permissions on a large number of Windows 2000 SP4 servers running in Remote Admin mode.&amp;#160; Well, normally Id make use of WMI and make the changes using Win32_TSPermissionsSetting class.&amp;#160; Unfortunatly this class is not available in Windows 2000. &lt;/p&gt;  &lt;p&gt;To get around this issue in Windows 2000 try the following:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Create a domain group and manually assign the permissions to the RDP-Tcp connection on a single server &lt;/li&gt;    &lt;li&gt;Export the following reg key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\Security (REG_BINARY) &lt;/li&gt;    &lt;li&gt;You can now import this reg key on any number of servers across your enterprise.&amp;#160; Since the change was not made using the API you may have to reboot the server &lt;/li&gt; &lt;/ol&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3052484" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Scripting/default.aspx">Scripting</category><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Terminal+Server/default.aspx">Terminal Server</category><category domain="http://blogs.technet.com/pfe-ireland/archive/tags/Windows+Server+2000/default.aspx">Windows Server 2000</category></item></channel></rss>