Author Archives: Alan

About Alan

Alan Renouf has a role of Automation Frameworks Product Manager at VMware responsible for providing the architects and operators of the cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter. Alan is a frequent blogger at http://blogs.vmware.com/vipowershell and has a personal blog at https://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

Change DNS and WINS on multiple servers

OK, so you have just rebuilt your DNS/WINS server and it has a new IP address, now you have to log into every server that you gave a static address to and update the DNS/WINS…or do you ?

Not anymore, thanks to FatBeard

The following powershell script will do it for you by using PowerShell, you only need PowerShell on the machine you are running it from, not the servers you are changing as this is done through WMI. Even reads the server name entries from a text file !

function Set-DNSWINS {
#Get NICS via WMI
$NICs = Get-WmiObject ‘
-Class Win32_NetworkAdapterConfiguration ‘
–ComputerName $_ ‘
-Filter “IPEnabled=TRUE”

foreach($NIC in $NICs) {
$DNSServers = “12.34.5.67”,”76.54.3.21″
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration(“TRUE”)
$NIC.SetWINSServer(“12.345.67.890”, “12.345.67.891”)
}
}

function Get-FileName {
$computer = Read-Host “Filename of computer names?”
return $computer
}

$f = Get-FileName
Get-Content $f foreach {Set-DNSWINS}

Powershell get-member fun

Ok, as a newbie to Powerhsell it still amazes me how clever it is, whilst i was writing my recent report script which takes the results of various commands and outputs them to a word document for a report I was stuck with the properties of one of the objects.

I had been trying to translate some of the documented vbscript’s from the msdn site and use the same features as there wasnt much documentation for doing this in powershell at the moment on the web, I really got stuck finding the properties so i experimeted with get-member, check this out…

$msWord = New-Object -Com Word.Application

Which creates a new word com object

$msword | get-member

Didnt expect this to do anything as how would powershell know the properties of a com object but wait, look what i recieved….

TypeName: System.__ComObject#{00020970-0000-0000-c000-000000000046}

Name MemberType Definition
—- ———- ———-
Activate Method void Activate ()
AddAddress Method void AddAddress (SAFEARRAY(st…
AutomaticChange Method void AutomaticChange ()
BuildKeyCode Method int BuildKeyCode (WdKey, Vari…
CentimetersToPoints Method float CentimetersToPoints (fl…
ChangeFileOpenDirectory Method void ChangeFileOpenDirectory …
CheckGrammar Method bool CheckGrammar (string)
CheckSpelling Method bool CheckSpelling (string, V…
CleanString Method string CleanString (string)
DDEExecute Method void DDEExecute (int, string)
DDEInitiate Method int DDEInitiate (string, string)
DDEPoke Method void DDEPoke (int, string, st…
DDERequest Method string DDERequest (int, string)
DDETerminate Method void DDETerminate (int)
DDETerminateAll Method void DDETerminateAll ()
DefaultWebOptions Method DefaultWebOptions DefaultWebO…
DiscussionSupport Method void DiscussionSupport (Varia…
GetAddress Method string GetAddress (Variant, V…
GetDefaultTheme Method string GetDefaultTheme (WdDoc…
GetSpellingSuggestions Method SpellingSuggestions GetSpelli…
GoBack Method void GoBack ()
GoForward Method void GoForward ()
Help Method void Help (Variant)
HelpTool Method void HelpTool ()
InchesToPoints Method float InchesToPoints (float)
Keyboard Method int Keyboard (int)
KeyboardBidi Method void KeyboardBidi ()
KeyboardLatin Method void KeyboardLatin ()
KeyString Method string KeyString (int, Variant)
LinesToPoints Method float LinesToPoints (float)
ListCommands Method void ListCommands (bool)
LookupNameProperties Method void LookupNameProperties (st…
MillimetersToPoints Method float MillimetersToPoints (fl…
MountVolume Method short MountVolume (string, st…
Move Method void Move (int, int)
NewWindow Method Window NewWindow ()
NextLetter Method void NextLetter ()
OnTime Method void OnTime (Variant, string,…
OrganizerCopy Method void OrganizerCopy (string, s…
OrganizerDelete Method void OrganizerDelete (string,…
OrganizerRename Method void OrganizerRename (string,…
PicasToPoints Method float PicasToPoints (float)
PixelsToPoints Method float PixelsToPoints (float, …
PointsToCentimeters Method float PointsToCentimeters (fl…
PointsToInches Method float PointsToInches (float)
PointsToLines Method float PointsToLines (float)
PointsToMillimeters Method float PointsToMillimeters (fl…
PointsToPicas Method float PointsToPicas (float)
PointsToPixels Method float PointsToPixels (float, …
PrintOut Method void PrintOut (Variant, Varia…
PrintOutOld Method void PrintOutOld (Variant, Va…
ProductCode Method string ProductCode ()
Quit Method void Quit (Variant, Variant, …
Repeat Method bool Repeat (Variant)
ResetIgnoreAll Method void ResetIgnoreAll ()
Resize Method void Resize (int, int)
Run Method Variant Run (string, Variant,…
RunOld Method void RunOld (string)
ScreenRefresh Method void ScreenRefresh ()
SendFax Method void SendFax ()
SetDefaultTheme Method void SetDefaultTheme (string,…
ShowClipboard Method void ShowClipboard ()
ShowMe Method void ShowMe ()
SubstituteFont Method void SubstituteFont (string, …
ToggleKeyboard Method void ToggleKeyboard ()
FindKey ParameterizedProperty KeyBinding FindKey (int, Vari…
International ParameterizedProperty Variant International (WdInte…
IsObjectValid ParameterizedProperty bool IsObjectValid (IDispatch…
KeysBoundTo ParameterizedProperty KeysBoundTo KeysBoundTo (WdKe…
SynonymInfo ParameterizedProperty SynonymInfo SynonymInfo (stri…
ActiveDocument Property Document ActiveDocument () {g…
ActivePrinter Property string ActivePrinter () {get}…
ActiveWindow Property Window ActiveWindow () {get}
AddIns Property AddIns AddIns () {get}
AnswerWizard Property AnswerWizard AnswerWizard () …
Application Property Application Application () {g…
Assistant Property Assistant Assistant () {get}
AutoCaptions Property AutoCaptions AutoCaptions () …
AutoCorrect Property AutoCorrect AutoCorrect () {g…
BackgroundPrintingStatus Property int BackgroundPrintingStatus …
BackgroundSavingStatus Property int BackgroundSavingStatus ()…
BrowseExtraFileTypes Property string BrowseExtraFileTypes (…
Browser Property Browser Browser () {get}
Build Property string Build () {get}
CapsLock Property bool CapsLock () {get}
Caption Property string Caption () {get} {set}
CaptionLabels Property CaptionLabels CaptionLabels (…
CheckLanguage Property bool CheckLanguage () {get} {…
COMAddIns Property COMAddIns COMAddIns () {get}
CommandBars Property CommandBars CommandBars () {g…
Creator Property int Creator () {get}
CustomDictionaries Property Dictionaries CustomDictionari…
CustomizationContext Property IDispatch CustomizationContex…
DefaultSaveFormat Property string DefaultSaveFormat () {…
DefaultTableSeparator Property string DefaultTableSeparator …
Dialogs Property Dialogs Dialogs () {get}
DisplayAlerts Property WdAlertLevel DisplayAlerts ()…
DisplayAutoCompleteTips Property bool DisplayAutoCompleteTips …
DisplayRecentFiles Property bool DisplayRecentFiles () {g…
DisplayScreenTips Property bool DisplayScreenTips () {ge…
DisplayScrollBars Property bool DisplayScrollBars () {ge…
DisplayStatusBar Property bool DisplayStatusBar () {get…
Documents Property Documents Documents () {get}
Dummy1 Property bool Dummy1 () {get}
EmailOptions Property EmailOptions EmailOptions () …
EnableCancelKey Property WdEnableCancelKey EnableCance…
FeatureInstall Property MsoFeatureInstall FeatureInst…
FileConverters Property FileConverters FileConverters…
FileSearch Property FileSearch FileSearch () {get}
FocusInMailHeader Property bool FocusInMailHeader () {get}
FontNames Property FontNames FontNames () {get}
HangulHanjaDictionaries Property HangulHanjaConversionDictiona…
Height Property int Height () {get} {set}
KeyBindings Property KeyBindings KeyBindings () {g…
LandscapeFontNames Property FontNames LandscapeFontNames …
Language Property MsoLanguageID Language () {get}
Languages Property Languages Languages () {get}
LanguageSettings Property LanguageSettings LanguageSett…
Left Property int Left () {get} {set}
ListGalleries Property ListGalleries ListGalleries (…
MacroContainer Property IDispatch MacroContainer () {…
MailingLabel Property MailingLabel MailingLabel () …
MailMessage Property MailMessage MailMessage () {g…
MailSystem Property WdMailSystem MailSystem () {g…
MAPIAvailable Property bool MAPIAvailable () {get}
MathCoprocessorAvailable Property bool MathCoprocessorAvailable…
MouseAvailable Property bool MouseAvailable () {get}
Name Property string Name () {get}
NormalTemplate Property Template NormalTemplate () {g…
NumLock Property bool NumLock () {get}
Options Property Options Options () {get}
Parent Property IDispatch Parent () {get}
Path Property string Path () {get}
PathSeparator Property string PathSeparator () {get}
PortraitFontNames Property FontNames PortraitFontNames (…
PrintPreview Property bool PrintPreview () {get} {s…
RecentFiles Property RecentFiles RecentFiles () {g…
ScreenUpdating Property bool ScreenUpdating () {get} …
Selection Property Selection Selection () {get}
ShowVisualBasicEditor Property bool ShowVisualBasicEditor ()…
SpecialMode Property bool SpecialMode () {get}
StartupPath Property string StartupPath () {get} {…
StatusBar Property {get} {set}
System Property System System () {get}
Tasks Property Tasks Tasks () {get}
Templates Property Templates Templates () {get}
Top Property int Top () {get} {set}
UsableHeight Property int UsableHeight () {get}
UsableWidth Property int UsableWidth () {get}
UserAddress Property string UserAddress () {get} {…
UserControl Property bool UserControl () {get}
UserInitials Property string UserInitials () {get} …
UserName Property string UserName () {get} {set}
VBE Property VBE VBE () {get}
Version Property string Version () {get}
Visible Property bool Visible () {get} {set}
Width Property int Width () {get} {set}
Windows Property Windows Windows () {get}
WindowState Property WdWindowState WindowState () …
WordBasic Property IDispatch WordBasic () {get}

AMAZING! I could then find the property I wanted and send it the syntax i needed, how cool !

> 1000 Visits

Last night my sometimes working hit counter said I had over 1000 hits, just wanted to say a big thank you to anyone that has bothered to read the ramblings of a lonely IT contractor and a bigger thanks to those of you who have come back again !

Rescan all hosts for new storage

More of a note for myself really but others may find this useful, to rescan all the hosts (rather than clicking Rescan in the GUI) you can run the following PowerShell command:

For a Specific Cluster:

get-cluster -name “MY CLUSTER” | get-vmhost | Get-VMHostStorage -RescanAllHBA

All Hosts in VC:

get-vmhost | Get-VMHostStorage -RescanAllHBA

VI Toolkit Webinar by Carter Shanklin

For those who haven’t had much exposure to the Powershell Toolkit and what it can do, there is a recording of a webinar presented by the Carter Shanklin at this link. It is pretty basic and intended for those with little or no exposure to the toolkit.

If you’ve ever wondered what it is or why you might want to use it (like disconnecting the CD from 45 or 50 VMs so you can VMotion them without having to deal with the right-click – pick-from-the-pop-up-menu process manually 45-50 times) then you might want to check this out.

More recorded webcasts are available on : http://www.vmware.com/a/webcasts/recorded/

Original Source and great site: here

Exporting Virtual Infrastructure Information to MS Word

The below is a script that will export various information into Microsoft Word using PowerShell and the VI Toolkit, this is completely risk free and does not alter anything, just feed it your VI server name and sit back, it can also be used as a scheduled task and even set to email you a word attachment.

It even throws in a few graphs and pie charts for good measure, almost all information can be sent to the functions for you to expand on the report easily.

Comments are welcome, the good the bad and the ugly !

Usage: report.ps1 YOURVISERVER

See below or download here:

Reporting Script