Life of a Geek Admin

The Daily adventures of a true geek administrator

Life of a Geek Admin - The Daily adventures of a true geek administrator

Microsoft Script Explorer for Windows PowerShell

While digging around on the Internet for some PowerShell code I came across a new tool from Microsoft called Microsoft Script Explorer for Windows PowerShell (pre-release).

Microsoft Script Explorer for Windows PowerShell (pre-release) helps scripters find Windows PowerShell scripts, snippets, modules, and how-to guidance in online repositories such as the TechNet Script Center Repository, PoshCode, local or network file systems and Bing Search Repository. It was released on 3/12/2012 and looks to be a pretty handy tool to add to your PowerShell arsenal!!

Creating Folder Shares with PowerShell

Here is a cool little function that you can use to create a share on a system. Save this function in a PowerShell module and load to your toolset.To run this cfunction you must have full administrator privileges, this function also sets the ErrorActionPreference to stop.

function New-Share {
param($Path, $Name)
try {
$ErrorActionPreference = 'Stop'
if ( (Test-Path $Path) -eq $false) {
$null = New-Item -Path $Path -ItemType Directory
}
net share $Name=$Path
}
catch {
Write-Warning "Create a new share: Failed, $_"
}
}

To use the new function open up a PowerShell command and type:

PS C:\> New-Share c:\temp TempShare

TempShare was shared successfully.

Now you should be able to see the new share you have created. You will want to go in and set access permissions to the new share you created.

Adding Additional Fonts to PowerShell and Command Console

Ever wanted to add a different font to PowerShell and command prompt, we’ll here is an easy way to add it with PowerShell.

Open a PowerShell with Administrator privileges and execute the following commands.

$key = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont'
Set-ItemProperty -Path $key -Name '000' -Value 'Courier New'

To select a font, right-click the icon in the console title bar and choose “Properties”, then click on the “Font” tab. Select the font and the size you want and click “Ok”.

If you want to add others just make sure you have the name ex: Calibri and just add another 0 (zero) to the -Name parameter.

Converting User Names to SIDs with Powershell

While doing some Active Directory work ran across a need to translate a user name to a SID (security identifier)  to help find traces of it in the registry. Here is an easy way to do this with PowerShell function.

function getSID($name, $domain=$env:userdomain) {
$objUser = New-Object System.Security.Principal.NTAccount($domain,$name)
$strSID =
$objUser.Translate([System.Security.Principal.SecurityIdentifier])
$strSID.Value
}

Try it with your login and see what you get.

PS:> getSID <yourid>

Converting Adobe Type 1 Fonts AFM for use on Windows 7

Recently ran into an interesting issue where a client had a purchased Adobe Type 1 font the had been using on their Mac OSX systems and need to use the font on their newer Windows systems. Being that the fonts were Adobe Type 1 fonts and only had the .AFM files this was an issue with using the font on a Windows system, so it had to be converted.

This was achieved by using Fondu and AfmToPfm. Fondu was run on the Mac and AfmToPfm on the Windows 7 system.

Download and install Fondu to your Mac, the download is a zipped pkg file and just needs to be extracted and installed. Once installed Fondu will be located in /usr/local/bin. Copy your AFM file to a folder or a folder of your choice. Open a terminal on your Mac, it can be found under Utilities folder in your applications on OSX 10.4 and 10.5, which is all I have at my disposal.

Navigate in terminal to the folder where the the afm file reside and type

ibook-g4$ /usr/local/bin/fondu -afm 

And Fondu is off to the races. It will extract what it can find in the files and create bdf, pfb and other afm files it finds. If Fondu asks to overwrite it is fine to allow it to do so. Once complete copy the files to your Windows system using a usb drive or other methods at your disposal.

Now install AfmToPfm to your Windows system and open the application. Click on the Add from folder button or Add Files button and navigate to your folder where the extracted files reside and add them. Click on Create PFM Files and like magic you now have PFM files that can be installed into Windows Fonts.

To install the fonts just right click on the PFM files and click install and they will be added to c:\windows\Fonts directory and available to your applications.

Extending PowerShell with modules

With Microsoft adding PowerShell to Windows it opened many different possibilities for the scripter’s and IT Administrators managing hundreds and thousands of servers with automation from their desks. One of the problems with running PowerShell from the desk is that you need modules so you can write such great scripts. In this post I will list a few of the great resources to find the modules and in future posts plan to show scripts based on some of the modules.

Installing the Remote Server Administration Tools (RSAT) feature on Windows 7

In order to install the Active Directory Module for Windows PowerShell you need to download the RSAT tools for Windows 7 here. Once this is installed you are still not finished, you need to enable the Active Directory module. Navigate to Control Panel > Programs and Features > Turn Windows Features On or Off and select Active Directory Module for Windows PowerShell that you want to install.

Once you have Active Directory web services running on at least one domain controller and the AD PowerShell module is installed, you are ready to run the AD PowerShell module. You can do this in one of two ways. First, you can access the “Active Directory Module for Windows PowerShell” shortcut in Administrative Tools as shown here:

Right click the shortcut and select “Run as administrator” in order to start PowerShell with elevated permissions.

You can also simply import the AD PowerShell module in your existing PowerShell session. Just use the Import-Module ActiveDirectory command:

Import-Module ActiveDirectory

PowerShellPack Modules
http://archive.msdn.microsoft.com/PowerShellPack

Windows PowerShell Pack contains 10 modules to help supercharge your Windows PowerShell scripting. The PowerShellPack lets you write user interfaces in PowerShell script, manage RSS feeds, schedule operating system tasks, and much more. Download and install PowerShell pack to get started.

Run Import-Module PowerShellPack from within PowerShell.

Module Description
WPK – Create rich user interfaces quick and easily from Windows PowerShell. Think HTA, but easy. Over 600 scripts to help you build quick user interfaces
TaskScheduler – List scheduled tasks, create or delete tasks
FileSystem  – Monitor files and folders, check for duplicate files, and check disk space
IsePack  – Supercharge your scripting in the Integrated Scripting Environment with over 35 shortcuts
DotNet  – Explore loaded types, find commands that can work with a type, and explore how you can use PowerShell, DotNet and COM together
PSImageTools  – Convert, rotate, scale, and crop images and get image metadata
PSRSS  – Harness the FeedStore from PowerShell
PSSystemTools  – Get Operating System or Hardware Information
PSUserTools  – Get the users on a system, check for elevation, and start-processaadministrator
PSCodeGen  – Generates PowerShell scripts, C# code, and P/Invoke

MSDN Powershell Projects

There are many PowerShell projects with any imaginable PowerShell modules for download. Just visit the site  at http://archive.msdn.microsoft.com/Project/ProjectDirectory.aspx?ProjectSearchText=Powershell and browse away.

VuePoint PDS-ST415-VP portable Scanner

Several months back I ran across a portable page hand scanner at local office store. With old computer books and genealogy I occasionally have a need to scan pages or photographs in places where a flatbed scanner or camera just won’t work.

Hand scanners have improved greatly over the years from the old hand scanners. So I took a chance on VuePoint PDS-ST415-VP scanner. Note: VuePoint has released a newer version PDS-ST415-VPS that has added 900 DPI scan resolutions.

Whats in the package:
VuePoint PDS-ST415-VP portable Scanner
Carry Case
USB Cable (not pictured)
2xAA Batteries
Installation CD (not pictured and not required to retrieve scans)

First Impressions: It is compact and nice looking.

Ease of Use: Very easy to use. Press the button to turn it on, select color or black and white and press scan to start and stop. Uploading easy, just plug in the usb and copy the files. Very easy.

Price: $99 at any office store

Cons: Have to get used to the scanning motion to get an even scan. This is not a killer as with practice makes perfect.

Overall: Wonderful addition to my tools, portable, easy to use and fills in where I need it. Add it in the laptop case and I am set to get a scan of whatever I may find.

Specifications:

Features   Portable Scanner for color images, documents, magazines
Color Options   Black
Sensor   Color Contact Image Sensor, High speed sensor
Resolution   Standard: 300 DPI (default) ; Medium: 600 DPI; High: 900 DPI
External Memory   Support microSD card up to 32GB (not included)
File Format   JPG/PDF
Approx. Scanning Length   300 DPI: 98” 600 DPI: 45”
Approx. Scanning Width   Approx. 8.27”
LCD   Scanning status display
Date and Time Setting   Yes
Auto Power Off   3 minutes
Approx. Scanning Speed   (A4 and Standard letter Size)*

  • Medium resolution (600 DPI) with color = 8 sec
  • Standard resolution (300DPI) with color = 3 sec

Approx. Minimum Capacity   High resolution: 110 scans; Medium resolution: 250 scans; Standard resolution: 850 scans
USB Port   USB 2.0 High Speed
Power Source   2xAA Alkaline Batteries
Battery Life   Approx. > 200 scans
Dimension(LxHxW)   Approx. 10.1” x 1” x 1.2”
Weight   6.9 oz. (with batteries); 5.3 oz. (without battery)
System Requirements   Windows® XP, Windows® Vista™, Windows® 7, Mac OS® 10.4 or above (direct plug-in, driver installation not required)
ABBYY® (OCR Software)   Optical Character Recognition (OCR) Software included converts and exports scanned files to computer for editing text. Compatible with Windows® XP, Windows® Vista™ and Windows® 7. (Not compatible with Mac OS)
Accessories   USB Cable, 2xAA Alkaline batteries, Pouch, Cleaning cloth, Calibration paper, User’s manual Software CD

 

 

Updating VMWare ESXi Hypervisor 5

Recently I built a VMWare ESXi Hypervisor 5 server for testing and learning purposes. As a good admin you must always patch and VMWare is no exception.

First download and install VMWare vCLI from http://www.vmware.com/support/developer/vcli/. You must have an account on VMWare to download the products, the account is free. I will be using vCLI installed on Windows 7 x64 Professional, so the path maybe different on your installation.

Now Download the latest patch from http://www.vmware.com/patchmgr/findPatch.portal. The current patch is ESXi500-201204001.zip. Once you have downloaded the latest patch copy it to a datastore on the ESXi 5 server or a place the server to patch has access to, for this post I am using /vmfs/volumes1/datastore2/updates. Download the zip file and do not extract it. Open vCLI session.

First we need to see if the server needs to be in Maintenance Mode for the patch, issue the following command:

esxcli --server=192.168.1.80 --username=root software sources vib get -d /vmfs/volumes/datastore2/updates/ESXi500-201204001.zip | grep "Maintenance Mode Required: True"

If grep returns a True then lets put it in maintenance mode, issue the following command:

"C:\Program Files (x86)\VMware\VMware vSphere CLI\Perl\bin\perl" vicfg-hostops.pl --server 192.168.1.80 --operation enter

Verify the host is in maintenance mode,issue the following command:

"C:\Program Files (x86)\VMware\VMware vSphere CLI\Perl\bin\perl" vicfg-hostops.pl --server=192.168.1.80 --operation info

Verify what vib’s are installed, issue the following command:

esxcli --server=192.168.1.80 --username=root software vib list | more

To find out which VIBs are available in the depot (the downloaded .zip file), issue the following command:

esxcli --server=192.168.1.80 --username=root software sources vib list --depot=/vmfs/volumes/datastore2/updates/ESXi500-201204001.zip | more

To update the ESXi 5 host with the VIBs included in the depot, issue the following command:

esxcli --server=192.168.1.80 --username=root software vib update --depot=/vmfs/volumes/datastore2/updates/ESXi500-201204001.zip

When the update is complete, verify the information presented. If prompted, reboot the ESXi 5 host by issuing the following command:

"C:\Program Files (x86)\VMware\VMware vSphere CLI\Perl\bin\perl" vicfg-hostops.pl --server 192.168.1.80 --operation reboot

Verify the patch bundle was installed, by issuing the following command:

esxcli --server=192.168.1.80 --username=root software vib list | more

If applicable, take the ESXi 5 host out of maintenance mode using the vSphere Client or with the following command:

"C:\Program Files (x86)\VMware\VMware vSphere CLI\Perl\bin\perl" vicfg-hostops.pl --server 192.168.1.80 --operation exit

If the operation  exit command fails just open vSphere client and remove the server from Maintenance mode and un-pause the vm’s on the server.

Note: All of this can be done from a Linux system as well. VMWare provides a Linux vCLI download as well. The difference in the commands is that the perl preface used for Windows can be omitted as well as the .pl on the end of the command.

Autologon with Windows

Although it is not best practice to have a server set to Autologin with an id after reboot, it is sometimes a needed option for certain applications.

Autologon enables you to easily configure Windows’ built-in Autologon mechanism. Instead of waiting for a user to enter their name and password, Windows uses the credentials you enter with Autologon, which are encrypted in the Registry, to log on the specified user automatically.

Autologon is available from Windows Sysinternal Tools. You can download it from here.

  • Autologon is easy enough to use. Just run autologon.exe, fill in the dialog, and hit Enable. To turn off Autologon, hit Disable. Also, if the shift key is held down before the system performs an Autologon, the Autologon will be disabled for that logon. You can also pass the username, domain and password as command-line arguments: Autologon user domain password.

Reboot the server and it should login as expected.

SQL Server Configuration Manager unable to connect error

While running SQL Server Configuration Manager on a Windows 2008 server I received an unable to connect error.  The issue was an WMI corruption  in the sqlmgmproviderxpsp2up.mof.

The issue was resolved by the following steps.

  1. In the start menu type “cmd (without quotes) and on the top search result, right click the program icon and choose Run as administrator
  2. Type “net stop winmgmt” (without quotes) and press Enter to make certain the WindowsManagementInstrumentation (WMI) service is not running. If it is restarting set it to disabled and stop the service.
  3. Open a Windows Explorer and locate the path to C:\ windows\system32\WBEM\ folder and rename the Repository folder to something else like RepositoryOLD (right click and choose ‘Rename Folder‘). Set the service back to automatic.
  4. Reboot and restart as normal.
  5. In the start menu type “cmd (without quotes) and on the top search result, right click the icon and choose Run as administrator
  6. Type “net stop winmgmt” (without quotes) and press enter to stop the WMI service. If it is restarting set it to manual and stop the service.
  7. Type “winmgmt /resetRepository” (without quotes) and restart the computer.

 

Right click on command prompt and select Run as Administrator and type mofcomp.exe “C:\Program Files (x86)\Microsoft SQL Server\100\Shared\sqlmgmproviderxpsp2up.mof”

Switch to our mobile site