Hey, Scripting Guy! Can You Translate This VBScript to Windows PowerShell?

ScriptingGuy1

 

Hey, Scripting Guy! Question

Hey Scripting Guy! I am wondering about something. I was looking on the Script Center Script Gallery, and I came across a pretty cool script that lists items that are in the user’s profile. It is in VBScript. Can you translate it to Windows PowerShell for me?

— AW

Hey, Scripting Guy! Answer

Hello AW,

Microsoft Scripting Guy Ed Wilson here. It is early morning. I am listing to Luciano Pavarotti on my Zune as he sings Lunge da Lei from Verdi’s La Traviata, and I’m sipping a cup of English Breakfast tea from my little blue tea pot the Scripting Wife bought me. The tea has a stick of real cinnamon in it, and I am munching on a freshly baked peach scone (peaches are in season in Charlotte, North Carolina, in the United States). Needless to say, I am in a good mood. Life is good. And I bought a new Microsoft keyboard the other day at the company store in Charlotte, so I am all set to answer your question.

I love our new Script Gallery—the search feature is cool, and the ability to filter scripts based upon the categories and scripting languages is sweet. The fact that you can directly upload scripts and not have to e-mail scripts to us and then wait for us to get around to publishing them is obviously another huge benefit. The rating, ranking, and discussion will turn out to be a big bonus as well. In short, as we used to say in Southern California, it rocks dude!

AW, you found the List Items in the User Profile Folder, which is seen here.

ListItemsInTheUserProfileFolder.vbs

Const USER_PROFILE = &H28&

Set objShell = CreateObject(“Shell.Application”)
Set objFolder = objShell.NameSpace(USER_PROFILE)
Set objFolderItem = objFolder.Self
Wscript.Echo objFolderItem.Path

Set colItems = objFolder.Items
For Each objItem in colItems
    Wscript.Echo objItem.Name
Next

The ListItemsInTheUserProfileFolder.vbs script begins by creating a constant, USER_PROFILE, and assigning hexadecimal 28 to it. A listing of shell folder constants is seen in Table 1; they are also documented on MSDN.

Table 1 Shell special folder values

Special Folder name

Hexadecimal value

ALTSTARTUP

0x1d

APPDATA

0x1a

BITBUCKET

0xa

COMMONALTSTARTUP

0x1e

COMMONAPPDATA

0x23

COMMONDESKTOPDIR

0x19

COMMONFAVORITES

0x1f

COMMONPROGRAMS

0x17

COMMONSTARTMENU

0x16

COMMONSTARTUP

0x18

CONTROLS

0x3

COOKIES

0x21

DESKTOP

0x0

DESKTOPDIRECTORY

0x10

DRIVES

0x11

FAVORITES

0x6

FONTS

0x14

HISTORY

0x22

INTERNETCACHE

0x20

LOCALAPPDATA

0x1c

MYPICTURES

0x27

NETHOOD

0x13

NETWORK

0x12

PERSONAL

0x5

PRINTERS

0x4

PRINTHOOD

0x1b

0 comments

Discussion is closed.

Feedback usabilla icon