{"id":54043,"date":"2009-04-04T00:38:00","date_gmt":"2009-04-04T00:38:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/04\/04\/hey-scripting-guy-quick-hits-friday-the-scripting-guys-respond-to-a-bunch-of-questions-040309\/"},"modified":"2009-04-04T00:38:00","modified_gmt":"2009-04-04T00:38:00","slug":"hey-scripting-guy-quick-hits-friday-the-scripting-guys-respond-to-a-bunch-of-questions-040309","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-quick-hits-friday-the-scripting-guys-respond-to-a-bunch-of-questions-040309\/","title":{"rendered":"Hey, Scripting Guy! Quick-Hits Friday: The Scripting Guys Respond to a Bunch of Questions (04\/03\/09)"},"content":{"rendered":"<p><H2>Troubleshooting the Application of Two WMI Classes<\/H2>\n<P>&nbsp;<\/P><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! The examples produced from the &#8220;Scriptomatic Version 2.0 by The Microsoft Scripting Guys&#8221; for the entries <B>Win32_ServiceSpecification<\/B> and <B>Win32_ServiceControl<\/B> both return error 0x80041002 under Windows Server 2003. I can&#8217;t find another WMI class that exposes the recovery options for services, which is something I need to be able to scrape off 100+ servers for auditing. Is that WMI class missing or broken possibly? I can run WMI scripts using just about any other WMI class except those two. What\u2019s up?<\/P>\n<P>&#8211; MP<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hi MP,<\/P>\n<P>Both of the <B>Win32_ServiceSpecification<\/B> and <B>Win32_ServiceControl<\/B> WMI classes are supplied by the MSI provider. We just tested it on our Windows XP computer, and they work fine. There is nothing magic about Scriptomatic. If the class does not work via a script generated by Scriptomatic, you probably have a problem with WMI on your computer. You will find <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/wmi.mspx\" target=\"_blank\">some resources<\/A> on the Script Center to assist you in troubleshooting this issue. <\/P>\n<P>Because you are talking about Windows Server 2003, you need to realize that the MSI provider is not installed by default. To install the MSI provider on your Windows Server 2003 machine, you go into <B>Add or Remove Programs<\/B>, and click <B>Add\/Remove Windows Components<\/B>. The Windows Components Wizard appears. Scroll down the list of components until you see <B>Management and Monitoring Tools<\/B>, and then click <B>Details<\/B>. In the Management and Monitoring Tools dialog box, choose <B>WMI Windows Installer Provider<\/B>. It is a very small installation. Because you say you have over 100 servers, you can use sysocmgr and script the installation. <A href=\"http:\/\/support.microsoft.com\/kb\/222444\" target=\"_blank\">This KB article<\/A> talks about using sysocmgr to install optional components. If you follow the article, you will need to know the component to add. This line of code placed in your file will do the trick:<\/P><PRE class=\"codeSample\">WbemMSI = On<\/PRE>\n<P>This script will tell you if the MSI provider is installed:<\/P>\n<P><B>FindMSIProvider.vbs<\/B><\/P>\n<DIV><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;\nwmiNS = &#8220;\\root\\cimv2&#8221;\nstrProv = &#8220;MSI&#8221;\nSet objWMIService = _\n    GetObject (&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; wmiNS) Set colItems = \nobjWMIService.InstancesOf(&#8220;__Win32Provider&#8221;)<\/p>\n<p>For Each objItem In colItems\nWith objItem\nIf InStr(1,.name, strProv,1) then\n    WScript.echo .Name, .clsid _\n    &amp; vbcrlf &amp; &#8220;hostingModel: &#8221; &amp; .hostingModel<\/p>\n<p>End If\nEnd with\nNext\n<\/PRE><\/DIV>\n<DIV>&nbsp;<\/DIV>\n<DIV><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/library\/gallery\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\">Top of page<\/A><\/DIV><A class=\"\" title=\"EQD\" name=\"EQD\"><\/A>\n<H2>How Can I Create and Assign a New IP Address and Subnet Mask to Statically Configure the IP Settings for the Local Area Network?<\/H2>\n<P>&nbsp;<\/P><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! I am try to create a script that will ask for a new IP address and Subnet mask, and then assign those values to statically configure the IP settings for the Local Area Network. I have looked at <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/mar06\/hey0329.mspx\" target=\"_blank\">this article<\/A> for changing the IP address and subnet mask. But this script attempts to change all network adapters. Any ideas?<\/P>\n<P>&#8211; DD<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hi DD,<\/P>\n<P>We have lots of ideas about this. You first need to identify which network adapter you wish to change. The problem is that a &#8220;normal&#8221; computer can have as many as a dozen network adapters\u2014a pptp adapter, a ppoe adapter, a connection manager adapter, a Bluetooth adapter\u2014as well as the standard ethernet card and wireless network adapter. The problem comes into play when attempting to find the real network card. As seen in the following image, there are multiple network adapters:<\/P><IMG height=\"499\" alt=\"Image of multiple network adapters\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/april\/hey0403\/hsg-04-03-09-01.jpg\" width=\"606\" border=\"0\"> \n<P>&nbsp;<\/P>\n<P>In the <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/mar06\/hey0329.mspx\" target=\"_blank\">script you mentioned<\/A>, it uses <B>Where IPEnabled=True<\/B> to attempt to limit the network cards that are only enabled with an IP address. On many computers this approach will work. In fact, this works on my laptop as seen here (using Windows&nbsp;):<\/P><PRE class=\"codeSample\">PS C:\\&gt; Get-WmiObject win32_networkadapterconfiguration -filter &#8220;ipenabled = $true&#8221;<\/p>\n<p>DHCPEnabled      : True\nIPAddress        : {192.168.1.97, fe80::e9db:821c:506c:7e24}\nDefaultIPGateway : {192.168.1.254}\nDNSDomain        : nwtraders.com\nServiceName      : e1express\nDescription      : Intel(R) 82566MM Gigabit Network Connection\nIndex            : 4\n<\/PRE>\n<P>Why, you may ask, does this query work? Well it is because I disable all network adapters I am not using for security reasons. I had a scary experience a long time ago in an airplane when I was working and suddenly an icon popped up that said, &#8220;Now connected to Dave\u2019s laptop.&#8221; I opened the connection, and sure enough I could browse Dave\u2019s laptop. At that point in life, I started disabling all network adapters I was not using. Plus it simplifies things like we are trying to do today!<\/P>\n<P>All we really need to do is to find some property that will allow us to differentiate one specific network adapter from all the other possible network adapters. To do this, let\u2019s take a look at the properties of the <B>WIN32_NetworkAdapterConfiguration<\/B> WMI class. They are seen here:<\/P><PRE class=\"codeSample\">ArpAlwaysSourceRoute\nArpUseEtherSNAP\nCaption\nDatabasePath\nDeadGWDetectEnabled\nDefaultIPGateway\nDefaultTOS\nDefaultTTL\nDescription\nDHCPEnabled\nDHCPLeaseExpires\nDHCPLeaseObtained\nDHCPServer\nDNSDomain\nDNSDomainSuffixSearchOrder\nDNSEnabledForWINSResolution\nDNSHostName\nDNSServerSearchOrder\nDomainDNSRegistrationEnabled\nForwardBufferMemory\nFullDNSRegistrationEnabled\nGatewayCostMetric\nIGMPLevel\nIndex\nInterfaceIndex\nIPAddress\nIPConnectionMetric\nIPEnabled\nIPFilterSecurityEnabled\nIPPortSecurityEnabled\nIPSecPermitIPProtocols\nIPSecPermitTCPPorts\nIPSecPermitUDPPorts\nIPSubnet\nIPUseZeroBroadcast\nIPXAddress\nIPXEnabled\nIPXFrameType\nIPXMediaType\nIPXNetworkNumber\nIPXVirtualNetNumber\nKeepAliveInterval\nKeepAliveTime\nMACAddress\nMTU\nNumForwardPackets\nPMTUBHDetectEnabled\nPMTUDiscoveryEnabled\nServiceName\nSettingID\nTcpipNetbiosOptions\nTcpMaxConnectRetransmissions\nTcpMaxDataRetransmissions\nTcpNumConnections\nTcpUseRFC1122UrgentPointer\nTcpWindowSize\nWINSEnableLMHostsLookup\nWINSHostLookupFile\nWINSPrimaryServer\nWINSScopeID\nWINSSecondaryServer\n<\/PRE>\n<P>As you can see, there is a lot to choose from. Obviously, the <B>MACAddress<\/B> property would not be good to use, unless you had a listing of all the MACaddresses on your network. The <B>DHCPServer<\/B> property would be an interesting property to use if for instance you were getting ready to decommission a particular server. I have used the <B>index<\/B> property and the <B>caption<\/B> property for this purpose as well. For instance, if all your computers have the same kind of network card, the use of the <B>caption<\/B> property makes sense because you can filter on the <B>maker\u2019s<\/B> name. <\/P>\n<P>The <B>WIN32_NetworkAdapter<\/B> class has a <B>netConnectionID<\/B> property. This property is the same as the <B>name<\/B> property that displays &#8220;Local Area Connection.&#8221; You can use the <B>netConnectionID<\/B> property to find the index or the <B>DeviceID<\/B> property of your network adapter. You can then use this to allow you to connect back to your specific network adapter. You can do this via two separate WMI queries, or you can use the association class: <B>WIN32_NetworkAdapterSetting<\/B>. This WMI class relates the <B>WIN32_NetworkAdapter<\/B> class with the <B>WIN32_NetworkAdapterConfiguration<\/B> class. The <B>GetLocalAreaConnectionIP.ps1<\/B> script illustrates this technique. <\/P>\n<DIV>\n<P><B>GetLocalAreaConnectionIP.ps1<\/B><\/P><PRE class=\"codeSample\">Get-WmiObject -Class win32_NetworkAdapterSetting | \nForeach-object {\n  If( ([wmi]$_.element).netConnectionID -eq &#8220;local area connection&#8221;)\n    {\n     &#8220;Adapter: $($_.setting)&#8221;\n     [wmi]$_.setting\n     [wmi]$_.element\n    } #end if\n } #end foreach\n<\/PRE>\n<P><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/networking\/02_atnc_basic.mspx\" target=\"_blank\">This article<\/A> is part of a nine-part series about the above concepts, using VBScript in the examples.<\/P><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/library\/gallery\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\">Top of page<\/A><\/DIV><A class=\"\" title=\"EXG\" name=\"EXG\"><\/A>\n<H2>How Can I Tell Which Version of Microsoft Office Is on My Computer?<\/H2>\n<P>&nbsp;<\/P><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! Is it possible to write a script that will show the version of Office on my computer?<\/P>\n<P>&#8211; LM<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hi LM,<\/P>\n<P>Of course. We can use the <B>WIN32_Product<\/B> WMI class, which is provided by the MSI provider. Using Windows PowerShell, your script might look something like this:<\/P>\n<P>GetOfficeVersion.ps1<\/P><PRE class=\"codeSample\">Get-WmiObject -class win32_product -filter &#8220;name like &#8216;%office%'&#8221;<\/PRE>\n<P>Using VBScript, the script would be a bit longer:<\/P>\n<P><B>GetOfficeVersion.vbs<\/B><\/P>\n<DIV><PRE class=\"codeSample\">wmiquery = &#8220;Select * from Win32_Product where name like &#8216;%office%'&#8221;\nSet objWmi = GetObject(&#8220;Winmgmts:&#8221;)\nSet colItems = objWmi.execquery(wmiQuery) \nFor Each item In colItems  \nWScript.Echo item.name \nNext\n<\/PRE><\/DIV>\n<DIV><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/library\/gallery\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\">Top of page<\/A><\/DIV><A class=\"\" title=\"EVH\" name=\"EVH\"><\/A>\n<H2>How Can I Read Text Files Via ADO?<\/H2>\n<P>&nbsp;<\/P><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! Sorry to bother you. I hope you can help me. I am following your instructions about reading text files via ADO. I am working in a tab-delimited file in Visual Basic 2008. I modified the text format in my registry to tab delimited. I also created a schema.ini file in the same folder of my txt files.The schema defines the datatype of each column, but one column that is supposed to be considered as text, the ADO column, is not importing the data. (When I check the column 3 value, there is nothing). This is the schema:<\/P><PRE class=\"codeSample\">[HCSR879C_092_20081103.txt]\nFormat=TabDelimited\nCol1 = ProgramName text\nCol2 = ProgramCode text\nCol3 = LocationCode text\nCol4 = SmstrHrsCrdt double\nCol5 = WrkFrcContEdu double\nCol6 = NonFundContEdu double\nCol7 = AdultLitcy double\nCol8 = UndupEnroll double\n<\/PRE>\n<P>Col3 is a mix. It can be numeric or text or alphanumeric. So in the schema its datatype is text, but it seems that ADO does not care. I am a little frustrated after an hour of trying different approaches. Any help will be really appreciated.<\/P>\n<P>&#8211; JM<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hi JM,<\/P>\n<P>The <A href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms974559.aspx\" target=\"_blank\">Much ADO About Text Files<\/A> article is something we still refer to on occasion. You should give it a read. You do not or should not need both a schema.ini and a registry entry. The article was written for VBScript and not for Visual Basic or Visual Basic .NET. However, I imagine it should work. If I were doing Visual Basic .NET, I think I would use ADO.NET instead of COM ADO because it is generally easier to use. I would think the problem is with your schema.ini file, but that\u2019s just a guess. Make sure the file is in the same folder as the one from where you are reading the CSV file. Here are some more Help articles. They should apply to both ADO.NET and COM ADO as well:<\/P>\n<TABLE class=\"\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">\n<TBODY>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><A href=\"http:\/\/support.microsoft.com\/kb\/149090\/en-us\" target=\"_blank\"><B>http:\/\/support.microsoft.com\/kb\/149090\/en-us<\/B><\/A><\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><A href=\"http:\/\/support.microsoft.com\/kb\/146224\/en-us\"><B>http:\/\/support.microsoft.com\/kb\/146224\/en-us<\/B><\/A><\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><A href=\"http:\/\/support.microsoft.com\/kb\/205439\/en-us\" target=\"_blank\"><B>http:\/\/support.microsoft.com\/kb\/205439\/en-us<\/B><\/A><\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<P>You may be able to find some inspiration in our <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/db.mspx\" target=\"_blank\">Databases Scripting Hub<\/A>. You may also want to ask a question at the <A href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\" target=\"_blank\">The Official Scripting Guys Forum<\/A>, there are a lot of very smart people who hang out over there. <\/P>\n<P>&nbsp;<\/P>\n<DIV><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/library\/gallery\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\">Top of page<\/A><\/DIV><A class=\"\" title=\"EQBAC\" name=\"EQBAC\"><\/A>\n<H2>How Can I Extract Information About Remote Users on My Citrix Server?<\/H2>\n<P>&nbsp;<\/P><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! I am still plugging away at my attempt to extract information regarding remote users on my Citrix servers. I am able to create a file from the output of the &#8220;QWINSTA.EXE&#8221; command. However, I cannot seem to copy that file to my own &#8220;C:\\temp\\&#8221; folder. The script below is what I am&nbsp;using:<\/P><PRE class=\"codeSample\">Const ForReading = 1\nConst ForWriting = 2<\/p>\n<p>Set oWshNet = CreateObject(&#8220;WScript.Network&#8221;)\nsComputerName = &#8220;myComputer&#8221;<\/p>\n<p>sUserName = GetUser(sComputerName)<\/p>\n<p>Function GetUser(sHost)\n    Set oShell = CreateObject(&#8220;Wscript.Shell&#8221;)\n    Set oFS = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)\n    Set fileName = oFS.CreateTextFile(&#8220;C:\\temp\\RemoteUsers.txt&#8221;)\n    sTmpFile = oFS.GetSpecialFolder(2).ShortPath &amp; &#8220;\\&#8221; &amp; &#8220;RemoteUsers.txt&#8221;<\/p>\n<p>&#8216;Run command and redirect stdout and stderr into temp file\n    oShell.Run &#8220;%ComSpec% \/c %SystemRoot%\\System32\\QWINSTA.EXE \/SERVER:&#8221; _\n &amp; sHost &amp; &#8221; &gt;&#8221; &amp; sTmpFile &amp; &#8221; 2&gt;&amp;1&#8243;, 0, True<\/p>\n<p>&#8216;Open the temp file\n    Set oTF = oFS.OpenTextFile(sTmpFile)\n    Set newFile = oFS.OpenTextFile(fileName, ForWriting)\n    oFS.CopyFile sTmpFile, fileName, True\nEnd Function\n<\/PRE>\n<P>The error that appears occurs in this line:<\/P><PRE class=\"codeSample\"> Set newFile =oFS.OpenTextFile(fileName, ForWriting)<\/PRE>\n<P>The error message indicates a &#8220;Type Mismatch&#8221;. I cannot see how this could be, since both files have been created as &#8220;Text&#8221; files.<\/P>\n<P>The &#8220;sTmpFile&#8221; path is to &#8220;Documents &amp; Settings\\ (my User ID)\\LocalSettings\\Temp&#8221;. Can you see anything that I may have missed, vis-a-vis the proper use of the File System Object? This should not be such a difficult process. However, I simply cannot see what is amiss.<\/P>\n<P>&#8211; FS<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hi FS,<\/P>\n<P>You are in fact getting a type mismatch error. You are creating a file object here:<\/P><PRE class=\"codeSample\">  Set fileName = oFS.CreateTextFile(&#8220;C:\\temp\\RemoteUsers.txt&#8221;)<\/PRE>\n<P>The <B>OpenTextFile<\/B> method takes a string and not a file object. Notice that you have a file object stored in the filename variable\u2014not a string!<\/P><PRE class=\"codeSample\">oFS.OpenTextFile(fileName, ForWriting)<\/PRE>\n<P>If you store your file name \/ path in a variable, you can then modify your codethusly:<\/P><PRE class=\"codeSample\">filePath = &#8220;C:\\temp\\RemoteUsers.txt&#8221;\nSet fileName = oFS.CreateTextFile(filePath)\noFS.OpenTextFile(filePath, ForWriting)\n<\/PRE>\n<P>Of course I would recommend renaming the filename variable to something else, such as <B>objFile<\/B>. You are right, it should not be this hard. This is why we invented Windows PowerShell.<\/P>\n<P>&nbsp;<\/P>\n<DIV><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/library\/gallery\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\">Top of page<\/A><\/DIV><A class=\"\" title=\"EWCAC\" name=\"EWCAC\"><\/A>\n<H2>How Can I Archive E-Mail on a Schedule Using Windows PowerShell?<\/H2>\n<P>&nbsp;<\/P><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! I have created a Windows PowerShell script that will go into specified mailboxes on Exchange Server and extract old e-mails out to an Outlook PST file. I have also created a Windows PowerShell script to be run from a command so that it can be called with a task scheduler.<\/P>\n<P>In the Windows PowerShell script, I have hard coded a date that is back 6 months, <B>-EndDate &#8220;09\/16\/08&#8221;<\/B>. What I would like to do is add a line to the script that automatically removes the last 6 months allowing me to put the .bat file into a scheduler and it would clean on its own.<\/P>\n<P>I am sure that I use the <B>Get-Date<\/B> cmdlet, but I am unsure of the syntax. Thanks guys, I would have never gotten this far had it not been for your articles.<\/P>\n<P>&#8211; TC<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hi TC,<\/P>\n<P>I am glad you find our articles helpful. You can do this:<\/P><PRE class=\"codeSample\">(get-date).adddays(-180)<\/PRE>\n<P>&nbsp;<\/P>\n<DIV><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/library\/gallery\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr09\/hey0403.mspx#top\">Top of page<\/A><\/DIV><A class=\"\" title=\"EUDAC\" name=\"EUDAC\"><\/A>\n<H2>How Can I Permit a Nonadministrator to Make Remote WMI Calls into a Remote PC?<\/H2>\n<P>&nbsp;<\/P><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! I need a script that changes the DCOM permission on a remote PC so that a non-administrator user can make remote WMI calls into the remote PC. I need this script so that I can carry out the task for 8000+ PCs.<\/P>\n<P>&#8211; VN<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hi VN,<\/P>\n<P><A href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa393266.aspx#setting_dcom_security_to_allow_a_user_to_access_a_computer_remotely\" target=\"_blank\">This article<\/A> talks about the remote WMI connection. Beginning with Windows Vista, you can use methods from this WMI class: <A href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394118(VS.85).aspx\" target=\"_blank\">win32_DcomApplicationSetting<\/A>. Prior to that, you are pretty much limited to hacking the registry. You may want to ping the <A href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\" target=\"_blank\">Official Scripting Guys Forum<\/A> to see if anyone has already written any scripts to do this. You may also be interested in the scripts found in the <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/csc\/default.mspx\" target=\"_blank\">Community-Submitted Scripts Center<\/A>. <\/P>\n<P>&nbsp;<\/P>\n<P>This concludes another Quick-Hits Friday. This also brings to a close another exciting week at the Script Center! Take care, and join us next week. <A href=\"http:\/\/en.wikipedia.org\/wiki\/TTFN\" target=\"_blank\">TTFN<\/A>.<\/P>\n<P>&nbsp;<\/P>\n<P><B>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/B><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Troubleshooting the Application of Two WMI Classes &nbsp; Hey, Scripting Guy! The examples produced from the &#8220;Scriptomatic Version 2.0 by The Microsoft Scripting Guys&#8221; for the entries Win32_ServiceSpecification and Win32_ServiceControl both return error 0x80041002 under Windows Server 2003. I can&#8217;t find another WMI class that exposes the recovery options for services, which is something I [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[19,727,45,6],"class_list":["post-54043","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-activex-data-objects-ado","tag-ado-net","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>Troubleshooting the Application of Two WMI Classes &nbsp; Hey, Scripting Guy! The examples produced from the &#8220;Scriptomatic Version 2.0 by The Microsoft Scripting Guys&#8221; for the entries Win32_ServiceSpecification and Win32_ServiceControl both return error 0x80041002 under Windows Server 2003. I can&#8217;t find another WMI class that exposes the recovery options for services, which is something I [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/54043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=54043"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/54043\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=54043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=54043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=54043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}