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}