Quick-Hits Friday: The Scripting Guys Respond to a Bunch of Questions (7/30/10)
In this post:
- How Can I Learn to Script?
- Troubleshooting a WMI Issue
- How Can I Get the Microsoft Script Debugger to Work?
- Choosing Between the 64-bit and x86 Versions of Windows PowerShell
How Can I Learn to Script? Hey, Scripting Guy! I am working as a desktop support technician in a private company. I would like to know about windows scripting. I looked at the Learn Scripting site on the Script Center, but I am still confused where to start.
In my office, I have to perform regular tasks such as backup, temporary file clean out, and other things. I am currently using batch files to do some of these things. I am very interested to move to the next level. How can I improve my scripting knowledge?
I am thinking that one day I might pursue one of the system administration certifications on Microsoft technology.
If you are just beginning to learn scripting, I would suggest you learn Windows PowerShell and not VBScript. This is because Windows PowerShell is a new language that is becoming the standard for command-line administration. VBScript is in maintenance mode and is no longer being developed or updated. The best place to begin is with the Getting Started articles. Also, pay attention to the Scripting Wife articles. Read them in order.
When you have a basic understanding, you should work through the 2010 Scripting Games events in the Beginner division. Note: the Scripting Wife has answers for each of these events. You should work on them before looking at the answer.
If you have questions as you are working, you can seek out assistance from the Official Scripting Guys Forum. We have some great moderators and others who hang out there and love to help people who are attempting to learn scripting. You should also read the Hey, Scripting Guy! Blog on a daily basis. We publish a new article on the blog 365 days each year. Reading through the blog is a great way to learn new techniques and to maintain interest in your learning progress.
In addition, you may wish to follow us on Twitter. Many people post questions and answers on Twitter. Search for the #PowerShell tag in your favorite Twitter application. Our Twitter name is ScriptingGuy. Troubleshooting a WMI Issue
Hey, Scripting Guy! I had sent you a message yesterday regarding using WMI and the objwbemLocator.ConnectServer method to then connect to a remote computer and change the description field of one of its local user accounts (although I actually need to be able to change the local user account’s password and in some cases disable some local accounts as well). Anyway, I have been going crazy with this all weekend and I am finally beginning to think that this just isn’t possible using this method. I am not sure why it would be with GetObject and then SetInfo, but not with objwbemLocator.ConnectServer, etc., and objItem.Put_.
Just for clarity, I am using an input text file of server names, local accounts, and passwords to authenticate with to each machine (some of the machines aren’t in any domain and there is no common account in their admin groups that I can leverage), and then I wish to connect to each machine with the required credentials before renaming the administrator account, changing the description, changing the password, and in some cases disabling other local accounts on that computer. I can change the account’s Name field because Win32_UserAccount does support a Rename method, but that’s it.
So can this be done at all using the objwbemLocator.ConnectServer method, or must I somehow think outside the box and try to come up with some strange workaround? In other words, am I just missing something here? In scanning the web, I see no such examples of anyone doing this. Every example I have ever seen always relies on GetObject (which obviously only utilizes one set of credentials), and where there are no issues changing an object’s properties and then using SetInfo to write to WMI. It seems that when using the objwbemLocator.ConnectServer method, I must always SELECT a class that has certain write limitations, if you know what I mean. Anyway, sorry to make this so long, but again, please let me know what I am missing here!
When you use the ConnectServer method from the SwbemLocator object it returns an SwbemServices object. This is the same object that is often created by using the VBScript GetObject method and implementing a WMI moniker. However, when in your moniker you connect to a specific instance of a WMI class, you are returning an SwbemObject and not a SwbemServices object. The ExecQuery method from the SwbemServices object always returns a SwbemObjectSet. To return an instance of a specific object, use the Get method and not ExecQuery. These objects are detailed on MSDN as well as in my Microsoft Press WMI book. The Win32_Useraccount class is described on MSDN.
The description property is inherited from Cim_ManagedSystemElement as shown in the property editor from WbemTest in the following image, and is therefore read-only. The password itself it not exposed.
There are a number of read/write properties that can be used such as disabled, fullname, lockout, passwordchangable, passwordexpires, and passwordrequired. As you indicated in your email message, there is also the rename method. This is about it as far as the Win32_UserAccount WMI class goes. The best interface to use to do account management is ADSI. It has higher performance and is much more complete in its capabilities. On a large network, the Win32_Useraccount WMI class generates a substantial amount of network traffic.
How Can I Get the Microsoft Script Debugger to Work?
Hey, Scripting Guy! I’m new to scripting and would hope to get and use the Microsoft script debugger. I tried using the debugger from the command prompt using wscript.echo //d, but I received an error message: Access Denied. I’m using Windows Vista and the WSH host. Thanks in advance
On Windows Vista you probably need to start the command prompt with elevated rights in order to obtain the necessary permissions to run the debugger. To do this, right-click the command prompt and choose Run as administrator.
Choosing Between the 64-Bit and x86 Versions of Windows PowerShell Hey, Scripting Guy! I have a Windows PowerShell script that calls a COM object that works on an x86 computer. I am targeting a remote computer that is x86, but I am attempting to run it from my 64-bit computer. I am getting an error that states that it cannot create the COM object. Am I stuck?
On a 64-bit version of Windows, you will have two Windows PowerShell shortcuts. One is 64-bit, and the other is designated as x86. Attempt to launch your script from the x86 version of Windows PowerShell and see what happens. The Windows PowerShell application folder from my computer is shown in the following image.
Well, this concludes another edition of Quick-Hits Friday. Join us tomorrow for the Weekend Scripter as we delve into the mysteries of determining if a text file is ASCII or Unicode.
We invite you to follow us on Twitter or Facebook. If you have any questions, send email to us at firstname.lastname@example.org, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson and Craig Liebendorfer, Scripting Guys