≡ Menu

I came across nice software (called Onyx) in VMware labs which has the ability to convert your UI operations into powershell code. You might wonder why this is useful. Let me explain. Sometimes we don’t know the parameter/method of a VMware specific powershell object responsible for a particular VM setting. For example, how to change the VM to use a manually assigned MAC address. We know how to do this via vSphere console but might not know until you do some google search. With Google search also it is not guaranteed that you will get correct results because someone had to figureout that in past and post it somewhere. If you want to do it yourself, then this tool is for you.

What it does is, it acts as proxy between your vSphere client and vCenter server and monitors the network communication. That means it can record all the changes you are making through UI and it can convert them into powershell code.

You don’t believe me? Check out this you tube video : http://www.youtube.com/watch?v=bANfdjuH4wk&feature=player_embedded

Download link: http://labs.vmware.com/flings/onyx

I found this tool really helpful.

{ 0 comments }

In this article I will show you how to change/reset HP ILO password from Operating System without going to HP ILO console.

Quite often it happens that we forget ILO passwords. It also happens that person who changed ILO password is not available and the password is not stored anywhere. This is a tough situation if you want to manage the server remotely via ILO. HP has developed a tool called “HP ONLINE Configuration (HPONCFG)” using which you can access all ILO settings.

There are two versions of this tool.

  1. Command line
  2. GUI

You can get both of them by downloading and installing HPONCFG from HP site (http://www.hp.com/support/ilo2 ) for the operating system where you want to change ILO settings.

Once downloaded, go to the installation directory(generally C:\Program Files\HP\hponcfg\)  and launch hponcfg_gui.exe to launch the utility. Make sure to do it as administrator; otherwise it won’t work. After launching, go to “Users” tab and you know what to do from there.

Apart from changing/resetting ILO passwords for users, you can also manage various other settings of ILO from this UI. You can change ILO IP address, change DHCP options, change ILO DNS servers, etc.

If you already know the password and looking for a way to change the password remotely via some automation, then refer my previous article (Change HP ILO User Password using Powershell).

Hope this helps and happy learning.

{ 0 comments }

It is simple. When you are at desktop screen, right click on the task bar, switch to navigation tab, and you will find the option (“Go to desktop instead of Start menu when I sign in”). Just check that box and click on OK.

It is very simple when you want to do it on a single computer. But how to deploy it to multiple workstations?. How to deploy it to all windows 8.1 computers in your office?

Any change in user environment is a change to file or registry. So, when you enable this option via task bar, the following registry value is set to ‘0’

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StartPage\OpenAtLogon

(Courtesy:  www.grouppolicy.biz)

So, being a system administrator, you have to decide what is the best way to deploy this setting to all users. You can use group policy preferences, scheduled tasks or any other custom mechanisms that you use in your organization. My preference is Group policy preferences as it is very easy to configure.

I don’t want to explain how to configure GPP as someone already did that. See http://www.grouppolicy.biz/2013/06/how-to-configure-a-boot-to-desktop-group-policy-for-windows-8-1/ for detailed instructions.

I also came across an article from same which is explaining how to enable “Boot to Desktop” on Windows 8 computers as well. Basically they are using SendKeys functionality in Windows Forms to trigger the desktop access from Start Menu. They are doing it through powershell script configured as a logon script for users. See http://www.grouppolicy.biz/2013/05/how-to-enable-boot-to-desktop-group-policy-for-windows-8/ details.

Hope this helps and happy learning.

{ 0 comments }

Troubleshooting: Who killed my process?

Who killed my process?

A tough question. It is very difficult to troubleshoot unexpected process terminations/exits. We don’t know what other process is causing my process to terminate. I am sure some of you have already faced this kind of problem. I came across a nice tool which can address this kind of situation.

Windows debugger(Windbg) has a utility called GFLAGS.EXE which can be used for monitoring a process exit. It has ability to tell us which process has terminated my process. It can monitor that and can give you a pop-up message when it happens. This simplifies the troubleshooting and helps catch the rogue process/application.

Apart from giving a System status message, it can write events to event log as well (check your application log). This also has facilities to dump process memory before exit.

Steps to enable process exit monitoring:

  • Run GFLAGS.EXE and select the Silent Process Exit tab.
  • Type the name of the process that is exiting unexpectedly.
  • Hit the TAB key on the keyboard to refresh the GUI.
  • Check the following boxes:
    • Enable Silent Exit Process Monitoring (This enables the feature and tracks silent process exits in the application event log. Event ID: 3001)
    • Enable Notification (This optionally creates a balloon popup with the same information in the event log.) 
    • Ignore Self Exits (This prevents superfluous logging when the application exits gracefully, such as when File / Exit is selected from a menu.)
  •  Click OK to save the change and exit the GFLAGS tool.

 NOTE: The changes will take effect immediately for any new processes launched after the change.  A reboot is NOT required.

I came across this nice tip in ASKPERF blog(http://blogs.technet.com/b/askperf/archive/2013/05/01/what-killed-my-process.aspx). Go through that for complete information.

 

{ 0 comments }

This is one of the good opportunities for Powershell learners. The Powershell inventor, Jeffrey Snover along with Jason Helmick is going to talk about Powershell v3 exclusively for IT administrators.

I hope you don’t want to miss this opportunity.

Course Outline

– Getting Started with PowerShell
– Don’t Fear the Shell
– The Help System & Getting Connected
– Extending the Shell
– Objects for the Admin
– The Pipeline: Deeper
– The Power in the Shell – Automation, Remoting, Scripting & Toolmaking

Link to Register for this event: http://www.microsoftvirtualacademy.com/liveevents/PowerShell-JumpStart?CR_CC=200211917

{ 0 comments }

In this post, I will show you how to disable the local area connections that are not in connected state in a Windows Server/Desktop. It is quite common scenario that our servers will have at least one or two Network adapters in disconnected state if don’t use all available network ports on the server. There is no harm in having them in such condition, but a few monitoring softwares like HP SMH treats this condition as error state. Moreover, it is not great to have disconnected network adapters on the server as this can lead to some sort of confusion when someone is debugging a problem on the server.

The following powershell code helps you to disable the network adapters that are in disconnected state on remote/local computers. The code uses a WMI class called Win32_NetworkAdapter which stores the details of each network connection in the windows server along with its status(connected/disconnected, etc). The status code 7 for a network adapter indicates that it is in “media disconnected state”.

CODE

function Disable-DisconnectedAdapter{            
[cmdletbinding()]            
param(            
[string[]]$ComputerName            
)            
foreach($Computer in $ComputerName) {            
Write-Host "Working on $Computer"            
if(Test-Connection -ComputerName $Computer -Count 1 -ErrorAction 0) {            
    try {            
        $nics = Get-WmiObject -Class Win32_NetWorkAdapter -ComputerName $Computer -ErrorAction Stop | ? { $_.NetConnectionStatus -eq 7 }            
    } catch {            
        Write-Error "Failed to Query WMI class for network adapters on $Computer"            
        Continue            
    }            

    foreach($nic in $nics) {            
        try {            
            $retval = $nic.disable()            
            if($retval.returnvalue -eq 0) {             
                "{0} network card disabled successfully" -f $nic.Name            
            } else {            
                "{0} network card disable failed" -f $nic.Name            
            }            
        } catch {            
            "Error occurred while disabling {0}" -f $nic.Name            
            continue            
        }            
    }            

} else {            
    Write-Verbose "$Computer is offline"            
}            

}            
}

Test this code before you try in production environment.

{ 0 comments }

System administrators depend a lot on WMI objects to query various information from local or remote computers. That means if any of the WMI query is taking long time or never ending, the automatons placed by System administrator may fail. I ran into same situation yesterday. Query against a WMI Class(given by third party application) is taking very long to execute and never ending. This is resulting in my scripts to halt at that computer for very long and not proceeding further. This is a big problem and I feel the automation should handle such cases as well. Otherwise you will be under impression that script is running fine(if you schedule it somewhere) but it is actually not. You will not realize this until someone reports a problem or you yourself identify the problem by manually running the script.

Well, what is the fix now? Can Get-WMIObject support a timeout parameter. No, I couldn’t find any such option. But the dotnet name space(System.Management)  has this facility. I wrote a wrapper function that works on top of Dotnet classes to query the WMI classes of remote computer. This function takes 4 parameters. (1) ComputerName (2) Class (3) NameSpace and (4)TimeOutInSeconds. These parameters are self descriptive so need to explain much.

CODE:

Function Get-WmiObjectCustom{            
[cmdletbinding()]            
param(            
 [string]$ComputerName = $env:ComputerName,            
 [string]$NameSpace = "root\cimv2",            
 [int]$TimeoutInseconds = 60,            
 [string]$Class            
)            

try {            
 $ConnectionOptions = new-object System.Management.ConnectionOptions            
 $EnumerationOptions = new-object System.Management.EnumerationOptions            
 $timeoutseconds = new-timespan -seconds $timeoutInSeconds            
 $EnumerationOptions.set_timeout($timeoutseconds)            
 $assembledpath = "\\{0}\{1}" -f $ComputerName, $NameSpace            
 $Scope = new-object System.Management.ManagementScope $assembledpath, $ConnectionOptions            
 $Scope.Connect()            
 $querystring = "SELECT * FROM {0}" -f $class            
 $query = new-object System.Management.ObjectQuery $querystring            
 $searcher = new-object System.Management.ManagementObjectSearcher            
 $searcher.set_options($EnumerationOptions)            
 $searcher.Query = $querystring            
 $searcher.Scope = $Scope            
 $result = $searcher.get()            
} catch {            
 Throw $_            
}            
return $result            
}

Usage:

Get-WMIObjectCustom -Class Win32_ComputerSystem -ComputerName PC1 -TimeoutInSeconds 20

I found this approach organically in MSDN blog and modified the code to make it as advanced function so that it can support error handling better. Also modified a few pieces of code to make it look better.

Happy learning

{ 8 comments }

I have seen many complaining that message recall is not working as expected in their environments. I too often receive queries related to it. Today one of my colleague asked me whether the message recall that she/he did will work for sure or not. My answer is “YES/NO/MAYBE”. Because I never seen it working in such a confidant and smooth manner. It surprised me every time. I wanted to do a deep dive into this topic from long time but never got a chance — but today I did. I searched a bit on internet and found a interesting link that answers most of the questions and clarifies how it works.

Though a few people described it as funny/fancy feature in all versions of exchange/outlook but never seemed worked as expected, I am still feeling that below scenarios are valid. At least in my case scenario#2 answered my question because no human mailbox will have auto-processing of meeting requests box enabled. This generally configured in conference room mailboxes/shared mailboxes.

But your case might be different, so go through these and let me know if you find this helpful. Happy learning.. 🙂

Source: http://office.microsoft.com/en-us/outlook-help/recall-or-replace-an-email-message-after-it-is-sent-HA010354931.aspx

Scenarios that affect recall success

The success or failure of a message recall depends on the recipients’ settings in Outlook. In the following table, five scenarios are presented:

  • Four scenarios that explain what happens when message recall is tried in various situations
  • One scenario that describes what happens when the recall of a message that was sent to a Microsoft Exchange public folder is tried
Action Result
You send a message to someone. You recall the original message and replace it with a new one.On the recipient’s computer, under Tracking, the Automatically process requests and responses to meeting requests and polls check box is selected. Note   To view this setting, click the File tab. Under Outlook, click Options, click Mail, and then scroll to the Tracking section. Both the original message and the recall message are received in the recipient’s Inbox.Assuming the original message has not been read, the original message is deleted and the recipient is informed that you, the sender, deleted the message from his or her mailbox. Note    If the original message is marked as read (viewing in the Reading Pane is not reading in this scenario) when the recall message is processed, the recipient is informed that you, the sender, want to delete the message. However, the message remains in the recipient’s Outlook folder.
You send a message to someone. You recall the original message and replace it with a new one.On the recipient’s computer, under Tracking, the Automatically process requests and responses to meeting requests and polls check box is not selected. Note   To view this setting, click the File tab. Under Outlook, click Options, click Mail, and then scroll to the Tracking section. Both the original message and the recall message are received in the recipient’s Inbox.On the recipient’s computer, one of the following results occurs:

  • If the recipient opens the recall message first, the original message is deleted, and the recipient is informed that you, the sender, have deleted the message from their mailbox.
  • If the recipient opens the original message first, the recall fails, and both the original and recall messages are available.

 Note    If the original message is marked as read (viewing in the Reading Pane is not reading in this scenario) when the recall message is processed, the recipient is informed that you, the sender, want to delete the message. However, the message remains in the recipient’s Outlook folder.

You send a message to someone. You recall the original message and replace it with a new one.On the recipient’s computer, either by rule or by action of the recipient, the original message is moved out of the Inbox to another folder and the recall message remains in the Inbox (or it is moved to another folder also). If the recall message and the original message exist in separate folders, the recipient receives a message that indicates a recall attempt failed. This occurs regardless of the Outlook configurations and the read status of the message.The original message and the new message are both available to the recipient.
You send a message to someone. You recall the original message and replace it with a new one.On the recipient’s computer, either by rule or by action of the recipient, both messages are moved to the same folder. This results in behavior similar to what occurs when Outlook is not configured to automatically process messages. On the recipient’s computer, one of the following results occurs:

  • If the recipient opens the recall message first, the original message is deleted, and the recipient is informed that you, the sender, deleted the message from his or her mailbox.
  • If the recipient opens the original message first, the recall fails, and both the old and new messages are available.
You send a message to a public folder. You recall the original message and replace it with a new one. One of the following results occurs:

  • If the recipient who reads the recall message has read access to all the items in the public folder but did not read the original message, the recall succeeds, and only the new message remains. You, the sender, receive a message that indicates the recall succeeded.
  • If the recipient has already marked the original message as read, he or she is informed that the recall failed, and only the recall message is deleted.

If a user who has any other public folder rights opens the recall message, the recall fails, and the user receives a message that states the recall failed. Both the old and new messages remain in the public folder.

 Notes 

  • If the recipient reads the original message and then marks it as unread, it is considered never read and recall is successful.
  • In the public folder, it is the reader’s rights, not the sender’s, that determine the success or failure of the recall.
{ 1 comment }

Pstip# Get Drive letter from a path

When working with paths it is often required to find out the drive letter of of a path. I generally do this using Dotnet methods, but just realized that PowerShell has a buil-in way to do this.

The Split-Path cmdlet can help you doing this. Look at the before sample code.

function Get-DriveLetterFromPath {            
[cmdletbinding()]            
param(            
[parameter(mandatory=$true)]            
[string]$Path,            
[switch]$Resolve            
)            

Try {            
    if(Split-Path -Path $Path -IsAbsolute) {            
        Split-Path -Path $Path -Qualifier -Resolve:$Resolve -ErrorAction Stop            
    }            

} catch {            
    Write-Host "Failed to get drive letter. Details : $_"            
}            

}

This function has one mandatory parameter name -Path and one optional parameter -Resolve. The -Resolve parameter will resolve the path that you are passing through Path parameter.

Hope you find this useful.

{ 0 comments }

In this post, I will show you how to use Powershell for enabling or disabling OU protection in Active Directory.

In my last post, we have seen how to query Organization Units in Active Directory that has protection enabled. Now we will see how to enable or disable this protection option using PowerShell.

As I said earlier, the ProtectedFromAccidentalDeletion property of OU object stores the status of protection. In the below script I am using Set-ADOrganizationalUnit cmdlet from ActiveDirectory module to set this property.

The script takes DN of the OU object as input and verifies if it exists (see my previous post). It does it as part of parameter validation so that script can exit if a wrong OU path is provided. Rest of the code is very simple, and I hope it doesn’t require any explanation. However, please feel free to post questions if you have any.

Test this script in your test environment before you decide to use in production.

CODE:

function Set-OUProtection {            
[cmdletbinding()]            
param(            
[parameter(ParameterSetName="Enable")]            
[parameter(ParameterSetName="Disable")]            
[ValidateScript({[ADSI]::Exists("LDAP://$_")})]             
[string]$DN,            
[parameter(ParameterSetName="Enable")]            
[switch]$Enable,            
[parameter(ParameterSetName="Disable")]            
[switch]$Disable            
)            

try {            
 Import-Module ActiveDirectory -ErrorAction Stop            
} catch {            
 Write-Error "Failed to Import the active directory module"            
 exit(1)            
}            

Switch ($PsCmdlet.ParameterSetName) {            
 "Enable" {             
    try {            
     Set-ADOrganizationalUnit -Id $DN -ProtectedFromAccidentalDeletion $true -ErrorAction Stop            
     Write-Host "Successfully enabled Protection on OU : $DN"            
     break            
    } catch {            
     Write-Host "Failed to enabled Protection on OU : $DN"            
    }             
   }            
 "Disable" {            
    try {            
     Set-ADOrganizationalUnit -Id $DN -ProtectedFromAccidentalDeletion $false -ErrorAction Stop            
     Write-Host "Successfully disabled Protection on OU : $DN"            
     break            
    } catch {            
     Write-Host "Failed to disable Protection on OU : $DN"            
    }             
   }            

}            

}

Output:

{ 1 comment }