≡ Menu

One of my old friend/colleague called me to day for a small help. He is looking for script to get the list of active directory groups that a computer account is member of. Since this is a very basic requirement every System administrator will get, I wanted to post it in my blog.

So, the code described in this post uses Quest Active Directory powershell cmdlets. I can code using the dotnet objects or built-in activedirectory module in windows 7/2008 as well but since I wanted to make it more generic, I opted for Quest cmdlets. Another advantage is that even newbies can query AD with these tools efficiently.

Since I am using Quest AD cmdlets, you should down load them from http://www.quest.com/powershell/activeroles-server.aspx and installed it on your computer. After installation, copy the below code into a file called Get-ComputerGroups.ps1 and run it from Quest AD shell(you can launch this from program files), as shown below.

Get-ComputerGroups.ps1

[cmdletbinding()]
param(
[parameter(mandatory=$true)]
$ComputerName
)            

$Groups = (Get-QADComputer -Id $ComputerName).Memberof            

$Groups | % {
$_.split(",")[0].Split("=")[1]
}

Usage:

[PS] C:\temp\Get-ComputerGroups.p1 -ComputerName MyPC1

Here -ComputerName parameter is mandatory.

Similarly, if you want to provide the computer names from text file and get the active directory group names of all of them, then use the below code.

Get-ComputerGroups.ps1

[cmdletbinding()]
param(
[parameter(mandatory=$true)]
$FilePath
)            

$Computers = Get-Content $FilePath
foreach ($ComputerName in $Computers) {
    write-host "$ComputerName is memberOf following Groups"
    $Groups = (Get-QADComputer -Id $ComputerName).Memberof
    $Groups | % {
    $_.split(",")[0].Split("=")[1]
}            

}

Usage:

[PS] C:\> Get-ComputerGroups.ps1 -FilePath c:\temp\Computersfile.txt

If you want to redirect the output to a text file, just try the below command.

[PS] C:\> Get-ComputerGroups.ps1 -FilePath c:\temp\Computersfile.txt | Out-File c:\temp\output.txt

The output will be written to output.txt file.

Feel free to comment here if you have any doubts.

 

{ 4 comments }

Ever since Windows 8 consumer preview is out, I wanted to upgrade my Home PC. Given I have only one PC, it has some softwares which I use regularly. If some of them not working, then I can do nothing but reverting old OS. That is a waste of time and efforts. I need to install every thing again on after rebuilding with XP/Windows 7 OS.

So, Isn’t it nice if there is a place which can tell me a software or device is compatible with windows 8 Beta? I use software like Nero, VLC player, iTunes and many others on my current home PC and would like to know if they are compatible with windows 8 so that I can consider migrating.

Hurry… There is a way out there…. MS has given a online facility where you can just type in your software or device name to find out the compatibility. In some cases you may need to upgrade the version of software which is totally fine.

I did search for my wish list of softwares that I want to move to windows 8 and go the results I need. You can also do it by visiting below URL to verify the compatibility of your software or devices like printers, mobile devices, gaming devices etc. The list that is given in the website seems to be huge and covering most applications and devices that a normal user need. Don’t look for software you developed or has got it developed. No surprise you won’t see them in the list 🙂

http://www.microsoft.com/en-us/windows/compatibility/en-US/CompatCenter/Home

 

Hope this helps… Happy evaluation…

{ 1 comment }

As promised MS has announced Windows 8 Consumer Preview version and many enthusiastic people has already downloaded and playing with it.

There are two download methods available for this product.

1. Windows 8 Consumer Preview Setup:

If you go to http://windows.microsoft.com/en-US/windows-8/download and request for download, you will see a “Windows8-CustomerPreview-setup.exe” downloading. Basically what this does is, it analyzes your system and gives a detailed report about compatibility of your hardware with Windows 8 Customer preview version and also gives you the tools which can use to build media(DVD/Flash disk) from ISO files.

This is a good option for home users who want to upgrade their current PC to windows 8 CP.

2. Windows 8 ISO files Download:

This is for System administrators like me and also for people who want to do the download from one computer and install it on a different one. You can download the ISO files from http://windows.microsoft.com/en-US/windows-8/iso. English, Chinese(simplified), German, Japanese versions are available for download in both x64(64-bit) and x86(32-bit) formats

Well, after choosing your download method, the next step is installation. Like for any other installation, Windows 8 also has it’s own system recommended configuration for giving better performance.

 

System Requirements

Windows 8 Consumer Preview works great on the same hardware that powers Windows 7:

  • Processor: 1 gigahertz (GHz) or faster
  • RAM: 1 gigabyte (GB) (32-bit) or 2 GB (64-bit)
  • Hard disk space: 16 GB (32-bit) or 20 GB (64-bit)
  • Graphics card: Microsoft DirectX 9 graphics device or higher
  • To use touch, you need a tablet or monitor that supports multitouch
  • To access Windows Store and to download and run apps, you need an active Internet connection and a screen resolution of at least 1024 x 768
  • To snap apps, you need a screen resolution of at least 1366 x 768

 

Hope this information helps you to get started with this brand new OS.

You can also refer to my previous blog post about problems with installing windows 8 Developer preview in virtual environment. People has made good amount of suggestions in comments sections which you will find useful. You can also go through blog post from Microsoft(http://blogs.msdn.com/b/b8/archive/2012/02/29/running-the-consumer-preview-system-recommendations.aspx) to get more details.

Feel free to raise if you have any questions.

 

 

{ 0 comments }

Simple steps to increase your laptop battery life

While researching for some material to prepare my previous article, I stumbled on one of the posts of “Microsoft at work” blog. The post is about best practices to give good life to your battery. The points discussed in the article are interesting and I felt worth sharing it.

You can read the article at http://www.microsoft.com/atwork/maintenance/battery.aspx

 

 

{ 0 comments }

Are you looking for a way to change power plan on local or remote computer? You are at the right place. The script discussed in this article will help you in changing the power plans in PowerShell way. MS built-in tool(powercfg.exe) is available that can also help you to do this job. But I am not using that tool in my script by building a wrapper around it. I am simply relying on WMI class to change the power plan. I recommend WMI way because using executables inside script is not a good practice and it should be our last resort when it is not possible through WMI or dotnet class or some API.

The Win32_Powerplan WMI class will return list of power plans available in the computer. This list includes built-in power plans like”Power Saver”, “Balanced” and “high performance” plus any custom power plans that user has created. Each returned power plan a again  a object which will have a method called Activate() to activate the current power plan. This power plan object also contains a proper called IsActive which will be set to $true if is the active power plan that system is using currently.

The code follows…

Set-PowerPlan.ps1

[cmdletbinding()]                        

param (
[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[string[]]$ComputerName = $env:computername,                        

[ValidateNotNullOrEmpty()]
[parameter(Mandatory=$true)]
[ValidateSet("Power Saver", "Balanced", "High Performance")]
[string]$PowerPlan                        

)                        

begin{}                        

Process {
foreach ($Computer in $ComputerName) {
 if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
  Write-Verbose "$Computer is online"
  $PreviousPowerPlan = Get-WmiObject -Class Win32_Powerplan -Namespace root\CIMV2\Power -ComputerName $Computer | ? {$_.IsActive -eq $true}
  $CurrentPowerPlan  = Get-WmiObject -Class Win32_Powerplan -Namespace root\CIMV2\Power -ComputerName $Computer | ? {$_.ElementName -eq $PowerPlan}
  $CurrentPowerPlan.Activate()
  $OutputObj  = New-Object -Type PSObject
  $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()
  $OutputObj | Add-Member -MemberType NoteProperty -Name PreviousPlan -Value $PreviousPowerPlan.ElementName
  $OutputObj | Add-Member -MemberType NoteProperty -Name CurrentPlan -Value $CurrentPowerPlan.ElementName
  $OutputObj
 } else {
  write-Verbose "$Computer is offline"
 }
}            

}                        

end {}

 

Save the above code into a file called “Set-PowerPlan.ps1” and it is ready for usage. You can use -ComputerName parameter if you want to run against a computer. If this parameter is not specified, it runs on local computer.

Go through the below examples for usage instructions and let me know if you have any questions.

Hope this helps…

{ 2 comments }

MS tool for reporting Outlook calendar issues

Troubleshooting calendar issues is one of the pain areas in Exchange/Outlook. Always there will be ‘n’ no.of items we need to verify to identify why it went wrong. Bad thing about it is, there won’t be any logging in Exchange/MS Outlook to understand what went wrong. All you can do is enable debug logging and send the ETL files to MS support for analysis.

Well, that is a history now. MS has  a tool that can check and report problems with calendar in a given outlook profile. It can also run against mailboxes hosted on a given server. As mentioned, it is just a reporting tool, and will not fix any of the problems. Hmm, having something is better than nothing 🙂

The good things about this tool is it supports below Exchange/Outlook versions.

  1. Microsoft Office Outlook 2003
  2. Microsoft Office Outlook 2007
  3. Microsoft Office Outlook 2010 (32-bit)
  4. Microsoft Office Outlook 2010 (64-bit)
  5. Microsoft Exchange Server 2003
  6. Microsoft Exchange Server 2007
  7. Microsoft Exchange Server 2010

 

What checks this tool does?

The Calendar Checking Tool for Outlook (CalCheck) is a command-line program that checks Microsoft Outlook Calendars for problems. The tool opens an Outlook profile to access the Outlook Calendar. It performs various checks, such as permissions, free/busy publishing, delegate configuration, and automatic booking. Then each item in the calendar folder is checked for known problems that can cause unexpected behavior, such as meetings that appear to be missing.

As CalCheck goes through this process, it generates a report that can be used to help diagnose problem items or identify trends.
Checks performed

The following Calendar-specific checks are performed and logged in the report:

  •     Permissions on the Calendar
  •     Delegates on the Calendar
  •     Free/Busy publishing information
  •     Direct Booking settings for the Mailbox or Calendar
  •     Total number of items in the Calendar folder

The following item-level checks are performed and logged in the report:

  •     No Organizer email address
  •     No Sender email address
  •     No dispidRecurring property (causes an item to not show in the Day/Week/Month view)
  •     Time existence of the dispidApptStartWhole and dispidApptEndWhole properties
  •     No Subject for meetings that occur in the the future or for recurring meetings (a warning is logged)
  •     Message Class check (a warning is logged)
  •     dispidApptRecur (recurrence blob) is checked for time on overall start and end times, not for exceptions
  •     Check for Conflict items in the Calendar
  •     Check for duplicate items, based on certain MAPI properties
  •     Check if over 1250 recurring meetings (a warning is logged) and 1300 recurring meetings (an error is reported); 1300 is the limit
  •     Check if you are an attendee and you became the Organizer of a meeting
  •     Check meeting exception data to ensure it is the correct size

[Above content is grabbed from Exchange Team Blog]

Download and references:

Download Link : http://www.microsoft.com/download/en/details.aspx?id=28786

Exchange Team Blog : http://blogs.technet.com/b/exchange/archive/2012/02/22/calcheck-the-outlook-calendar-checking-tool.aspx

Codeplex project: http://calcheck.codeplex.com/

 

 

{ 1 comment }

Show The Current Date & Time In A Cell in Excel Sheet

At times you may want to include current date & time in a excel sheet. How do you do that automatically?
2 functions help us to do that
  • Today() – Inserts current date
This formula will only update when the worksheet is recalculated or when you reopen the workbook. That’s usually not a problem since the date only changes once a day. Also, you may have to format the cell to give you your desired date format.
  • Now() – Inserts Current Date & Time

 

 
This formula gives you both the date and time in the same cell (i.e. 19-May-03 9:00pm), however, is less useful because the time in the cell won’t change until your worksheet recalculates or when you reopen your workbook. If you just want the cell to display the time only, you’ll have to change the number format by selecting Format, Cells, Number, Time, (select a desired time format), OK
{ 0 comments }

Breaking Administrator Password of Windows XP

As system administrators we could have received multiple calls from laptop/home users saying that they have forgotten the Local Administrator Password and ask us to crack.

While there are many third party hacking /crack tools on net, below article helped me to do that without any of those.

Here is the article which explains in simple way to reset the password… Hope it would be useful to you sometimes in your operations…

http://www.unp.me/f140/break-administrator-password-of-windows-xp-23706/

{ 0 comments }

This post talks about querying Active Directory Sites and subnets information from AD using Powershell. This script is helpful when you want to know subnets mapping to given site and servers lying in a site. This scrip doesn’t need much explanation since it is looking very straight forward. If you defer with me, please comment what part of script you want to understand. Also feel free to post if you would like to query any other information related to sites and services. Happy to help.

Code: Get-ADSites.ps1

[cmdletbinding()]            
param()            

$Sites = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites            

foreach ($Site in $Sites) {            

 $obj = New-Object -Type PSObject -Property (            
  @{            
   "SiteName"  = $site.Name;            
   "SubNets" = $site.Subnets;            
   "Servers" = $Site.Servers            
  }            
 )            

 $Obj            
}

 Output

{ 6 comments }

Powershell: Uninstall software on remote computer

Ok. It’s time to uninstall a application using powershell. This post is continuation to Powershell: Script to query softwares installed on remote computer where I discussed about procedure to query installed applications on remote computer without using Win32_Product WMI class. The one advantage with Win32_Product WMI class is it’s uninstall() function using which we can trigger uninstallation of softwares on local or remote computer.

In this post, I am going to provide a powershell script which provides same functionality as uninstall() function of Win32_Product WMI class. My code uses GUID of product to trigger the uninstallation by passing it to msiexec process. It also triggers the uninstallation in silent mode so no UI will appear for the user while performing the uninstallation.

Code goes here…

[cmdletbinding()]            

param (            

 [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
 [string]$ComputerName = $env:computername,
 [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Mandatory=$true)]
 [string]$AppGUID
)            

 try {
  $returnval = ([WMICLASS]"\\$computerName\ROOT\CIMV2:win32_process").Create("msiexec `/x$AppGUID `/norestart `/qn")
 } catch {
  write-error "Failed to trigger the uninstallation. Review the error message"
  $_
  exit
 }
 switch ($($returnval.returnvalue)){
  0 { "Uninstallation command triggered successfully" }
  2 { "You don't have sufficient permissions to trigger the command on $Computer" }
  3 { "You don't have sufficient permissions to trigger the command on $Computer" }
  8 { "An unknown error has occurred" }
  9 { "Path Not Found" }
  9 { "Invalid Parameter"}
 }

Note that you need my previous script(Get-InstalledSoftware.ps1) and the one discussed in this article(Uninstall-InstalledSoftware.ps1) to make this uninstallation works since the code discussed in this article depends on the output of Get-InstalledSoftware.ps1 script.

Usage:

  1. Run Get-InstalledSoftware.ps1 script and note the GUID of application that you want to uninstall.
  2. Run Uninstall-InstalledSoftware.ps1 -GUID <<uninstall application GUID here>>

Uninstall-InstalledSoftware.ps1 -GUID “{54D3F6B5-515B-45B8-8F41-FC4D26FEFFEA}”

Test this script in test environment before you try on any production computer. Any improper use of this script can trigger the uninstallation of multiple applications if handled improperly.

This can made as single liner…..

.\Get-InstalledSoftware.ps1 -ComputerName MyPC1 | ? {$_.AppName -eq “iTunes” } | .\Uninstall-InstalledSoftware.ps1

This triggers the installation of iTunes applications. Please note that at any point of time you are passing the output single computer to Uninstall-InstalledSoftware.ps1.

This is just a initial version. I will enhance it to accept multiple computers and multiple uninstallations at same time. I will also make it more robust to track the uninstallation process.

Hope this helps..

Your comments are welcome

{ 41 comments }