Bookmark and Share

In this post:

 

Can I Submit Ideas for the 2010 Scripting Games?

Hey, Scripting Guy! Question

Hey, Scripting Guy! I saw on Twitter that you are actually beginning planning for next year’s Scripting Games. Is this true? Also, I have a couple of ideas that I think would make cool events. How can I suggest them to the appropriate people?

-- AA

 

Hey, Scripting Guy! AnswerHello AA,

It is true. We are in the planning stages for the 2010 Scripting Games. We welcome all suggestions, comments, and ideas for events. In fact, two of the events from the 2009 Summer Scripting Games came from faithful readers who suggested the ideas via scripter@microsoft.com.

 

How Can I Load the ISE on Windows Server 2008 R2?

Hey, Scripting Guy! Question

Hey, Scripting Guy! Okay, I am new to Windows PowerShell, but understand that version 2.0 is shipped with Windows Server 2008 R2 RTM. All I want is the ISE for Windows Server 2008 R2 and cannot find it anywhere. Where can I download just the ISE?

-- RB

 

Hey, Scripting Guy! AnswerHello RB,

In Windows Server 2008 R2, Windows PowerShell is installed by default. However, the integrated scripting environment (ISE) is optional and is installed as a feature. 

 

How Can I Prevent Pop-Up Windows When Running a VBScript Script?

Hey, Scripting Guy! Question

Hey, Scripting Guy! I know this may be a waste of your time, but the simple script that uses the command Wscript.Echo is not working for me. The code is shown here:

Wscript.Echo "My very first script."

I always get the dialog box when the script is run. Here are the steps that I follow:

·   In Notepad I type the command Wscript.Echo "My very first script."

·   I save the file as test.vbs.

·   The script works, but I get the dialog box here:

Image of dialog box shown when script is run

You said something about using CScript, but I do not understand. When you say "command window," do you mean a command prompt? Here is the command:

cscript test.vbs:

I'm sorry to be such a waste of your time but it annoys me that I can only get a pop-up box.

-- AJ

Hey, Scripting Guy! Answer

Hello AJ,

 To find the command prompt, you do this:

·   Click Start, and then click Run.

·   In the box that appears type cmd and press ENTER.

·   The Command Prompt window opens. At the command prompt, type cscript and the path to your script. This is seen here:

Image of typing at command prompt

When you double-click the script or run the script without placing the word cscript in front of it, you will get the pop-up window you are seeing.

 

How Can I Overwrite Existing Files When Using VBScript and the FileSystemObject?

Hey, Scripting Guy! Question

Hey, Scripting Guy!

Can you please shed some light on this for me, please!! I have this script and when I run it, it works, but I always get an error that says that the file already exists even though it doesn’t. I have no clue why. Can you please help me? I want to overwrite any existing files. Thanks so much!

HowCanIOverWriteExistingFiles.vbs

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objFSO = CreateObject("Scripting.FileSystemObject")
'Create a reference to a FileSystemObject, then call the CopyFile method

 

Set objFolder = objFSO.GetFolder("E:\Document_Locator_Repository\Requisitions")
Set colFiles = objFolder.Files
'Need to look at all the files in this folder, so we use the Files method to get a collection of all the files


For Each objFile in colFiles
    objFSO.CopyFile objFile.path, "E:\Document_Locator_Repository\Requisitions\Archive Logs\TempFolder_PM\", False
Next

-- EM

Hey, Scripting Guy! Answer

Hello EM,

 If you want to overwrite any existing files, you need to change this line to True as I have done here:

objFSO.CopyFile objFile.path, "E:\Document_Locator_Repository\Requisitions\Archive Logs\TempFolder_PM\", TRUE

In addition, in your script you can delete the code seen here, because you are not using it:

strComputer = "."

 

Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

 

 

How Can I Change the Local Administrator Password with a Script?

Hey, Scripting Guy! Question

When I use your code to change the local administrator password for an organizational unit (OU) in my domain as seen here, it works great.

ChangeLocalAdminPassword.vbs

Set objOU = GetObject("LDAP://OU=Finance, DC=fabrikam, DC=com")

objOU.Filter = Array("Computer")

 

For Each objItem in objOU

    strComputer = objItem.CN

    Set objUser = GetObject("WinNT://" & strComputer & "/Administrator")

    objUser.SetPassword("i5A2sj*!")

Next


However, I get a "General access denied” error. I use this script as a startup script in Group Policy.

-- IE

Hey, Scripting Guy! AnswerHello IE,

Your Group Policy account does not have rights to change the local administrator password because it is not a member of the local administrators group. Your Domain Admin account is a member of the local administrators group, and therefore has the rights required to change the local administrator password. 

 

How Can I Prompt the User for a Computer Name in a VBScript Script?  

Hey, Scripting Guy! Question

I was wondering if it is possible to configure a script that I create using Scriptomatic 2.0 to prompt for a text file to read computer names from every time, or simply enter a computer name? I work in an environment where the systems I manage constantly change, and the ability to update a text file rather than an entire script every time would be fabulous.

-- ID

Hey, Scripting Guy! AnswerHello ID,

The script in the Hey Scripting Guy! article, How Can I Repeatedly Prompt a User to Enter a File Name, illustrates using the InputBox to prompt for a user name. You could use the InputBox function to prompt for the text file. You would then need to use the FileSystemObject to read through your text file. The Read Arguments From a Text File script from the TechNet Script Center Gallery illustrates reading a text file and performing a WMI query. If you move the text file path up to a variable, and then use the InputBox to supply the path to the text file, you will have what you wish.

 


How Can I Simultaneously Delete Multiple Groups from the Same OU in Active Directory?  

Hey, Scripting Guy! Question

I am looking for a script that can delete multiple groups simultaneously in Active Directory from the same OU. I got this script from TechNet Script Center Site. But I need to modify it to delete more than one group:

Set objOU = GetObject("LDAP://ou=hr,dc=fabrikam,dc=com")

 

objOU.Delete "group", "cn=atl-users"

-- RJ

Hey, Scripting Guy! AnswerHello RJ,

The easiest way is to store the groups in an array and use For…Each…Next to walk through the array.


 

How Can I Use WMI in a Windows PowerShell Script?    

Hey, Scripting Guy! Question

We upgraded our entire back-end servers, and I am managing/administering using Vista 64-bit precisely. Do you have a version of Windows PowerShell that I can use to send remote commands on services, etc.? Secondly, I developed several .ps1 scripts and would like to know how to setup one to call the other script, like I did with the previous versions of DOS. Lastly, I would like to set up my environment in a way that when I reboot, the scripting environment is kept.

-- JR

Hey, Scripting Guy! AnswerHello JR,

There is the Release candidate of Windows PowerShell 2.0 for Windows Vista and Windows XP on Microsoft Connect.

But keep in mind that neither the community technology preview (CTP) nor the release candidate (RC) is supported on production machines. They are basically betas that are for you to preview. Here is a Hey, Scripting Guy article where I talk about this concept. 

As for doing stuff with services, you can use Windows PowerShell 1.0 and use WMI. I just wrote the Change Start Mode of a Service script and posted it to the TechNet Script Center Gallery to illustrate what I am talking about in more detail.

 

This brings us to the end of another Quick-Hits Friday. It is also the end of another week on the TechNet Script Center. Thank you for all of the questions sent to scripter@microsoft.com. Join us next week as we answer additional scripting questions. If you want to know exactly what we will be scripting next week, follow us on Twitter or Facebook. If you have any questions, send e-mail to us at scripter@microsoft.com or post your questions on the Official Scripting Guys Forum. See you on Monday. Peace! 

Ed Wilson and Craig Liebendorfer, Scripting Guys