Archive

Archive for January, 2011

Windows7: Troubleshoot startup performance

January 29, 2011 2 comments

As an IT system engineer, you have probably faced an issue where one particular workstation will not start in a timely fashion. Usually with msconfig.exe could be a lot solved by turning of nonessential services at start-up. But there is also a way to get an overview of all steps that run during a start-up. You can use xbootmgr.exe to generate a report that provides you with valuable startup information in an easy-to-interpret tables or XML file that you can use to help in diagnosing your next startup problem. This tool is included in the Windows SDK toolkit, which you can download on the Microsoft MSDN site: http://msdn.microsoft.com/en-us/windows/bb980924

Install SDK for windows 7

  • Install Windows Performance toolkit
  • Install Debugging tools for Windows

Once the install is complete, start the command prompt as Administrator. Type the following command to generate a boot report and save it to c:\temp folder:

xbootmgr -trace boot -traceFlags BASE+CSWITCH+DRIVERS+POWER -resultPath C:\TEMP

  • -trace boot: Perform a boot trace.
  • -traceflags BASE+CSWITCH+DRIVERS+POWER: default is: BASE+CSWITCH will generate all default info about CPU, I/O, processes, services… , POWER is for Power management events, DRIVERS will generate all Driver events.
  • -resultPath: Specify the location of the output files.


Open “The Performance Analyzer trace file” with extention *.etl. Double-click on the file. Below I will show some interesting graphics of the boot trace file.

The Winlogon

During WinLogonInit, the user logon screen appears, the service control manager starts services, and Group Policy scripts run. WinLogonInit ends when the Explorer process starts. In this example you can see that the GPClient takes 246 seconds to load. This means that there is performance problem with the “Computer policies”. After the first GPClient will run a second GPClient which loads the “User Policies”.

Services

In the services graph you can see exactly how much time it takes for each service to start.

Driver Delays

In this graph you can see which driver files get stuck during the startup process. In this example are no specific delays showed.

Xbootmgr is a fantastic tool that can provide all information you need about the startup/shutdown of a Windows7/Server2008 machine.

Advertisements
Categories: Windows XP / 7

Powershell: Remove all members of an AD group

January 25, 2011 3 comments

PowerShell is sometimes easier then you think. I was looking for a command that removes all members of an AD group. First found a solution with the Get-QADGroup and pipe with Get-QADGroupmember and then removes all members with a foreach Remove-QADGroupMember.

Get-QADGroup $Group | Get-QADGroupMember | foreach { Remove-QADGroupMember -Identity $Group -Member $_.DN }

But it can be a lot easier with the $null variable:

Get-QADGroup $Group | Set-QADGroup -Member $null

Categories: Powershell

Exchange 2007: fix RecipientTypeDetails of Distribution Groups

January 4, 2011 2 comments

In this post I will explain how to change the RecipientType attribute via Powershell. I had a problem in Exchange 2007 that “Distribution groups” were displayed as Usermailboxes. So I figured out why this was and how I could solve this.

In AD you have two attributes: msExchRecipientDisplayType, msExchRecipientTypeDetails. When you output the Distributiongroup attributes in Exchange 2007: “Get-DistributionGroup name | fl” you can see RecipientType and RecipientTypeDetails. Following my experiences are the AD – Exchange 2007 mappings as follow:

msExchRecipientDisplayType (AD) = RecipientType (Exchange 2007)
msExchRecipientTypeDetails (AD) = RecipientTypeDetails (Exchange 2007)

When you create a new Distributionlist is the “msExchRecipientTypeDetails” value default “<not set>” in ADSI Edit:

But the attribute is still set in Exchange 2007: Get-DistributionGroup name | fl
It seems that Exchange automatically takes the RecipientType as RecipientTypeDetails.

My problem was that Distributiongroups were displayed as Usermailbox in the Exchange 2007 Console:

As you can see is the “msExchRecipientTypeDetails” configured with Value 1 which displays the Distribution group as UserMailbox:

I made a Powershell script to empty the attribute “msExchRecipientTypeDetails” from all Distribution groups that are displayed as “user mailbox” in the Exchange Console. It’s unfortunately not possible to configure the RecipientTypeDetails via Set-DistributionGroup. You must configure it via LDAP but this is harder to configure this via Powershell.

Some explanation of the script:

{$_.RecipientTypeDetails -eq “UserMailbox”} : Get all Distribution Groups that equals RecipientTypeDetails “UserMailbox”

Get-DistributionGroup $dis | foreach { $_.DistinguishedName } : Retrieve the Distinguishedname, this is necessary to get the full LDAP Path.

$LDAPPath.PutEx(1, “msExchRecipientTypeDetails”, $null): This command empties the value msExchRecipientTypeDetails

The script:

#Remove the AD attribute msExchRecipientTypeDetails from all Distribution groups that are visible as user mailboxes

#Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
$disAsUsermailbox = Get-DistributionGroup -ResultSize unlimited | where {$_.RecipientTypeDetails -eq “UserMailbox”}
#loop through all distributionLists
foreach ($dis in $disAsUsermailbox)
{

#Fix msExchRecipientTypeDetails in AD so that Distributionlist is displayed as Distributionlist and no longer as usermailbox (change from 1 to <not set>)
$DistinguishedName = Get-DistributionGroup $dis | foreach { $_.DistinguishedName }
$LDAPPath = [ADSI]"LDAP://$DistinguishedName"
$LDAPPath.PutEx(1, "msExchRecipientTypeDetails", $null)
$LDAPPath.setInfo()

}

OCS 2007 R2: Query PIC statistics with PICStats.sql

January 3, 2011 2 comments

In the older Resource Kit Tools of OCS 2007 was a nice SQL query script added which is not available anymore in the OCS 2007 R2 Resource Kit Tools.  The query script Picstats.sql is to report statistics related to public IM use. For example, you can use the script to determine the average number of public IM users that are in the contact list of your deployed users.

On the Standard Edition server navigate in the command prompt to the SQL Binn folder: C:\Program Files (x86)\Microsoft SQL Server\90\Tools\Binn

Execute:

osql.exe -E -S OCS001\RTC -n -d rtc -i c:\temp\picstats.sql

The -E flag Uses a trusted connection, -S Specifies the instance, -n hides the line numbers of the script, -d issues a USE db_name statement when osql is started, -i Identifies the file that contains a batch of SQL statements.

You can get the Picstats.sql from the old resource kit: http://www.microsoft.com/downloads/details.aspx?FamilyID=b9bf4f71-fb0b-4de9-962f-c56b70a8aecd Or copy the script below and save it as Picstats.sql. I corrected line 107 in the script: “from HomedUser as h with(readpast)” -> “from HomedResource as h with(readpast)”


set nocount on
set transaction isolation level read committed

select PicDomain as [PIC Domain],
       ltrim(str(MinContactsPerUser, 7,2))   as [Min Contacts/User],
       ltrim(str(MaxContactsPerUser, 7,2))   as [Max Contacts/User],
       ltrim(str(AvgContactsPerUser, 7,2))   as [Avg Contacts/User],
       ltrim(str(StdevContactsPerUser, 7,2)) as [Stdev Contacts/User]
from (
    -- Statistics on AOL contacts
    select 'AOL' as PicDomain,
           min(ContactCount) as MinContactsPerUser,
           max(ContactCount) as MaxContactsPerUser,
           avg(cast(ContactCount as dec(15,3))) as AvgContactsPerUser,
           stdev(ContactCount) as StdevContactsPerUser
      from (select count(*) as ContactCount
              from Contact as c with(readpast)
             inner join Resource as r with(readpast) on r.ResourceId = c.BuddyId
             where r.UserAtHost like N'%aol.com'
             group by c.OwnerId) as a
    union all
    -- Statistics on Yahoo! contacts
    select 'Yahoo!' as PicDomain,
           min(ContactCount) as MinContactsPerUser,
           max(ContactCount) as MaxContactsPerUser,
           avg(cast(ContactCount as dec(15,3))) as AvgContactsPerUser,
           stdev(ContactCount) as StdevContactsPerUser
      from (select count(*) as ContactCount
              from Contact as c with(readpast)
             inner join Resource as r with(readpast) on r.ResourceId = c.BuddyId
             where r.UserAtHost like N'%yahoo.com'
             group by c.OwnerId) as a
    union all
    -- Statistics on MSN contacts
    select 'MSN' as PicDomain,
           min(ContactCount) as MinContactsPerUser,
           max(ContactCount) as MaxContactsPerUser,
           avg(cast(ContactCount as dec(15,3))) as AvgContactsPerUser,
           stdev(ContactCount) as StdevContactsPerUser
      from (select count(*) as ContactCount
              from Contact as c with(readpast)
             inner join Resource as r with(readpast) on r.ResourceId = c.BuddyId
             where r.UserAtHost like N'%hotmail.%'
                or r.UserAtHost like N'%msn.com'
                or r.UserAtHost like N'%sympatico.ca'
                or r.UserAtHost like N'%webtv.net'
                or r.UserAtHost like N'%passport.com'
                or r.UserAtHost like N'%messengeruser.com'
             group by c.OwnerId) as a
    ) as b

-- How many users have at least one PIC contact?  (and percentage of total this represents.)
declare @CountWithPic int,
        @CountInEnterprise int
select @CountWithPic = count(*)
  from (select count(*) as ContactCount
          from Contact as c with(readpast)
         inner join Resource as r with(readpast) on r.ResourceId = c.BuddyId
         where r.UserAtHost like N'%aol.com'
            or r.UserAtHost like N'%yahoo.com'
            or r.UserAtHost like N'%hotmail.%'
            or r.UserAtHost like N'%msn.com'
            or r.UserAtHost like N'%sympatico.ca'
            or r.UserAtHost like N'%webtv.net'
            or r.UserAtHost like N'%passport.com'
            or r.UserAtHost like N'%messengeruser.com'
         group by c.OwnerId) as a
 where ContactCount >= 1
select @CountInEnterprise = count(*) from ResourceDirectory
select @CountWithPic      as [Users with at least one PIC Contact],
       @CountInEnterprise as [Total Enterprise Users],
       case when @CountInEnterprise > 0
            then ltrim(str(cast(@CountWithPic as dec(15,3)) / @CountInEnterprise * 100.0, 7,2))
            else null
            end           as [% with at least one PIC Contact]

-- Relative percentage of PIC contacts for a user
select
    ltrim(str(min(b.PercentPic), 7,2))                    as [Min PIC %/User],
    ltrim(str(max(b.PercentPic), 7,2))                    as [Max PIC %/User],
    ltrim(str(avg(cast(b.PercentPic as dec(15,3))), 7,2)) as [Avg PIC %/User],
    ltrim(str(stdev(b.PercentPic), 7,2))                  as [Stdev PIC %/User]
from (
    select
        OwnerId, TotalContacts, PicContacts,
        (cast(a.PicContacts as dec(15,3)) / a.TotalContacts * 100.0) as PercentPic
    from (
        select h.ResourceId as OwnerId,

            (select count(c2.BuddyId)
               from Contact as c2 with(readpast)
              where c2.OwnerId = h.ResourceId) as TotalContacts,

            (select count(*) as ContactCount
               from Contact as c3 with(readpast)
              inner join Resource as r with(readpast) on r.ResourceId = c3.BuddyId
              where c3.OwnerId = h.ResourceId
                and (   r.UserAtHost like N'%aol.com'
                     or r.UserAtHost like N'%yahoo.com'
                     or r.UserAtHost like N'%hotmail.%'
                     or r.UserAtHost like N'%msn.com'
                     or r.UserAtHost like N'%sympatico.ca'
                     or r.UserAtHost like N'%webtv.net'
                     or r.UserAtHost like N'%passport.com'
                     or r.UserAtHost like N'%messengeruser.com')) as PicContacts

        from HomedResource as h with(readpast)
        ) as a
    where TotalContacts > 0
    ) as b

Output:

Categories: OCS 2007 / Lync 2010

Powershell: Display the complete content of a value

January 2, 2011 Leave a comment

When you output object attributes that have long value names then you might not view the complete name of the value into the Shell console. I use the following command for an example:

Get-QADUser test_user | select samaccountname, UserPrincipalName, ModificationDate, CanonicalName

You can see that CanonicalName is not displayed completely. The best solution is to use the “format-table -autosize” in combination with a “out-string” with a high string width:

Get-QADUser test_user | select samaccountname, UserPrincipalName, ModificationDate, CanonicalName | Format-Table -AutoSize | Out-String -Width 2000  > test.txt

Just use a high string width, the “format-table -autosize” will trim the column size to a size that is sufficient for the values, then you have always the complete value with a neat column width.

Categories: Powershell

Powershell: Output only values

January 2, 2011 Leave a comment

If you want to hide the columns headings in Powershell output you can use the “-hidetableheaders” parameter.

Example:

Get-QADGroup sales | select samaccountname | ft -hidetableheaders

But white spaces remains when you use this parameter and it might be not  useful when you want to export these values to a text file. You can solve this with the “foreach” loop:

Get-QADGroup sales |  foreach { $_.samaccountname }

Categories: Powershell