≡ Menu

Do you have a mix of Windows Server 2003 and Windows Server 2012 R2 domain controllers in your domain and occasionally experiencing logon issues? It could be due to Computers which changed their machine password recently and failing to communicate with domain after that. AskDS(Microsoft Active Directory support team) recently published an article about this which gives further details into this problem and a few possible workarounds. You might want to try them if you are seeing similar problems in your environment.

http://blogs.technet.com/b/askds/archive/2014/07/23/it-turns-out-that-weird-things-can-happen-when-you-mix-windows-server-2003-and-windows-server-2012-r2-domain-controllers.aspx

 

{ 0 comments }

I came across a post from a PowerShell MVP at happysysadmin.com blog about finding boot performance of Windows Client operating system with PowerShell. I liked this post alot because of very good explanation he provided about different parameters involved in boot and how to interpret them.

Worth taking a look.

http://www.happysysadm.com/2014/07/windows-boot-history-and-boot.html

Thanks  for this wonderful article.

{ 0 comments }

Windows Server 2012 and Windows 8.1 has inbuilt module for managing Group Policy objects in Windows environment. It has a total of 26 cmdlets to serve different types of Group policy operations. In this article I will focus on Get-GPO cmdlet and its usage.

You can start with importing the module first.

Import-Module GroupPolicy

This module is made available automatically when you install domain controller role in Windows Server 2012. If you want to install this module on a member server running windows server 2012, you can do it by adding Group Policy Management feature. This installs both MMC and PowerShell modules.

gpo module install

If you want to install this feature also via PowerShell, then try the below two commands. This will install GPMC.

Import-Module ServerManager            
Add-WindowsFeature GPMC

Get total no. of cmdlets in GroupPolicy module

To see the no. of cmdlets available in this module, below command will help.

(Get-Command -Module GroupPolicy | ? {$_.CommandType -ne "Alias" }).Count

List all Group policies in domain.

If you want to list all Group policies in current domain, use Get-GPO cmdlet with -All parameter. This will all GPOs in the current domain. This will return information like Displayname, GUID, GPO status, creation and modified time, etc of each GPO.

Get-GPO -All

Search for a GPO

Searching for a GPO by display name is also easy. Its matter of filtering the output generated from Get-GPO cmdlets.

Get-Gpo -all | ? {$_.displayName -match "Logon" }
filter-gpo-by-name

Convert to GUID to Name and Name to GUID:

If you know GUID of a GPO, you can get the display name of and similarly you can get GUID if you know the display name of it. Finding this information in prior operation systems requires either nontrivial coding or usage of third party tools/scripts.

Get-GPO -Name LogonPolicy | select id
Get-GPO -Guid 98cbbc75-de94-4093-9b46-d4100230849e | select displayname

gpo-name-to-guid-to-name

Specify DC name/domain name to query:

If you would like to query Group policy information from a specific domain controller, you can do that by pointing Get-GPO cmdlet to domain controller by specifying -Server parameter. You can also specify the name of the domain in FQDN format.

Get-GPO -all -Server TIBDC1

Export Group policy information to CSV:

The group policy information can be easily exported to a CSV/Excel by using Export-CSV cmdlet in combination with Get-GPO cmdlet.

Get-GPO -all | export-csv c:\temp\GPOinfo.csv -NoTypeInformation

Hope this helps. Happy learning. In next post I will cover about other Group Policy cmdlets and their usage.

{ 4 comments }

Previously I talked about how to read the start menu pinned items and their group details using PowerShell. If you have missed that article, read it from https://techibee.com/powershell/query-start-menu-groups-and-pinned-programs-in-windows-8-1-using-powershell/2395 . In this post I will share my thoughts on customizing the start menu layout for Windows 8.1 based users using Group policies.

In my previous post, I have used Export-StartLayout cmdlets to export the start menu pinned items configuration. When I was using that cmdlets, I came across Import-StartLayout cmdlets which I thought can be used for importing the start menu layout. But after some reading, I understood that it is used only for importing into build images. So, this is not useful for deploying a standard new (or updated) start menu style to existing users who are already using Windows 8.1 desktops.

While searching for ways to do it, I came across a group policy named “Start Screen layout” at below path in group policy console.

Start menu layout GPO

User Configuration => Administrative Templates => Start Menu and Task bar => Start Screen Layout

And the policy description says this:

===========================

Specifies the Start screen layout for users.

This setting lets you specify the Start screen layout for users and prevents them from changing its configuration. The Start screen layout you specify must be stored in an XML file that was generated by the Export-StartLayout PowerShell cmdlet.

To use this setting, you must first manually configure a device’s Start screen layout to the desired look and feel. Once you are done, run the Export-StartLayout PowerShell cmdlet on that same device. The cmdlet will generate an XML file representing the layout you configured.

Once the XML file is generated and moved to the desired file path, type the fully qualified path and name of the XML file. You can type a local path, such as C:\StartLayouts\myLayout.xml or a UNC path, such as \\Server\Share\Layout.xml. If the specified file is not available when the user logs on, the layout won’t be changed. Users cannot customize their Start screen while this setting is enabled.

If you disable this setting or do not configure it, the Start screen layout won’t be changed and users will be able to customize it.

===========================

So, I enabled this policy with the exported XML file that I captured with Export-StartLayout. It worked as expected but with a few caveats.

It worked but took away a few things users/administrators really need. After applying the style through Group policies, noticed the following.

  • Users cannot pin any more new items – this is already mentioned in GPO description
  • Whatever the previously pinned items by the users will go vanished – that is what I observed in testing. Let me know if you see any different behaviour
  • Users cannot even pin new items to their task bar from Apps menu

So bottom line is that, you should keep above points in mind before deciding to deploy start menu layout using Group policy. Setting a default layout in build is a good idea in my opinion.

{ 0 comments }

Like any other Hypervisor infrastructure, VMs in Microsoft Hyper-V can also sync time from its host. This time synchronization happens through Hyper-V integration services. Along with Time sync a few other things like OS Shutdown, Data exchange, heartbeat, snapshot operations are performed via this integration service.

These features can be enabled or disabled via PowerShell in Hyper-V environment. In this post, let us see how to enable/disable time synchronization in Hyper-V environment using PowerShell.

To know the status of time synchronization between VM and the Hypervisor, try below command. It shows the list of features controlled via Integration services and their status.

Get-VMIntegrationService -VMName Win8

and you will see below output.

VMTimesync-Hyperv

As you can see in the output, Time synchronization is enabled. To disable that feature, we can use Disable-VMIntegrationService cmdlet.

Get-VMIntegrationService -VMName Win8 -Name "Time Synchronization" | Disable-VMIntegrationService

Similarly to enable, it we can use Enable-VMIntegrationService cmdlet.

Get-VMIntegrationService -VMName Win8 -Name "Time Synchronization" | Enable-VMIntegrationService

At any point of time, you can view the current state by running Get-VMIntegrationService.  Like Time synchronization, we can manage other features like OS shutdown, VSS, Key-Value Pair exchange, Hearbeat via these cmdlets.

Get-VMIntegrationService -VMName Win8 -Name "Time Synchronization"

Hope this helps

{ 1 comment }

The PowerShell script discussed in this article will help in querying Programs and groups pinned to start menu in Windows 8.1 metro UI. It also gives their size and the executable that it is pointing.

Windows 8.1 has a PowerShell cmdlet, Export-StartLayout, that helps in exporting the current UI setting. This will export Start Menu items along with their group name and size to XML file (or bin file). Parsing this XML file will help in reading the list of applications that are currently pinned to start menu.

The below code will export the details to XML file and read details from it to produce output in Object format. The details will contains, application name, group that it belongs, size of the icon in start menu, and fensepost value (not sure what it represents as I am writing this. Will search for it later).

CODE: Get-StartMenuItems.ps1

[cmdletbinding()]            
param(            
)            
$XMLPath = Join-Path $env:temp "startmenu.xml"            
            
Export-StartLayOut -As XML -Path $XMLPath            
$Content = Get-Content $XMLPath            
$Groups = $Content.GetElementsByTagName("group")            
foreach($Group in $Groups) {            
 #$Group.Getenumerator()            
            
 $Tiles = $Group.Getenumerator()            
 $GroupName = $Group.Name            
 foreach($Tile in $Tiles) {            
            
  $AppID = $Tile.AppID            
  $Size = $Tile.size            
  $FensePost = $Tile.FencePost            
  $OutputObj = New-Object -TypeName PSobject            
  $OutputObj | Add-Member -MemberType NoteProperty -Name GroupName -Value $GroupName            
  $OutputObj | Add-Member -MemberType NoteProperty -Name AppID -Value $AppID            
  $OutputObj | Add-Member -MemberType NoteProperty -Name AppSize -Value $Size            
  $OutputObj | Add-Member -MemberType NoteProperty -Name FensePost -Value $FensePost            
  $OutputObj            
              
 }            
            
            
}            

Output:

startmenuitems

This script is available at TechNet Gallery… http://gallery.technet.microsoft.com/Get-start-menu-items-in-df4158c7

{ 0 comments }

While playing with a code today, I wanted to pin a few of my applications to start menu using PowerShell. I know that it is pretty easy through “Shell.Application” Com Object by accessing verbs() of the executable or link file.

I quickly verified that applications I want to link to start menu has the verb “Pin to Start”. So, I thought its matter of calling that verb through PowerShell. In past I have done similar thing for pinning applications to task bar(read this post for details — https://techibee.com/powershell/pin-applications-to-task-bar-using-powershell/685) , so thought of applying same logic here. But at the end failed miserably.

Though the application I want to pin to start menu has this verb when I right click on it, same is not visible when accessed programmatically. Do you understand what I am saying? See the below example.

For demonstration, I want to pin “Microsoft Word” application to start menu. So, I right clicked on windows.exe to see if it has verb called “Ping to start” – yes it has.

pin-start-menu-ui

Now I tried to access the verbs programmatically using PowerShell. Below few lines of code will return verbs of the given application.

$shell = New-Object -ComObject "Shell.Application"            
$Folder = $shell.NameSpace("C:\Program Files\Microsoft Office 15\root\office15")            
$exe = $Folder.ParseName("winword.exe")            
$exe.Verbs()

After running above code, you can clearly see that there is no Pin to Start verb in output. So you cannot call it programmatically.

pin-to-start-verb-missing

After searching for some time, I came across a post in MSDN forums which says that programatical access to pin to start verb is restricted in Windows 8.1. This means you cannot no more perform pin to start menu operation using scripts/tools. Only users can interactively do this.

Related threads:

http://social.msdn.microsoft.com/Forums/en-US/35e91e6a-7d5e-4a32-9a9c-c30990de8a05/why-could-not-get-pin-to-start-context-menu-for-lnk-file-in-windows-81-rtm?forum=windowsgeneraldevelopmentissues

Then how to customize the start screen in Windows 8.1 environment? This I will cover in my next post. Stay tuned.

{ 0 comments }

Often you might be hearing complaints that SQL queries running slow on Windows Server 2008 R2 or Windows Server 2012. You will be puzzled after finding CPU, Memory, Disk, and Network utilization normal but still the queries are running slow when compared with other Windows Server 2003 boxes.

Many people I talked to said they have this problem though their server is built with high Hardware configuration. I has similar chat with one of my previous college when on vacation last week. Since this is more hindering problem for Windows Administrators, I want to put up an article based on this.

Both Windows Server 2008(and R2) and Windows Server 2012(and R2) comes with a default Power Plan of “Balanced” and this is the culprit in most slow performance cases. All latest processors has something called P-States (Power States) which will allow low power utilization by Processor by reducing the processor clock speed when Server is not loaded with any tasks and appears ideal. When a new process starts that requires high CPU processing power, the Operating system switches the processor from lower P-States to higher P-States to increase the CPU performance. This is in a Nut Shell. Read the articles posted at the end of this article to read more about these P-States.

Switching to lower P-States (Balanced Power plan) helps you in saving energy bills at the cost of slow running application. To get rid of this new Power optimization thing and let your processor run at full frequency, follow the below procedure.

Change the Power plan in Windows OS to “High Performance”:

To change a power plan:

  1. Click on Start and then Control Panel.
  2. From the list of displayed item under Control Panel click on Power Options, which takes you to select a power plan page. If you do not see Power Options, type the word ‘power’ in the Search Control Panel box and then select choose a power plan.
  3. By default, the option to change power plans is disabled. To enable this, click the Change settings that are currently unavailable link.
  4. Choose the High Performance option
  5. Close the Power Option window

Change the Power plan in Hardware to “High Performance”:

There are a similar settings available at the Hardware level as well. I recommend you change them at hardware level as to “High Performance”. In case of HP hardware, you can manage them from ILO Power option. Below are the options available in HP hardware and make sure to select HP Static High Performance mode.

You can configure Power Regulator for any of four operating modes:

  • HP Static High Performance mode
  • HP Static Low Power mode
  • HP Dynamic Power Savings mode
  • OS Control mode

As you can see there is an OS control mode available as well. By selecting this option, you are configuring hardware to allow OS to change the hardware level settings. When this option is selected, and you switch the OS to “high performance” power plan, the hardware also automatically switched to high performance mode.

A restart is required after the above changes. It is not mandatory that this particular solution will help in all cases but it is one of the things you should try when you notice slow SQL query times on a Windows Server.

There is a KB article (http://support.microsoft.com/kb/2207548/en-us) on this topic which recommends setting the server to high performance mode when performance degradation is observed.

If you want tune your Windows Server 2008 R2 or Windows Server 2012 further, you might find this article useful (http://www.microsoft.com/whdc/system/sysperf/Perf_tun_srv-R2.mspx)

Related links:

https://software.intel.com/en-us/blogs/2008/05/29/what-exactly-is-a-p-state-pt-1

http://h10032.www1.hp.com/ctg/Manual/c00300430.pdf

http://support.microsoft.com/kb/2207548/en-us

{ 0 comments }

I came across a question in Technet Forums about how to merge multiple CSV files into one single CSV with additional column added to the output file that indicates the file name from where it imported. You can read full question at http://social.technet.microsoft.com/Forums/en-US/c9470c3e-37a2-48e0-8170-a235fbee2d2e/merging-several-csv-files-in-one-csv-file?forum=winserverpowershell

To address the need, I prepared a quick PS function. Posting it here for my blog readers reference.

CODE:

function Merge-CSVFiles {            
[cmdletbinding()]            
param(            
    [string[]]$CSVFiles,            
    [string]$OutputFile = "c:\merged.csv"            
)            
$Output = @();            
foreach($CSV in $CSVFiles) {            
    if(Test-Path $CSV) {            
                    
        $FileName = [System.IO.Path]::GetFileName($CSV)            
        $temp = Import-CSV -Path $CSV | select *, @{Expression={$FileName};Label="FileName"}            
        $Output += $temp            
            
    } else {            
        Write-Warning "$CSV : No such file found"            
    }            
            
}            
$Output | Export-Csv -Path $OutputFile -NoTypeInformation            
Write-Output "$OutputFile successfully created"            
            
}            
            

INPUT FILES AND OUTPUT:

File1.CSV:

csvfile1

File2.CSV

csvfile2

Run the below command to merge above two CSVs.

Merge-CSVFiles -CSVFiles C:\temp\file1.csv,C:\temp\file2.csv -OutputFile c:\temp\output.csv

Output CSV will be like this.

outputcsv

Happy learning…

{ 16 comments }

We all know that size conversion in PowerShell is pretty straightforward. If you have a number in bytes and want to convert it into MB or GB, it is as simple as typing 12345/1GB or 12345/1MB in PowerShell prompt or script.

Ok, then where is the problem and why I am writing this post. The real problem comes in two scenarios.

Scenario#1

When you want to convert a value from other than bytes to KB/MB/TB/GB: It is easy to convert any format to other using PowerShell console but when it comes to writing scripts, we will have this problem. For example, VMware datastores will have a property which says CapacityinMB and the value will be integer. In that case, you need to convert the number to bytes and then convert back to your final required format. This is because, from property name you know it is in MB but there is no easy way to make the shell understand that is in MB while doing the conversion. Conversion like 245760/1GB treats 245760 as bytes and calculation will go wrong. We can follow a ugly way like suffixing the number with a string “MB” and then divide it by 1GB (“245760MB”/1GB). I feel this not a good programming approach.

powershell-size conversion 1

Scenario#2

When want to apply precision and return only 2(or any given number) of digits after the dot: Another problem you will notice is the no. of digits you want to have in the precision numbers. When converting using the traditional method, we will end up with more number of precision digits which I want to avoid. I just need 2 or 3 based on my requirement. Again we can address this by using a ugly method by calling Tostring(“00”)

powershell-precision-1

To address above two scenarios, I came with below function which eases the conversion from any-to-any (Bytes, KB, MB, GB, and TB). It also has a facility mention the no. of precision digits you want to have.

Code#

function Convert-Size {            
[cmdletbinding()]            
param(            
    [validateset("Bytes","KB","MB","GB","TB")]            
    [string]$From,            
    [validateset("Bytes","KB","MB","GB","TB")]            
    [string]$To,            
    [Parameter(Mandatory=$true)]            
    [double]$Value,            
    [int]$Precision = 4            
)            
switch($From) {            
    "Bytes" {$value = $Value }            
    "KB" {$value = $Value * 1024 }            
    "MB" {$value = $Value * 1024 * 1024}            
    "GB" {$value = $Value * 1024 * 1024 * 1024}            
    "TB" {$value = $Value * 1024 * 1024 * 1024 * 1024}            
}            
            
switch ($To) {            
    "Bytes" {return $value}            
    "KB" {$Value = $Value/1KB}            
    "MB" {$Value = $Value/1MB}            
    "GB" {$Value = $Value/1GB}            
    "TB" {$Value = $Value/1TB}            
            
}            
            
return [Math]::Round($value,$Precision,[MidPointRounding]::AwayFromZero)            
            
}            
            

Output:

The output is very intuitive and explains the usage.

convert-size-output

Hope this helps…

{ 15 comments }