Hey, Scripting Guy! Quick-Hits Friday: The Scripting Guys Respond to a Bunch of Questions (02/13/09)

ScriptingGuy1

How Do I Troubleshoot Some Scripts Not Executing on Certain Computers?

 

Hey, Scripting Guy! Question

Hey, Scripting Guy! I have VBScripts executed using GPOs per organizational unit. For some reason, the scripts are not executed on certain computers. Sometimes, clicking Repair on Local Area Network connection and logging off does the trick. Any ideas why this is happening?

– JO

SpacerHey, Scripting Guy! Answer

Hi JO,

When a local area network connection is repaired, several things happen. The DHCP address is released and renewed, the DNS cache is flushed, and a name release is sent and reregistered. If this fixes your problem, it tells me that you have networking connectivity issues. This can be manifested in several ways which I am sure you know how to troubleshoot:

•

Wiring problems

•

Network adapters that are allowed to go to sleep and do not really wake up properly

•

Sleep/hibernation issues of the computer itself

 

How Can I Change the User Name on All Domain Computers?

 

Hey, Scripting Guy! Question

Hey, Scripting Guy! In reference to this article, when I use Windows Explorer to connect to a remote computer, I can see a description of that computer in the Details pane. How can I change the description for a computer on all domain computers to the user name, (%username%)?

– RH

SpacerHey, Scripting Guy! Answer

Hi RH,

I do not believe you can use a system variable for that value, but if your users use the same computer all the time, you can use the example in this article to obtain the user name.

Store the user name in a variable, instead of using wscript.echo to print it out to the screen. You can then use the variable in the code you referred to earlier.

 

Can I Have an E-Mail Message Sent to Me When a Computer Backup Is Complete?

 

Hey, Scripting Guy! Question

Hey, Scripting Guy! Can you please give me a script that will send e-mail to me when the backup of the computer is completed?

– KN

SpacerHey, Scripting Guy! Answer

Hi KN,

Here are some scripts that send e-mail: the Script Center Script Repository and the Community-Submitted Scripts Center. You may want to look at them and see what looks good to you.

Here is an excellent article that reviews this process. You will need to figure out how your particular backup program finishes and how to detect that to send your e-mail. By the way, most backup programs already have an e-mail feature built into them; you may want to investigate one of those programs before doing all the work to cobble together a script.

 

How Do I Change Group Types in Preparation for an Exchange 2007 Rollout?

 

Hey, Scripting Guy! Question

Hey, Scripting Guy! I am trying to run the ChangeGroup-ERROR-DontWork.vbs script to change global groups to security groups in readiness for an Exchange 2007 rollout. I ideally need to change all mail-enabled security groups and distribution groups to universal. But I get an error that says the operation did not satisfy one or more of the constraints associated with the object. Now, clearly, I want my objects to be completely satisfied with my script. I can’t imagine having groups that were not satisfied. Please look at my script and help!

Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &H8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &H80000000
Set objGroup = GetObject _
    ("LDAP://ou=test,dc=researchnow,dc=com")
objGroup.Put "groupType", ADS_GROUP_TYPE_UNIVERSAL_GROUP OR ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.SetInfo

– PL

SpacerHey, Scripting Guy! Answer

Hi PL,

An unhappy group is an uncooperative group, and I appreciate your attitude toward all this. In this case, however, we do not need to administer an MMPI to your server. In your script, you are connecting to an organizational unit, not to a group. Here is an article that illustrates how to change the group type. You will need to change your code to something like this.

Set objGroup = GetObject("LDAP://cn=group,ou=test,dc=researchnow,dc=com")

 

How Can I Rename All Personal Folder Shares Hosted on a File Server?

 

Hey, Scripting Guy! Question

Hey, Scripting Guys! (I assume you’re not all alone there.) We’re in the process of consolidating many AD domains into one, which means that we’ll have to standardize a lot to maintain manageability of the objects in the new domain. One of the parts that is being standardized are the user names. We have a solution for the migration of all users, the renaming of the objects, and the security setting (NTFS, etc.) changes, but we’ve come to a problem that we’re hoping you’ll be able to help solve with a script. Because all user names will be changed, we will also need to rename all the personal folder shares that are hosted on a file server.

•

Each folder will need to be renamed (this will remove the share if I’m not wrong).

•

Each share name will need to be renamed/readded (%USERNAME%$).

Both these changes will need to be made at the same time that the users are actually migrated, so we will need to do this change in the same speed. For each group/batch of users that is migrated, we have a comma-delimited file that can be used to find the old and new user names.

I hope you can help us!

– MS

SpacerHey, Scripting Guy! Answer

Hi MS,

We are not alone—or are we? I know such a script can be written. I am trying to decide how hard it might be. There are a few areas that concern me:

•

Maintaining share permissions: This one is the biggie!

•

Maintaining the NTFS permissions

•

I am not certain of the effect of renaming the share or renaming the folder. I recall seeing events in the event log to the effect of the missing folder for the share. These were lanmanserver warnings. The registry continues to keep share information. I think you will need to:

•

Delete the share.

•

Rename the folder.

•

Recreate the share.

You can use the following WMI classes to assist in this part of the problem:

•

WIN32_share to create and to delete shares

•

WIN32_Directory to rename the folders

And here are some resources that might help:

•

Files and Folders Archive

•

How Can I Share a Folder on a Remote Computer?

•

Deleting Shared Folders

•

Creating Shared Folders

•

How Can I Rename a Folder?

You can also post questions to the Scripting Guys Forum. Some really smart people hang out there, all of whom are working IT pros. One or more of them may have already done some of this work for you, or they may even have other ideas about how to accomplish this migration. As much as I hate to say it, writing a script is not always the correct answer to a particularly complex problem. As for scripting, here is a that will give you a good over view of the scripting process.

 

How Can I Change Registry Values and Security Permissions?

 

Hey, Scripting Guy! Question

Hey, Scripting Guy! I need to make a logon script to change some registry keys’ DWRD value and change some security permissions on some folders. Could you help me?

– WA

SpacerHey, Scripting Guy! Answer

Hi WA,

Here are some previous Script Center articles that talk about working with the registry:

•

Registry Overview

•

Sesame Script: Working with the Registry

•

Reading Entry Values and Types

•

Managing the Registry

In addition, you might benefit from looking at some additional examples. Here is a collection of registry scripts from the Script Center Script Repository. The basic process of working with the registry is covered in this online resource. The easiest way to set permissions on the registry is probably to use SubInACL. You can download it from this location.

 

How Can I Change the User Name on All Domain Computers?

 

Hey, Scripting Guy! Question

Hey, Scripting Guy! Can you perform the functional equivalent of a -contains or -notcontains on a multidimensional or jagged array inside Windows PowerShell without a custom function?

– CC

SpacerHey, Scripting Guy! Answer

Hi CC,

Basically, no. James, a test engineer on the Windows PowerShell team, wrote this example for you to illustrate how to get -contains type of capability from a jagged array. Thanks James!

function Test-MultiDimensionalArrayContains($items, $array) {
    foreach ($arr in $array) {
        foreach ($nestedArr in $array) {
            foreach ($i in $items) {
                if ($nestedArr -eq $i) {
                    return $true
                }
            }
        }
    }
    return $false
}
$jaggedArray = @(
    @(1..5),
    @(6..10),
    @(11..15)
)
Test-MultiDimensionalArrayContains 1 $jaggedArray
Test-MultiDimensionalArrayContains 17,16 $jaggedArray

Hope this helps. Phew! This concludes another Quick-Hits Friday and another scripting week. We hope you have a great weekend, and we look forward to seeing you again on Monday.

 

Ed Wilson and Craig Liebendorfer, Scripting Guys