Learn about Windows PowerShell
How Can I Return File Names of Files Created in Less Than an Hour from the Current Time?
Hey, Scripting Guy! I am attempting to write a script that looks at the creation dates of all files in a certain directory. If the files were created less than an hour from the current time, the script will return those file names. The script will be a recurring script running every hour. I read the script article concerning the datediff function; however, I am not sure how to compare the objFile.CreationDate (string) and now(). Can you please help?
I used to hate working with dates in VBScript. Here is a collection of scripts that work with files and folders from the Script Center Script Repository. These two articles talk about using the datediff function: the first one is a Sesame Script article from the Library and the second is a Scripting Guy blog article. Working with dates is easier when you use Windows PowerShell and I have a series of Hey Scripting Guy blogs that talk abouit ths.
Hey, Scripting Guy! I´m trying to get the actual connection speed of my Network-Connection, and I'm going mad. It seems that WMI has such a parameter, but the value is always empty. I can see Connection Speed in the Status of the Network-Card, but how can I access that information with a script?
According to the WMI SDK, the speed property has not been implemented on any version of Microsoft Windows before Windows Vista and therefore always returns null. On Windows Vista, it will return the actual connection speed. That is why you are having a problem with your script. Here is a script that will work for you on Windows XP.
strComputer = "."
wmiNS = "\root\WMI"
wmiQuery = "Select * from MSNdis_LinkSpeed"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)
Set colItems = objWMIService.ExecQuery(wmiQuery)
For Each objItem in colItems
wscript.echo "Active: " & objItem.Active
wscript.echo "InstanceName: " & objItem.InstanceName
wscript.echo "NdisLinkSpeed: " & objItem.NdisLinkSpeed
wscript.echo " "
Top of page
Hey, Scripting Guy! We are trying to hide the Internet Explorer address bar, but after searching around and wasting nearly an hour, we gave up. Can you help us, old master of scripting minutiae?
I am not sure I like being called an old master of scripting minutiae, but I will take it as a compliment, which is I am sure the sprit in which it was offered. There is actually a "Hey, Scripting Guy!" article that was written several years ago that talks about this very thing. Here is a script I wrote that does a similar thing:
Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.AddressBar = 0
objExplorer.Visible = 1
Hey, Scripting Guy! I have a good knowledge of Group Policy but I am unsure how to work with it through script. Could you please send me some resources related to scripting and Group Policy.
I am not entirely certain from your e-mail message exactly what you are trying to do with scripting and Group Policy. If you would like to actually create Group Policy objects via scripting, you are pretty much out of luck unless you purchase a third-party product. We do have an API that is available through the Group Policy Management Console, which will allow you to manage Group Policy objects via scripting. You could also be talking about using WMI filters with Group Policy. So I am going to send you some links related to both topics. This article talks about using WMI filters in Group Policy. This article talks about scripting WMI-related tasks and contains a number of good ideas. Here is a link to the Group Policy scripting hub, which has links to articles and the Script Repository.
Hey, Scripting Guy! I'm trying to compile a VBScript that will go out to a predefined server list, do a WMI call for local disk drives, and then output that to an Office Excel cell. My problem is that I am overwriting my disk data in the Office Excel cell while I'm in my for...next loop. The data I want to collect is the name, description, size, and free space of every local fixed disk in that server and output that to a single Office Excel cell. How can I append all the disk data into that single cell within Office Excel?
All you need to do is to append to your variable inside the for...each…next loop. This is seen :
a = Array("a","b","c")
For each i In a
b = b + i
Hey, Scripting Guy! I am new to scripting. I need a script that will monitor a text log file for new entries (or lines), that contain the word “Global” or “Remote”. That line needs to be put in an e-mail message and sent to a distribution list. Also, each day a new text log file is created by the application. So, the script needs to account for that. Example :
Wed Nov 12 17:54:44 EST 2008, Global, userid, Unknown, User Logged In
Wed Oct 29 11:48:06 EST 2008, HWDevice, userid, 11111111,
Device HKxxxxxx successfully processed Action: Remote Application: Remote Application Name=MyRemote
I am not entirely certain I understand exactly what you are asking. When you mention monitoring, that makes me think of looking at something on a rather continuous basis. This kind of scripting is rather difficult and is actually not best done for long periods of time using a script. We can monitor a file for changes using the type of technique that is described in this "Hey, Scripting Guy!" article.
When the file is changed, we could open the file and look for the word "Global" or "Remote". To do this, you need to use regular expressions, which is another rather advanced kind of scripting. In fact, regular expressions become their own language and are areas in which people specialize. This "Hey, Scripting Guy!" article talks about searching a text file for a particular word.
If this is something that must run continuously, what you really need to do is write a service to do this. If you insist on doing this via script, the second best thing to do would be to create a permanent event consumer via WMI. This can be done by scripting, but is very difficult to do as well. This article talks about the process involved in performing this.
Because you are new to scripting, let me point you to some resources that may be of interest to you. This is the VBScript Getting Started Guide. It has a number of good links to help you get started. You may also wish to consider learning Windows PowerShell. In fact, Windows PowerShell is the future of Microsoft scripting. If I were just starting out, I think I would focus on learning Windows PowerShell and be ahead of the game, rather than learning VBScript, which is currently in maintenance mode at Microsoft. This means there is no new development work being done to it other than a few bug fixes from time to time. In fact, VBScript has not changed since the release of Windows XP. Here is the Windows PowerShell hub. If you decide to learn Windows PowerShell, download and install version 1.0, which is the current, released product.
Hey, Scripting Guy! If I use the script below, I can enter all the SAMACCOUNT names in the array to filter just those user objects in Active Directory Directory Services? Is there a limitation to how long the array can be?
Set colItems = GetObject _
("LDAP://ou=Servers, dc=fabrikam, dc=com")
colItems.Filter = Array(“User”, "Computer")
For Each objItem in colItems
An array is, I believe, pretty much limited by the amount of memory you have in your computer. Play with this script to demonstrate:
StartTime = Timer
For i = 0 To 1000000
ReDim Preserve a(i)
a(i) = i
endTime = Timer
WScript.Echo "It took: " & FormatNumber(endtime - startTime) & " seconds"
You will also notice this takes a significant amount of time as the size of the array approaches more than a million items. On my computer the above script took 45 seconds and used a maximum of 35 MB of RAM.
Hey, Scripting Guy! I downloaded the WindowsPowerShellV2_CTP3_SDK.chm, but when I open it on my Windows Vista computer, all I get is "Navigation to Web Page was cancelled." Is this file corrupt or what?
You have to right-click the .chm file and unblock it in Windows Vista.
Hey, Scripting Guy! Is there a way to detect or enumerate disabled network adapters? I’ve disabled my Local Area Connection and checked it via WMI’s Win32_NetworkAdapter. I get NetConnectionStatus of ‘0’ (Disconnected). I would like to see the same behavior the Network Connections Control Panel applet provides.
Unfortunately, WMI does not report this information. However, DevCon will probably work for you.
Hey, Scripting Guy! How can I find out who is using a file on the network, such as an Office Excel file that a user has had open for a long time and has forgotten to close). Thank you very much in advance for your assistance in this matter.
Strange thing: I have been asked this question twice today! And I don’t have a better answer for you than I did for the other guy. I don’t think it can be done. You may want to check The Official Scripting Guys Forum! and see what they say.
Have a safe weekend, and we will see you back on Monday. Until then, peace.
Ed Wilson and Craig Liebendorfer, Scripting Guys
Thank you admin, good article
I have files on CD in subfolders firstname_surname e.g. E:\Mel_VB\ or E:\John_Smith\. I want to copy all .jpg files to my C:\ not including subfolders and rename them to include the firstletter of firstname and secondname (subfolder name). e.g. E:\Mel_VB\001.jpg to C:\Pics\MV001.jpg AND E:\John_Smith\002.jpg to C:\Pic\JS002.jpg
I'm able to copy the files without the subfolders but don't know how to go about the renaming:
for /d %%a in (*.*) do xcopy /y "\%%a\*.jpg" "C:\Pics\"
Thanking you in advance,
Question, How can I setup powershell power management settings which will allow me to shutdown as well as power up a device or devices at a certain time?
I need to write a script that prompts the user to select 1 of 4 options in a dialog box. For example. Once the user logs in a window needs to pop up.
The user is asked, "Please choose the desk you are logging into."
The options would be a dropdown list showing "desk 1, desk 2, desk 3, desk 4"
Once the user has chosen their selection there will be a value corresponding to that selection such as 346, 367, 325, 356, My script will then need to proceed and as follows if
346, write value in the file C:\Folder\cptermw.ini , section; TTY configuration, Value; TTYREAL =
This will set our Virtual Machine's software TTY to the correct terminal number for our software to print to the proper printer.
Any help would be appreciation