≡ Menu

Today I had a need to query the default value of a registry key in remote computer. There are several articles on internet which are talking about reading default value of a registry key from local machine but no one has enough information about reading default value of registry from remote computer. After some research I found the code which works for both local and remote computers.

Here you go.

$txtKey = ".txt"            
$computer = $env:computername            
$HKLM   = [microsoft.win32.registrykey]::OpenRemoteBaseKey('ClassesRoot',$computer)            
$txtref  = $HKLM.OpenSubKey($txtKey)            
$txtvalue = $txtref.GetValue($null).tostring()            
write-host $txtvalue

In this example, I am reading the default value of “HKEY_CLASSES_ROOT\.txt” registry key.  The code is self explanatory. Feel free to write in comment section if you have any questions. Happy to help.

Hope this helps..

{ 2 comments }

Convert Decimal number to Integer using Powershell

While writing Powershell scripts we come across the need for converting numbers from one number system to another. In this post, I will show you how to convert a decimal number to Integer.

The easiest way to do this in Powershell is, using the [int] accelerator. Look at the below example for more clarity.

$decimal = 10.51            
$integer = [int]$decimal            
write-host $integer

Another way available is to use the System.Math dotnet class which has functions to adjust a decimal to nearest integer. For example, if your decimal value is 10.12, you can either adjust it to 10 or to 11. Based on your requirement, you can use one of Ceiling() or Floor() methods of Math class. See below example for more details.

[System.Math]::Ceiling(10.1) # adjusts the value to 11            
[System.Math]::Ceiling(10.8) # adjusts the value to 11            
[System.Math]::Floor(10.1) # adjusts the value to 10            
[System.Math]::Floor(10.8) # adjusts the value to 10

Output:

Hope these examples helps you in doing the conversions. Happy learning.

{ 0 comments }

This post will talk about GFI cloud based Windows Servers monitoring platform (Network server monitor online– NSMO) for small sized organizations.

Trust me, System administrators job never has 9 to 6 working hours. Someone might call you during midnight to complain about their mailbox inaccessibility or over a weekend to report a server unavailability. That is the reason most System administrators end up with 24X7 working hours and keep checking their cell phone of any missed calls. This situation can be improved if your organization has proper monitoring in place which alerts you over email/SMS when a something goes wrong with the infrastructure. This post is exactly for such windows administrators who want to get alerted about any IT infrastructure outages like server going down, service going down, disk space issues, etc.; so that you can fix them well ahead of time before any of the users reporting the issue.

I came across a cloud based monitoring solution named Network Server Monitor (NSMO) from GFI Software(www.gficloud.com/nsmo) which can help you get alerted about any IT outages. The very good thing about this monitoring system is, it is cloud based. That means, monitoring is provided as service and you don’t need to worry about managing/supporting this monitoring system.

Pros:

  1. Using GFI cloud based monitoring you can monitor following components of your windows servers
    • Service running status
    • Free disk space
    • Backup completion status
    • Antivirus updates status
    • Critical Windows Event log errors
    • Server availability/reachability
    • Disk performance/health
  2. When any failure is noticed, it can alert you by email or SMS or both
  3. It has provision to restart a service when it is down and configuration options available to send alert after x failed attempts to rectify the problem.
  4.  A dashboard available to give a quick view of your IT infrastructure health status.
  5. The monitoring dashboard is web based that means you can access it from your PC, mobile, tablet, etc
  6. You can reboot the servers remotely from dashboard if you notice any issues with them. No need to reach office during weekends just for rebooting the servers.
  7. Easy setup, installation and configuration
  8. Low licensing cost( I read that it is $12 per server, per year, per service)

Cons:

  1. Cannot perform custom actions like executing commands or scripts on the servers remotely
  2. No other checks are possible apart from the ones given in Pros section
  3. No trend analysis and report generation about alerts is possible
  4. Need to install GFI cloud agent on your servers to start monitoring them. No use of native interfaces like WMI, WINRM and other windows APIs.
  5. Not a good solution if your IT infrastructure is BIG and you have custom monitoring requirements.
  6. It cannot monitor other network devices like printers and scanners.
  7. It cannot monitor network devices.
  8. No remote control is possible.

Dashboard:

References:

  1. Home Page: http://www.gficloud.com/nsmo
  2. Features and benefits: http://www.gficloud.com/nsmo-features-and-benefits
  3. Documentation and further reading: http://www.gficloud.com/nsmo-resources#nsmo

Conclusion:

I feel this is a very good service for small organizations where the no. of servers are <20 and monitoring requirements are simple. It gives the flexibility to System administrators to monitor their infrastructure from anywhere in the world through web. It sends real time alerts about any outages so that System administrators can act before someone reports the problem during midnights.

Disclaimer:

The thoughts expressed in this post are completely my personal views. The content provided here is just for information purpose only and I am not responsible in any way for any misbehaviors of the product. I request you to perform complete evolution of the product before you take a call about purchase/implementation.

{ 0 comments }

Check if a string is NULL or EMPTY using PowerShell

In this post, I will show you how to verify if a string is empty, null or having white spaces using Powershell.

Checking if a string is NULL or EMPTY is very common requirement in Powershell script. If we don’t do that we will end up with run time errors if we try to perform some operation on that string variable which is empty or null. So the question now is, how to check it?

Well, below is the most often used technique to check if a string is NULL or empty

            
if($mystring) {            
    Write-Host "string is not empty"            
} else {            
    Write-Host "String is EMPTY or NULL"            
}

Most scripts use this method, however we can make things better by using “System.String” dotnet class. It has a method IsNullOrEmpty() which returns true if the passed string is null or empty. See the below example for clarity

IF([string]::IsNullOrEmpty($mystring)) {            
    Write-Host "Given string is NULL or EMPTY"            
} else {            
    Write-Host "Given string has a value"            
}

Both the methods described above gives you the same functionality. But if you want more meaningful and neat look to your code, I would prefer the second method.

Now you might get a question, what if the $mystring has white space as value. It is neither a EMPTY value nor a NULL value so we can not use IsNullOrEmpty() method in this case. If you try it, it will return False which means string is not NULL or EMPTY. In such cases we can use another method available with System.String class. That is IsNullOrWhiteSpace() . The good thing about this method is it covers all three cases, NULL, EMPTY, and WHITESPACE. It will work for any number whitespaces in the variable. See the below examples for clarity

IF([string]::IsNullOrWhiteSpace($string1)) {            
    Write-Host "Given string is NULL or having WHITESPACE"            
} else {            
    Write-Host "Given string has a value"            
}            

$string1 = " "            
IF([string]::IsNullOrWhiteSpace($string1)) {            
    Write-Host "Given string is NULL or having WHITESPACE"            
} else {            
    Write-Host "Given string has a value"            
}            

$string1 = ""            
IF([string]::IsNullOrWhiteSpace($string1)) {            
    Write-Host "Given string is NULL or having WHITESPACE"            
} else {            
    Write-Host "Given string has a value"            
}

After executing above code you will get Given string is NULL or having WHITESPACE three times in output.  So, it is clear that theIsNullOrWhiteSpace()method is working for detecting NULL, EMPTY and WHILESPACE strings.

Hope this helps and happy learning..

Please feel free to write in comments section if you have any questions.

{ 11 comments }

Query Environment Variables using PowerShell

In this post I will show you how to query both user and computer environment variables using Powershell.

There are several ways available to query environment variables of a computer using Powershell. Out of them, I like dotnet way the most. The System.Environment  MSDN class has methods using which we can query user specific and computer specific environment variables of local computer. For easy understanding of usage, I am giving few examples below.

Query PATH environment variable of current logged on user:

[environment]::GetEnvironmentVariable("PATH","User")

Query PATH environment variable of computer:

[environment]::GetEnvironmentVariable("PATH","Machine")

Query TEMP environment variable of current logged on user:

[environment]::GetEnvironmentVariable("TEMP","User")

Query TEMP environment variable of Computer:

[environment]::GetEnvironmentVariable("TEMP","Machine")

After going through the above examples, you might have already got the idea about how to use [Environment]::GetEnvironmentVariable method. As you have noticed, this method takes two arguments. First one is name of the environment variable whose values you want to query and the second one is type of environment variable. This type has three possible values, User, Machine and Process. The User type represents user environment variable, Machine represents computer environment variable.

 

Hope this this helps…

{ 0 comments }

In this post I will show you how to configure your Exchange 2010 server to send emails to internet.

I recently entered Windows Azure 90 days trial program and hosted my test lab in the cloud. My test lab contains AD and Exchange services. Since this is not the first time I am configuring AD & Exchange services test lab, my setup completed too quick. If you are interested, read my previous article about Step-by-step Exchange Server 2010 Installation Guide. While testing something, I got a requirement to test email flow to internet. My test lab contains AD on one server and Exchange Maibox, CAS, and HTS roles on other server.

Here is the procedure I followed to create the send connector that sends emails from Exchange organization to internet. I am giving both ways(Exchange console method and Powershell way) to do this.

Using Exchange Management Console:

  • Open the Exchange Management Console
  • In the console tree, expand Organization Configuration, select Hub Transport, and then in the work pane, click the Send Connectors tab.
    In the action pane, click New Send Connector. This starts New SMTP Send Connector wizard .
  • On Introduction page, give a meaningful name to your connector and set the Select the intended use for this connector field to internet and click Next.
  • On the Address space page, click Add and select SMTP Address space.
  • In the SMTP Address space popup window, enter “*” in Address Space field without quotes as shown below and click OK and click Next on Address Space page.
  • On the Network settings page, select Use domain name system (DNS) “MX” records to route mail automatically and click Next
  • In Source Server page select the HTS server which is responsible for sending emails to Internet From your Exchange organization. In my case it is TIBR2. Click Next Once you are done.
  • Review the summary and click on New button as shows below
  • This completes configuring your Exchange 2010 organization to send emails to external world. You can send a test email from any mailbox to any internet email account like gmail and verify it is delivered. Mine is working without any issues.

Using Powershell

Open Exchange Management Shell and execute the following Powershell command.

New-SendConnector -Name "From Techibee.net to Internet" -AddressSpaces "*" -Usage Internet -DNSRoutingEnabled $true -SourceTransportServers TIBR2

A few important notes:

  • The DNS server configured in HTS server which was nominated to send emails to outside should have proper DNS server settings so that it can resolve the MX records of domains to which your users will send emails.
  • The HTS server which was nominated should be able to reach the MX servers of the target domains on port 25. This is required to deliver emails to target email servers. You need to configure your firewall rules accordingly if you have any.
{ 0 comments }

Microsoft has announced 90 day free trail of Windows Server 2012 in their Azure environment. Per their description, you can deploy a windows server 2012 from their pre-built images and explore the features by just RDPing to the host.

I subscribed to this program today and here is what I got as part of trail.

 

If you want to try, follow the below steps.

Are you ready to try the Windows Server 2012 operating system in minutes with no test hardware required? Without downloading an ISO or VHD file or installing anything, you can be up and running in just a few steps.

Step 1 – Sign up for a FREE 90-day trial of Windows Azure

  • In a few short steps, enable your trial and get access to all of the Windows Azure services at no cost or obligation
  • The trial allows you to create several Windows Server 2012 Virtual Machines on our Windows Azure public cloud.
  • Join the thousands of others easily and efficiently experiencing Windows Server 2012 on Windows Azure.

Step 2 – Deploy a Windows Server 2012 Virtual Machine from our gallery of pre-built test images

  • With a few clicks, deploy a clean image from our gallery in just minutes.
  • Use Remote Desktop to manage your new virtual machine just like you would a physical server.
  • Test and evaluate Windows Server 2012 features on your fully functional virtual machine.
  • With Window Azure Virtual Network, securely link your new virtual machine to your data center, allowing it to interact with your existing resources.

Step 3 – Learn more about what you can do with Windows Server 2012 on Windows Azure

Continue the conversation!

Want to ask a question or join the community of Windows Azure Virtual Machine users? Check out our forums on Stack Overflow or MSDN .

 

{ 4 comments }

In this post, I will show you how to get pop-up windows in System tray notification area using balloon tips and Powershell.

If you are looking for a article about how to get pop-up message box using powershell rather than balloon tip, refer to this article: https://techibee.com/powershell/how-to-get-pop-up-message-box-using-powershell/839

System tray notifications increase the user experience. Say I am  a Powershell script which will shutdown a server and wait for it to come online, I don’t have to keep watching the console to know if my server is up or not. Rather I would rely on some notification (email, pop-up messages, etc) to get the status so that I can work on something else while my server(s) is booting up. It sounds interesting. Isn’t it?

We can list down “n” number of use cases where System tray notifications will come handy in various scripts. I won’t list all of them here as it is impossible and I will leave it to your imagination to get your own list of use cases. However, what I will cover in this post is, the code used for generating system tray notifications using balloon tips. This post is actually inspired from today’s daily tip from http://powershell.com. They have given a basic code using which you can get balloon pop-up message. Here I will give you a sophisticated function which you can use in any script to provide different types of messages.

Function: Show-BalloonTip

function Show-BalloonTip {            
[cmdletbinding()]            
param(            
 [parameter(Mandatory=$true)]            
 [string]$Title,            
 [ValidateSet("Info","Warning","Error")]             
 [string]$MessageType = "Info",            
 [parameter(Mandatory=$true)]            
 [string]$Message,            
 [string]$Duration=10000            
)            

[system.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null            
$balloon = New-Object System.Windows.Forms.NotifyIcon            
$path = Get-Process -id $pid | Select-Object -ExpandProperty Path            
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)            
$balloon.Icon = $icon            
$balloon.BalloonTipIcon = $MessageType            
$balloon.BalloonTipText = $Message            
$balloon.BalloonTipTitle = $Title            
$balloon.Visible = $true            
$balloon.ShowBalloonTip($Duration)            

}

Usage instructions:

Show-BalloonTip -Title “my message” -MessageType Warning -Message “you have a warning dude” -Duration 1000

Show-BalloonTip -Title “Error occurred” -MessageType Error -Message “you have a Error dude” -Duration 1000

Sample Output:

Hope you will find this function useful. Feel free to use it in your scripts.

I welcome your comments for improvisation.

{ 21 comments }

Exchange Server 2013 videos from TechEd Australia 2012

Excited about new Exchange Server 2013 product and unable to find much information about it on web? Channel 9 has made Exchange Server 2013 videos from TechEd Australia 2012 available for folks like you.

Exchange Server 2013 High Availability and Site Resilience

http://channel9.msdn.com/Events/TechEd/Australia/2012/EXL315

Exchange Server 2013 Deployment and Coexistence

http://channel9.msdn.com/Events/TechEd/Australia/2012/EXL332

Exchange Server 2013 Architecture Deep Dive

http://channel9.msdn.com/Events/TechEd/Australia/2012/EXL311

The New Exchange – Archiving and Compliance

http://channel9.msdn.com/Events/TechEd/Australia/2012/EXL333

Hope you will enjoy these videos.

Please refer to Channel9 website for more videos from TechEd Australia 2012

{ 0 comments }

News Updates

  • Script to configure static ports on Exchange Server 2010 : (click here)
  • Preparing your network diagram? Use Vision stencils from Cisco for rich look and proper representation of devices (click here)
  • DHCP Alternate Configuration PowerShell Module : (click here)
  • Here’s how Samsung flew bloggers halfway around the world, then threatened to leave them there (click here)
  • Got my copy! FREE eBook updated for RTM – Introducing Windows Server 2012 (click here)
{ 0 comments }