03 October 2012

Migrating server and agents from DPM 2010 to DPM 2012

Before DPM Server installation, make sure, that your Time Zone is correct. To change Time Zone after DPM installation, follow the instructions (http://technet.microsoft.com/en-us/library/hh758055.aspx):

  1. Change Time Zone on Windows Server
  2. net stop msdpm
  3. DPM Console – Options, Auto Discovery. Change the schedule (this triggers the recalculation of time zones on all jobs)

For server migration, install a new server with Windows Server 2008 R2 and DPM Server 2012 (currently I’m having problem with Windows Server 2012, restore operation is unavailable).

For client migration (use the following steps in this sequence):

  1. Stop dpm agent on client machine (net stop dpmra)
  2. Uninstall dpm agent from client machine using appwiz.cpl (Add/Remove Programs) or by command line (usable on Core Editions):
    Windows 2008
    MsiExec.exe /X{5EB850FE-84F7-4856-A203-0F80BC93C66A}
    Windows 2003
    MsiExec.exe /X{3EC7C770-9F3F-4177-A754-EBFF04A1AFF2}
  3. Remove Protection Group from old DPM Server (you probably will retain the data, since new data is not yet available)
  4. Disable firewall on client machine
  5. Uninstall agent from old DPM Server and remember those things:
    1. don’t install the new agent before this step
    2. the uninstall will throw error message because we already removed it, this is ok, if the agent disappears from Agents list on DPM Server
    3. please remove client manually and stop the service before the manual uninstall, this way you can avoid the restart of client machine
  6. Install the agent from new DPM Server
  7. Enable the firewall on client machine (if it was disabled in step 4)
  8. Create new Protection Groups and enjoy the game

28 September 2012

Scheduled reboot for Windows Server

If you need to restart a Windows Server, you have a lot of options:

  1. Use PowerShell cmdlet Restart-Computer.
  2. Use Sysinternals tool psshutdown.exe (downloadable from http://live.sysinternals.com/psshutdown.exe, sometimes it’s available also with UNC \\live.sysinternals.com\tools\psshutdown.exe, you need to start webclient service using net start webclient in administrative command prompt)
  3. Use the shutdown.exe already in Windows installation.
  4. Or just use graphical interface :)

For instant reboot you can use all of them (for example PowerShell’s Restart-Computer with no parameters reboots local computer instantly).

To schedule a reboot, I suggest psshutdown.exe (shutdown.exe is a strip down version of psshutdown.exe, with less parameters). To shut down the server @22:22 (22 minutes past 10pm) use this command:

psshutdown -f -r -t 22:22

image

The 13:38:00 in the picture doesn’t mean the reboot time, which is 22:22:00. It mean’s that after 13 hours and 38 minutes the server will reboot.

If you need to abort the countdown, use psshutdown –a

image

20 September 2012

How to make yourself MSSQL admin

There is a good chance, that you run into a Microsoft SQL Server, where you don’t have administrative access. This can be happen when SQL is installed using another user account and this account is deleted afterwards.

First of all you need to stop SQL service (it can stop other SQL services also):

image

Then look at the properties of the service. Copy and paste the path to executable to administrative command prompt:

imageimage

Add to the command line "-mSQLCMD" and press Enter. This will run SQL server in interactive and single user mode and allows only sqlcmd to be launched.

image

At a different administrative command prompt run sqlcmd. If it fails with “Only one administrator…” error, then block SQL port using Windows Firewall and try again starting the service manually in single user mode. If it fails with “Token-based server access validation failed with an infrastructure error”, then you are not in administrative command prompt

image

When you succeed running sqlcmd, type two commands:

sp_addsrvrolemember 'domain\user', 'sysadmin'
go

image

Now your account domain\user is an administrator of this SQL server.

To close open command prompt windows gracefully, type quit and press Enter in sqlcmd prompt and press CTRL+C on sql server prompt and press Y.

Also remember to start services.

18 September 2012

Check Calendar folder permissions and reset folder name in Exchange 2010 room mailboxes

If you have several room mailboxes and want to audit Calendar folder permissions, then the PowerShell command you need is:

Get-Mailbox -RecipientTypeDetails roommailbox | %{" ";"$_";"----------";Get-MailboxFolderPermission $_":\Calendar"}|ft -a

If this command doesn’t work, use those two instead:

$rooms = Get-Mailbox -RecipientTypeDetails roommailbox
$rooms | %{" ";"$_";"----------";Get-MailboxFolderPermission $_":\Calendar"}|ft -a

The command will get all room mailboxes and show permissions on each of them like shown on the following picture:

image

As you notice, some of the room mailboxes will throw error messages. That’s because Calendar folder is named differently (for example Kalender when using Estonian or Kalenteri when using Finnish).

To see room mailboxes regional settings, use the command

Get-Mailbox -RecipientTypeDetails roommailbox | Get-MailboxRegionalConfiguration | ft -a

It will show you the information, which isn’t very valuable, because language and folder names can still be different. The output looks like this:

image

As you can see, we have even New Zealand region :) To reset all room mailboxes to common calendar folder name, use this command:

Get-Mailbox -RecipientTypeDetails roommailbox | Set-MailboxRegionalConfiguration -Language "EN-US" -LocalizeDefaultFolderName -DateFormat yyyy-MM-dd

After the change the regional information is changed:

image

And the audit is successful

image

And finally to change for example the Default permission to Author, you can use this command:

Get-Mailbox -RecipientTypeDetails roommailbox | %{Set-MailboxFolderPermission $_":\Calendar" -User Default -AccessRights Author}

30 August 2012

Change Exchange 2010 Receive Connector certificate

If you have IMAP clients, then you want to make sure that the connection is encrypted. By default IMAP uses TCP port 143 and SMTP for sending uses TCP port 25. For encrypted traffic the usual port assignments are TCP port 993 for IMAPS and 587 for SMTPS.

To make the access to Exchange via IMAP clients easier you probably use a nice common name like mail.company.com. For that name you have a 3rd party certificate (or a certificate from a local CA). This certificate must be installed on a local store on every Client Access Server. This can be done via IIS configuration window:

image

Just select the server name from the left and double-click Server Certificates icon. From there you can request or import a certificate:

image

If you have Active Directory Certificate Services, you can use Create Domain Certificate.

For enabling this certificate for different services you need to use Enable-Exchangecertificate cmdlet. To see available certificates for Exchange to use, use Get-Exchangecertificate cmdlet.

Enable-ExchangeCertificate uniqueid -Services pop
Enable-ExchangeCertificate uniqueid -Services smtp
Enable-ExchangeCertificate uniqueid -Services imap
Enable-ExchangeCertificate uniqueid -Services http

Uniqueid is the thumbprint that can be seen in Get-Exchangecertificate output.

For POP and IMAP to get working with new certificate, you must restart corresponding services. For SMTP to get working, you must change the FQDN on affecting receive connector:

image

The FQDN must be the same as the common name on the certificate.

23 August 2012

Getting to know which Hyper-V guest is using disk using PowerShell script

Best way to investigate disk usage on hyper-v host is to look at all guests and figure out, which one is exhausting the system. The only way to get those readings is using perfmon (Performance Monitor) Hyper-V specific counters. Simple Task Manager or Resource Monitor doesn’t give that detail.

I got even further and scripted this. First take a look at the script:

$date = Get-Date
"importing AD module"
import-module activedirectory
"Getting computer list from AD"
$servers = Get-ADComputer -LDAPFilter "(operatingsystem=*server*)" | sort name
$servers |  measure
$i=1
write-host "Getting Hyper-V Disk Activity information..."
$info = $servers | foreach {
    $computername = $_.name
    write-host ($i++) $computername
 
    $readcounter = "\\" + $computername + "\Hyper-V Virtual Storage Device(*)\Read Bytes/sec"
    (get-counter -Counter $readcounter).countersamples | foreach {
        $obj = new-object psobject
        $obj | add-member noteproperty Host ($computername)
        $obj | add-member noteproperty Access ("Read")
        $obj | add-member noteproperty VHD ($_.InstanceName)
        $obj | add-member noteproperty MBps ([Math]::Round($_.CookedValue/1024/1024,2))
        $obj
        }
    
    $writecounter = "\\" + $computername + "\Hyper-V Virtual Storage Device(*)\Write Bytes/sec"
    (get-counter -Counter $writecounter).countersamples | foreach {
        $obj = new-object psobject
        $obj | add-member noteproperty Host ($computername)
        $obj | add-member noteproperty Access ("Write")
        $obj | add-member noteproperty VHD ($_.InstanceName)
        $obj | add-member noteproperty MBps ([Math]::Round($_.CookedValue/1024/1024,2))
        $obj
        }
        
    }
    
$filename2 = "c:\serverinfo\HVdiskactivity {0}.{1:d2}.{2:d2} {3:d2}.{4:d2}.csv" -f $date.year,$date.month,$date.day,$date.hour,$date.minute
# $info | Export-Csv -Path $filename2 -encoding utf8
$info2 = $info | where {$_.MBps -ge 1} | sort MBps -Descending
$info3 = $info2 | ConvertTo-Html
$info4 = [string]$info3
 
if($info2){
Send-MailMessage -SmtpServer smtp.domain.com -To rauno.magi@domain.com -From rauno.magi@domain.com -Subject "Hyper-v guests having greatest VHD activity" -Body $info4 -BodyAsHtml
}

What does this script do? Let’s look at step by step:



  1. First it import’s Active Directory module and uses it to get the list of all servers, which will be recorded to variable $servers

  2. Then it uses this list of servers to query performance information on each of them using get-counter cmdlet. It would be nice to reduce the list to hyper-v server’s only, but this is cosmetical and performance issue and doesn’t affect the functionality

  3. Nice thing is creating a new empty object and populate all properties/rows with data got from new-object cmdlet.

  4. All the information gathered will be stored into $info variable, which can be optionally saved to a csv file. This command is commented out at the moment

  5. Filtered and sorted list (disk activity more than 1MB per second, biggest numbers on top) will be sent as a e-mail message attachment in the message body.

06 August 2012

Getting rid of “reboot from a previous installation” message

Sometimes you might be unable to install some software with the following message:

A reboot from a previous installation is pending. Please restart the system and rerun setup.

This example is from Exchange Management Tools installation.

image

First you should try reboot (sometimes twice) and if this doesn’t work, look at the registry hive

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager

image

The key PendingFileRenameOperations should be normally not present. If it’s there, remove it. Then you can run your setup again and this time successfully.