Advanced Windows PowerShell Scripting Video Training

Advanced Windows PowerShell Scripting Video Training
Advanced Windows PowerShell Scripting Video Training

Friday, July 31, 2009

How do I force DFS to replicate?

If you need your DFS to replicate now, type this command in:

Repadmin /replicate /force

This is helpful when you first start a DFS replication topology. Before files can be transferred, the replication topology must be replicate through normal AD replication. File transfers happen next. Execute this command to speed things up a bit.


Wednesday, July 29, 2009

Can you download the Powershell ISE for Vista or Win7?

Below is the link for the latest version of Powershell V2 as of the writing of this article. The ISE (Integrated Scripting Environment) is good tool for those who are scripting in Powershell. It offers 3 windows. One for the script you are writing, one for the output, and one for commands. It makes writing powershell scripts faster and easier.


Sunday, July 26, 2009

Enumerate the OS version and Service Pack

This VBScript utilizes WMI to discover the Service Pack and OS version. We utilized the Scriptomatic from the Microsoft Scripting Center( to discover the correct object properties to script for.
First we issue the command On Error Resume Next to tell the script to continue executing even if an error is detected.
We then tell the script which computer to script against. This is done by setting a variable strComputer to “.”. this tells the script to execute on the local computer. By replacing the period with the name or IP address of a different computer, the script will execute against that computer. This asums the you have local administrative rights on that computer.
Line 3 will connect to the client.
Line 4 will gather a collection or all objects in the Win32_OperatingSystem on the target computer.
He For..Next loop will return the service pack and OS version.

On Error Resume Next

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

For Each objItem in colItems

Wscript.Echo "ServicePackMajorVersion: " & _

Wscript.Echo "ServicePackMinorVersion: " & _

Wscript.Echo "Version: " & objItem.Version


Thursday, July 23, 2009

I Can’t get Hyper-V to Release the Mouse!

More than likely someone else changed the mouse release key on you. To check this:

• Open Hyper-V Manager
• In the Actions pane, click Hyper-V Settings.
• Click Mouse Release Key in the left hand column.
• Use the drop down box to set the release sequence that you want to use.

Remember that you can install integration services so you no longer need to capture and release the mouse.

Wednesday, July 22, 2009

Is VB Editor available on versions of MS Office other then 2007?

In class we looked at how to discover the objects and methods available to us in Office 2007. We were able to utilize the object browser to disover how to script IMAP information in outlook. The question came up is you can script to older versions of Office software? Yes you can. I tested on Word XP.

Tools --> Macros --> Visual Basic Editor

Monday, July 20, 2009

Can you create an OU while executing a Script from a regular machine?

Yes you can. The user who is logged in on the client must be a member of the Domain Administrators or Enterprise Administrators group. The code below was used.

Set objdomain = GetObject("LDAP://DC=fourthcoffee,dc=com")
Set objou = objDomain.Create("OrganizationalUnit", "ou=HR")

To get this code to work in your environment, change line 1 after the LDAP:// statement to reflect your domain.

Thursday, July 16, 2009

Can you prevent users from using EFS through group policy?

Yes you can. In the Default Domain Policy simply brose to this path: Computer Configuration\Windows Settings\Security Settings\Public Key Policies\Encrypting File System. Right click the Encrypting File System and select Properties. From here you can disable EFS for your users. Below is a more in-depth article.

Wednesday, July 15, 2009

When do you use ConnectObject in VBScript?

`The WScript.ConnectObject allows you to receive events from an application and have your script act on it. The following code came from DevGuru at

Set objWord = WScript.CreateObject("Word.Application")WScript.ConnectObject objWord, "objWord_"

objWord.visible = True
blnWordVisible = True

Do While blnWordVisible
WScript.Sleep 500

Sub objWord_Quit
blnWordVisible = False
WScript.Echo "You quit Word."
End Sub

Sub objWord_DocumentChange
WScript.Echo "You switched documents."
End Sub

You switched documents.
You switched documents.
You quit Word.

Monday, July 13, 2009

How do you rename a Server Core computer?

The command for this is:

Netdom renamecopmuter computername /newname:new_computername /userd:domain\username /passwordd:*


Thursday, July 9, 2009

Mouse Frustration in Hyper-V

Many are discovering that when viewing a VM in Hyper-V on your 2008 server, you have to click the screen to get the mouse to be “Captured”. Further frustration sets in when you have to use the mouse release key combination of Ctrl – Alt- left arrow key. The problem is with Integration Services. Even though all the boxes are checked in the VM Settings for Integration Services, you still need to install the CD in the Guest OS.

• To do this, log into your Guest OS.
• Execute the Mouse release (Ctrl – Alt- left arrow key).
• On the menu bar of the VM, Click Action  Insert Integration Services Setup Disk.
• Click on you VM and browse to the CD drive in the VM.
• Allow the Integration Services to install.
• You may need to reboot the guest OS.
• Problem solved!

Wednesday, July 8, 2009

Is there some type of “duel security” when you create an NTFS namespace?

This question came about because when we set of DFS replication, it asked for permissions to be set. These permissions are share permissions, not NTFS permission. By changing the permission (NTFS or Share) on the folders in the DFSROOT folder, you can change both the NTFS and the Share permission after the DFS share has been created.

Sunday, July 5, 2009

Is Macintosh NAP compliant?

That one caught me off guard. I never thought of anybody putting a mac in an NAP setup. Thanks to Dan from Network Services Group ( walking into our classroom at the right time. Dan happened to be at the same training site as I am this week. He recommended going to to download an NAP client for Macintosh. Sure enough, someone thought about putting a Mac in an NAP.

Thursday, July 2, 2009


Uptime allows you to quickly estimate the system uptime for your server. It is a stand alone application that was developed during the Windows NT days. Even though it is a bit dated, in these times of lean budgets you take every free tool you can get. It also is a command line application. In any case, it allows you to demonstrate your ability to meet Service Level Agreements or corporate uptime requirements.

Wednesday, July 1, 2009

Can I have a script know what folder it was executed from?

This is one that bugged me years ago when I first started scripting. The problem was portability. I was not able to easily move my scripts from one location to another without having to go in and change me code for any external files the script referenced.

I first started off using a constant in the declarations section of the script. This helped. I simply put the folder location the script was in and used that constant throughout the script. I still had to do manual work. Finally I got smart and asked Windows where the script was being executed from. Below is the code that I used.

Declaration section
Dim AppPath ' Will store the path that the script and text file are located in.

Script Main Logic

' Determin the file path
AppPath = fGetPath

Functions and Sub Procedures

Function fGetPath
' Returns the path that the script is run from.
Set oShell = CreateObject("WScript.Shell")
GetPath = oShell.CurrentDirectory & "\"
End Function ' GetPath

Using this code, your script will know where it is at and make it portable without having to worry about where the script is stored or executed from.