13 December 2013

How to discover which WiFi AP is being used on Windows 7/8

When you have multiple access point and you want to see, how you are roaming between them and which one is currently in use, then you can monitor this using following procedure:

  1. Press Win+R, Run windows appears
    image
  2. Paste following text:
    powershell do {cls ; netsh wlan show int | findstr SSID ; netsh wlan show networks mode=Bssid | findstr SSID ; sleep 1} while (1)
  3. Press OK
    image

Then you can see which WiFi network you are using and which WiFi AP you are using (WiFi AP-s MAC address). Also you can see, which AP-s are visible.

image

In my case I have two network visible, both with 5 different AP-s. First two lines show What network I’m using (SSID) and which AP I am connected to (BSSID).

24 September 2013

Resolve DPM Agents Time Zone problems quickly

I reside at UTC+2 time zone and it is exactly 10 hours different from Windows Server post installation default time zone (UTC-8). So when I schedule a backup in Data Protection Manager from the server with default time zone, it happens 10 hours later. So about half of my protected servers ran the backup at 12:00 (about lunchtime) instead of 02:00 in the night as it should be. If I change the time zone in the server, it won’t help.

This is because at the installation of the DPM Agent the time zone was not changed yet. Microsoft has the solution, which is very painful (http://technet.microsoft.com/en-us/library/hh757791.aspx). It consists of installation and uninstallation of the agent and recreating the protection group (some of the necessary steps isn’t even mentioned in that article).

After digging in DPM Servers SQL database, I found a quick and a little bit dangerous way of resolving the issue. You need to connect with SQL Management Studio to your DPM database and look at the table tbl_AM_ServerTimeZone:

SELECT * FROM tbl_AM_ServerTimeZone

image

Copy one row with correct time zone to notepad and make a new command according the info you just pasted:

update tbl_AM_ServerTimeZone set
Bias = -120 ,
Description = '(UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius' ,
DaylightName = 'FLE Daylight Time' ,
DaylightBias = -60 ,
DaylightYear = 0 ,
DaylightMonth = 3 ,
DaylightDayOfWeek = 0 ,
DaylightDay = 5 ,
DaylightHour = 3 ,
DaylightMinute = 0 ,
DaylightSecond = 0 ,
DaylightMillisecond = 0 ,
StandardName = 'FLE Standard Time' ,
StandardBias = 0 ,
StandardYear = 0 ,
StandardMonth = 10 ,
StandardDayOfWeek = 0 ,
StandardDay = 5 ,
StandardHour = 4 ,
StandardMinute = 0 ,
StandardSecond = 0 ,
StandardMillisecond = 0

This command updates time zone information on all agents! So please be careful.

After this single SQL command you must edit the badly behaving protection groups. You don’t need to change anything on those, but just click Next, Next, Finish.

image

23 July 2013

Get sizes of inactive protection objects in DPM 2012

If your disk is becoming full on DPM server, then you need to delete inactive protection objects like I described in article http://raunomagi.blogspot.com/2012/05/microsoft-dpm-2010-delete-inactive.html.

But when you don’t want to delete all inactive objects, then you need to analyze, how much space can you recover by deleting individual inactive objects.

This can be done in DPM Management Shell using just one line of code (but a very long one :)

Get-Datasource -Inactive | select computer,logicalpath,@{Name="size"; Expression = {[int](($_.ReplicaSize+$_.ShadowCopyAreaSize)/1GB)}} | sort size -Descending | ConvertTo-Csv -Delimiter `t -NoTypeInformation | clip

image

This command takes all inactive replicas, selects host, path and size in GB. Then sorts it by size, converts to tab separated CSV stream and puts it to clipboard. After that command you can paste the clipboard info into Excel worksheet to do pivot tables or whatsoever.

image

22 July 2013

How to manually remove cluster and host objects from VMM 2012/2016

If you cannot remove cluster object using Virtual Machine Manager GUI or shell, then you need to connect to VMM database using SQL Server Management Studio:

image

Click the New Query button and remember to choose your VMM database name from the drop-down list (in my case VirtualManagerDB).

First take a look at your cluster objects with the command

SELECT * FROM tbl_ADHC_HostCluster

image

In my case the second row contains the cluster I want to delete from VMM database. Then you should put your ID to the following code (second row):

DECLARE @ClusterID GUID, @HostID GUID
SET @ClusterID = '2E60A809-F181-4F4E-B3C1-D75B1AE9FFF2'
SELECT @HostID = HostID from dbo.tbl_ADHC_Host where HostClusterID = @ClusterID
DELETE FROM tbl_WLC_VObject WHERE HostId = @HostID
DELETE FROM tbl_ADHC_HostVolume WHERE HostID = @HostID
DELETE FROM tbl_WLC_PhysicalObject WHERE HostId = @HostID
DELETE FROM tbl_ADHC_Host WHERE HostClusterID = @HostID
DELETE FROM tbl_ADHC_HostDisk WHERE HostID = @HostID
DELETE FROM tbl_ADHC_ClusterDisk WHERE OwnerHostID = @HostID
DELETE FROM tbl_ADHC_VmwResourcePool WHERE HostID = @HostID
DELETE FROM tbl_ADHC_VmwResourcePool WHERE HostClusterID = @ClusterID
DELETE FROM tbl_ADHC_ClusterDisk WHERE ClusterID = @ClusterID
delete from tbl_NetMan_HostNetworkAdapterToLogicalNetwork where HostNetworkAdapterID = (select HostNetworkAdapterID
from tbl_NetMan_HostNetworkAdapterToLogicalNetwork as nic2net, tbl_ADHC_HostNetworkAdapter as nic
where nic.HostID  = @HostID and nic2net.HostNetworkAdapterID = nic.NetworkAdapterID)
DELETE FROM tbl_ADHC_HostNetworkAdapter WHERE HostID  = @HostID
delete FROM tbl_ADHC_VirtualNetwork WHERE HostID = @HostID
delete from tbl_ADHC_ISCSIHbaToTargetMapping where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete from tbl_ADHC_ISCSIHbaToPortalMapping where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete from tbl_ADHC_HostInternetSCSIHba where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID
delete FROM tbl_NetMan_InstalledVirtualSwitchExtension WHERE HostID = @HostID
DELETE FROM tbl_ADHC_Host WHERE HostID = @HostID
DELETE FROM tbl_ADHC_HostCluster WHERE ClusterID = @ClusterID

image

After running this script your cluster should be removed from VMM.

--- Updated 18.04.2017

To remove a stuck host object only (without the cluster) I narrowed down the commands to this (just replace the yellow hostname):

DECLARE @HostID GUID
SELECT @HostID = HostID FROM dbo.tbl_ADHC_Host where ComputerName = 'host.domain.local'
DELETE FROM tbl_WLC_VObject                                          WHERE HostId = @HostID
DELETE FROM tbl_WLC_PhysicalObject                                   WHERE HostId = @HostID
DELETE FROM tbl_ADHC_HostVolume                                      WHERE HostID = @HostID
DELETE FROM tbl_ADHC_HostDisk                                        WHERE HostID = @HostID
DELETE FROM tbl_ADHC_ClusterDisk                                WHERE OwnerHostID = @HostID
DELETE FROM tbl_ADHC_VmwResourcePool                                 WHERE HostID = @HostID
delete from tbl_NetMan_HostNetworkAdapterToLogicalNetwork where HostNetworkAdapterID = (select HostNetworkAdapterID
from tbl_NetMan_HostNetworkAdapterToLogicalNetwork as nic2net, tbl_ADHC_HostNetworkAdapter as nic
where nic.HostID = @HostID and nic2net.HostNetworkAdapterID = nic.NetworkAdapterID)
DELETE FROM tbl_ADHC_HostNetworkAdapter                              WHERE HostID = @HostID
delete FROM tbl_ADHC_VirtualNetwork                                  WHERE HostID = @HostID
delete from tbl_ADHC_ISCSIHbaToTargetMapping where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete from tbl_ADHC_ISCSIHbaToPortalMapping where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete from tbl_ADHC_HostInternetSCSIHba where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete FROM tbl_ADHC_HostBusAdapter                                  WHERE HostID = @HostID
delete FROM tbl_NetMan_InstalledVirtualSwitchExtension               WHERE HostID = @HostID
delete FROM tbl_ADHC_HostToProcessorCompatibilityVectorMapping       WHERE HostID = @HostID
DELETE FROM tbl_ADHC_Host                                            WHERE HostID = @HostID

After running the commands I was able to normally remove the host object right in VMM console.

--- Updated 06.05.2022

Powershell version:

$srv = 'sqlservername'
$vmhost = 'fqdn.of.host.to.be.deleted'
Import-Module SQLPS -PSSession (New-PSSession $srv)
$query = "SELECT HostID FROM dbo.tbl_ADHC_Host WHERE ComputerName = '$vmhost'"
$HostID = (Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB).HostID.Guid

$query = "DELETE FROM tbl_WLC_VObject WHERE HostId = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

$query = "DELETE FROM tbl_WLC_PhysicalObject WHERE HostId = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

$query = "DELETE FROM tbl_ADHC_HostVolume WHERE HostId = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

$query = "DELETE FROM tbl_ADHC_HostDisk WHERE HostId = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

$query = "DELETE FROM tbl_ADHC_ClusterDisk WHERE OwnerHostID = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

$query = "DELETE FROM tbl_ADHC_VmwResourcePool WHERE HostId = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

$query = "
    SELECT
        HostNetworkAdapterID
    FROM
        tbl_NetMan_HostNetworkAdapterToLogicalNetwork AS nic2net,
        tbl_ADHC_HostNetworkAdapter AS nic
    WHERE
        nic.HostID = '$HostID'
        AND nic2net.HostNetworkAdapterID = nic.NetworkAdapterID
"
$nics = (Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB).HostNetworkAdapterID.Guid
foreach ($nic in $nics) {
    $query = "DELETE FROM tbl_NetMan_HostNetworkAdapterToLogicalNetwork WHERE HostNetworkAdapterID = '$nic'"
    Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB
}

$query = "DELETE FROM tbl_ADHC_HostNetworkAdapter WHERE HostId = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

$query = "DELETE FROM tbl_ADHC_VirtualNetwork WHERE HostId = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

$query = "SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = '$HostID'"
$hbaids = (Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB).hbaid.Guid
foreach ($hbaid in $hbaids) {
    $query = "DELETE FROM tbl_ADHC_ISCSIHbaToTargetMapping WHERE ISCSIHbaID = '$hbaid'"
    Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

    $query = "DELETE FROM tbl_ADHC_ISCSIHbaToPortalMapping WHERE ISCSIHbaID = '$hbaid'"
    Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

    $query = "DELETE FROM tbl_ADHC_HostInternetSCSIHba WHERE ISCSIHbaID = '$hbaid'"
    Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB
}

$query = "DELETE FROM tbl_ADHC_HostBusAdapter WHERE HostId = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

$query = "DELETE FROM tbl_NetMan_InstalledVirtualSwitchExtension WHERE HostId = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

$query = "DELETE FROM tbl_ADHC_HostToProcessorCompatibilityVectorMapping WHERE HostId = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

$query = "DELETE FROM tbl_ADHC_Host WHERE HostId = '$HostID'"
Invoke-Sqlcmd $query -ServerInstance talvmmsql2 -Database VirtualManagerDB

30 May 2013

Analyze MSSQL database table sizes

On a previous article (http://raunomagi.blogspot.com/2013/01/shrink-all-databases-on-microsoft-sql.html) I showed, how to reduce the sizes of database and log files. But, what if your database size is still too large. Then you need to inspect your Microsoft SQL Server database(s) using the following SQL query (having selected the database to be inspected as default):

SELECT t.name, SUM(a.total_pages) * 8192 AS TotalSpace
FROM sys.tables t, sys.partitions p, sys.allocation_units a
WHERE t.OBJECT_ID = p.OBJECT_ID AND p.partition_id = a.container_id
GROUP BY t.name
ORDER BY TotalSpace desc

This query was inspired from this page (http://stackoverflow.com/questions/7892334/get-size-of-all-tables-in-database), but I modified the script and removed some unnecessary references and reverse ordered the output using the TotalSpace column. So in the output you see the most heavily used tables first:

image

24 May 2013

How to change/assign/update certificates in Exchange Server 2010

First you need to obtain a certificate from CA. This varies from provider to provider. I manage certificates using Server Certificates section in Internet Information Services (IIS) Manager:

image

On the right hand pane of Server Certificates you will see commands for importing or requesting the certificate. You can use them for internal or external CA’s.

image

If you need to create multi-name certificate (SAN or Subject Alternative Name) please use Exchange Management Shell:

New-ExchangeCertificate -GenerateRequest -KeySize 2048 -SubjectName "c=ee, s=Harjumaa, l=Tallinn, o=YourCompany, ou=IT, cn=mail.yourdomainname.com" -DomainName mail.yourdomainname.com, autodiscover.yourdomainname.com -PrivateKeyExportable $True -FriendlyName "mail.yourdomainname.com"

After equal signs (=) you should have: your country code, state, city, organization, OU and common name. Common name is the default name for the certificate (for example mail.yourdomainname.com). The domainname switch is for SAN names (alternative names, like autodiscover.yourdomain.com etc) separated by comma. SAN should include always the common name. FriendlyName is for identifying certificates (for example two certificates with same common name but different expiration date).

This command gives you the certificate request. You should copy and paste it into CA's web form to request a certificate. When you get back the certificate from CA, then you should complete the request by using Internet Information Services (IIS) Manager.

On Windows 2008 based CA you might get the error:

The request contains no certificate template information. 0x80094801 (-2146875391)
Denied by Policy Module  0x80094801,….

image

Then you will need to use command line to submit the request to CA:

certreq -submit -attrib "CertificateTemplate: WebServer" WebServerCertReq.txt

where the file name in the end of command line contains the output of New-ExchangeCertificate command.


OK. Let’s assume, you managed to create a new certificate.

To list all installed certificates, use Exchange Management Shell:

get-exchangecertificate | ft thumbprint,servicesstringform,friendlyname -a

image

Remember the thumbprint of your new certificate and enter following 4 commands to assign those certificates to 4 protocols (IMAP, POP, SMTP and HTTP).

Enable-ExchangeCertificate thumbprint -Services imap
Enable-ExchangeCertificate thumbprint -Services pop
Enable-ExchangeCertificate thumbprint -Services smtp
Enable-ExchangeCertificate thumbprint -Services iis

Replace the string “thumbprint” with the actual thumbprint from previous get-exchangecertificate command.

Restart POP and IMAP services and do a IISRESET using following commands in powershell as administrator:

get-service *pop3,*imap4 | restart-service
iisreset

image

If you have CAS array, you should do almost the same procedure on other CAS array members, with the exception, that you don’t need to request new certificate. You must export the existing certificate from first CAS member and import it to other servers.

09 April 2013

DPM error “Failed to backup as another backup using the same CSV is in progress.”

DPM 2010/2012 is quite resilient backup software. It tries failed backups after 1 hour again. But it does it only once. Sometimes I still have error messages like:

Failed to prepare a Cluster Shared Volume (CSV) for backup as another backup using the same CSV is in progress. (ID 32612 Details: Back up is in progress. Please wait for backup completion before trying this operation again (0x8007173D))

image

This happens on hyper-v clusters with shared storage. Of course you can run into other type of error messages. To increase the retry count change AutoRerunNumberOfAttempts registry key to a bigger value using following command:

reg add "HKLM\Software\Microsoft\Microsoft Data Protection Manager\Configuration" /v AutoRerunNumberOfAttempts /t REG_DWORD /d 2

image

The “/d 2” part specifies the rerun attempts count. I will try with 2 retries and see, whether it gives me less errors to fix on daytime.

To see other registry options see this URL http://blogs.technet.com/b/dpm/archive/2011/06/06/how-to-use-and-troubleshoot-the-auto-heal-features-in-dpm-2010.aspx

08 April 2013

How to get rid of multiple Messenger contacts with name “Q” in Skype desktop application

When you are an enthusiastic updater of Skype, then you might stuck in a situation, where you have a lot of contacts with the name Q in Skype:

image

When I log in from an another Messenger client (for example ebuddy.com), then contact are with normal names.

To get rid of this use following steps:

  1. Close Skype from GUI or hit Win+R and type “tskill skype”.
  2. Delete Skype user specific profile by hitting Win+R (Start, Run…), type %appdata% and press Enter. From the C:\Users\XXXX\AppData\Roaming\ folder remove or rename the folder with name Skype.
  3. Start Skype again and log on with live account.

Of course you will lose all settings (font size, status notifications, automatic save location for received files, privacy settings etc).

04 April 2013

How to send e-mail manually using Telnet.exe or PowerShell

Let’s say, you want to send an e-mail to someone@hotmail.com. Then you need to act like a e-mail server.

First of all you need to know which servers serve the e-mail domain (the part after the @ sign). It’s done by using MX records on DNS servers. In our case the domain is hotmail.com. To get the MX records use this command:

nslookup -q=mx hotmail.com 8.8.8.8

image

The host 8.8.8.8 is good address for external DNS lookups, “hotmail.com” is the domain name and “-q=mx” says nslookup to request only MX records.

The answer section contains several MX records. If you get 0 results, then you cannot proceed (maybe there is a typo in domain name or you don’t have UDP 53 port open to DNS server or something else). Smaller MX preferences mean higher priority. E-mail servers try lower value servers first and if unsuccessful, then use higher value MX records to send e-mails.

Next you need to start “telnet mx1.hotmail.com 25” (you can use any server of those 4 MX records because they all are same priority). When the connection succeeds, type following commands:

helo
mail from:senders@address.com
rcpt to:someone@hotmail.com
data
subject: test

whatever
.
quit

image

After each line press Enter. Don’t use backspace, because Windows’ telnet.exe doesn’t transmit data at the end of a line, but each character individually. If you fail, press Enter and type the line again (use putty.exe if you need to use backspace).

HELO command needs sometimes the “hostname” after the HELO word separated by space. You can type anything in this place, but some anti-spam measures might want you to use some real name (you can use http://myip.eu to figure out the right hostname to use on your computer).

MAIL and RCPT commands require sometimes e-mail addresses to be inside angle brackets <>. DATA command starts actual e-mail content. You can use just Subject part in the header. Empty line is needed between the header and message body section. Message body will end with a line with a dot (.) as the only character on the line.

If you need to test same stuff more often, then you probably use PowerShell to send the message (instead of Telnet). The command line is pretty simple:

Send-MailMessage -SmtpServer mx1.hotmail.com -To someone@hotmail.com -From senders@address.com -Subject "test" -Body "whatever"

image

20 March 2013

Cloned computer missing from WSUS

When you count your computers in Active Directory and compare it to computers in Windows Server Update Services, you probably see a difference. In my case I saw several computers missing in WSUS. After investigating, I realized that those computers were cloned.

In administrative PowerShell window on WSUS server computer I checked, that the computer really doesn’t exist:

Get-WsusComputer –NameIncludes PartOfYourComputerName | ft -a

image

Actually you don’t need to sysprep those working systems. All you need is following four lines (in web browser they will wrap to a little more lines) running in administrative command prompt on WSUS client computer:

net stop wuauserv
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v SusClientId /f
wuauclt /resetauthorization /detectnow
wuauclt /reportnow

And almost instantly you can see this computer appear on WSUS management:

image

19 March 2013

Outlook 2013 one year limit for item searching

If you are used to Outlook 2010 searching experience, then the first thing you notice in Outlook 2013 is, that the search gives you only up to 1 year old results with the text “Showing recent results…”. When you click “More”, then older stuff will be searched from Exchange Server. Actually full timeframe search will be carried out and local cache is not used.

image

So we used local computer power to search something and then again Exchange Server resources to search again. It seems a wasteful way to search things.

This search limit is there because Outlook 2013 stores only 1 year old items in local copy of the mailbox (.OST file). Luckily this behavior can be customized in mail profile. Following procedures are with keyboard shortcuts. If you find some of them useful, you can leave a comment on this blog entry.

  1. Open Control Panel (Press Win+R, type “control”, press Enter)
    image
  2. In the search box type “mail” (in Windows 8 the cursor is automatically in search box), wait for search results to appear, then hit TAB so that the Mail icon text is highlighted and press Enter.
    image
  3. Mail Setup windows appears. Press Enter or Space to press the selected “E-mail Accounts…” button.
    image
  4. In Account Settings window press ALT+A to press the “Change…” button
    image
  5. Move the slider from 12 months to the rightmost option “All”. Hit 3 times TAB and press END.
    imageimage
  6. Close all opened windows. Press 2 times Enter (Next and Finish) and then 3 times ALT+F4 (Closes active window).

Close and open Outlook. Wait for entire mailbox to be synchronized and enjoy fast local search. And you can search everything offline too.

11 March 2013

System Center Virtual Machine Manager 2012 SP1

When you install System Center Virtual Machine Manager 2012 SP1 on your administrative Windows 8 workstation, you will get the following error message:

Console Add-ins Warnings and Errors
The following warnings and error were encountered while loading console add-ins.

Could not update managed code add-in pipeline due to the following error:

Access to the path 'C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\Bin\AddInPipeline\PipelineSegments.store' is denied

image

When you start your console as administrator, you don’t receive the error message.

Easiest thing to do is to open the following folder in windows explorer:

C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\Bin\AddInPipeline

image

You will get the prompt about not having permissions on that folder. Press Continue.

image

And voila! Your “Virtual Machine Manager Console” will open after that trick without any errors.

24 January 2013

mechita - Remote Desktop application written in C#

If you have 2 or more Windows Servers in your domain, then using Remote Desktop Connection for administering a lot of servers is probably a bit frustrating.

image

That’s why I wrote my own application for easy management of all Windows Servers. The application can be downloaded from http://bit.ly/WWwuGp. It uses .NET Framework 4.0, so you need to install this also if not already installed.

It loads all computer accounts, where operating system contains the word “server” and list them in the list, so you can with one click log on to any server.

image

If your logged on user account is not the account for administering the server, you should use “Run as different user…” for launching the .exe file.

If you would like to save your password for even faster logging, check the password check-box and type your password in pop-up window and press OK. It will be saved to registry for local user [HKCU\Software\mechita] so other users of your computer will not see it (unless they have administrative rights). Clearing the password check box removes the entry from registry.

image

Console check box allows to log on to console session (equivalent to mstsc /console or mstsc /admin). For example Windows Server 2003 desktop session would be a possible use of that. Or server, where terminal licensing is not activated and the trial time is over.

“X servers in domain” text shows, how many server computer accounts are in AD. By clicking that text (yes, I know that’s not a intuitive approach), the servers list will be updated along with the computer count (for example if you have discovered, that you have an old server account and you deleted that account from AD).

“Close session” button closes the active tab and disconnects from that server.

For going into full screen, press Ctrl+Alt+Pause. The same key combination is also used for returning from full screen mode.

I hope you like this application. any suggestions for improvements are welcome. Put them in comment area.

Ideas so far:

  1. Favorite servers list or most recently used servers list
  2. Reconnect connection in active tab page
  3. Resize application window should resize terminal session also
  4. Server’s list should be cached
  5. Remote Desktop Gateway should be configurable (in conjunction with servers list cache this could be awesome). At the moment no RDP Gateway is used.

Shrink all databases on a Microsoft SQL Server instance

When disk free space on your Windows Server goes below your threshold and you discover, that your MSSQL installations DATA directory is the biggest one with lot’s of large log files (.LDF extension), then this solution is for you.

This very simple command:

EXEC sp_MSForEachDB 'select ''?'' as [Database]; ALTER DATABASE [?] SET RECOVERY SIMPLE; DBCC SHRINKDATABASE (''?'' , 0)'

get’s all databases, and for each:

  1. Displays the database name
  2. Changes database recovery model to Simple (Important! Read this information http://technet.microsoft.com/en-us/library/ms189275.aspx for implications when changing Recovery Model)
  3. Shrinks all database files, leaving 0% free space inside database and log files

This SQL Management Studio screenshot shows the output of the command:

image

In my case 14GB DATA directory was reduced to 2GB. Impressive.

22 January 2013

Easily schedule deletion of older files in a particular folder

In a previous post http://raunomagi.blogspot.com/2012/05/how-to-delete-files-older-than-x-days.html I revealed how to delete older files, but some folder keep growing up and need regular cleaning.

Let’s assume, that the folder, that is growing is IIS web logging in folder C:\inetpub\logs\LogFiles\W3SVC1 (this can be any folder, but to make it more realistic I use this one). To check, how big this folder is right now, use this PowerShell command:

dir C:\inetpub\logs\LogFiles\W3SVC1 | measure -sum length

image

It’s not easily readable, but I see 150 files using 29GB of disk space.

For scheduled deletion you need only few lines to paste into administrative command prompt:

  1. echo forfiles /d -50 /p C:\inetpub\logs\LogFiles\W3SVC1 /c "cmd /c del @path" > %windir%\DeleteOldFiles.bat
  2. schtasks /create /RU:"" /SC:DAILY /TR "'%windir%\DeleteOldFiles.bat'" /ST:01:00 /RL:HIGHEST /TN:DeleteOldFiles
  3. schtasks /run /TN:DeleteOldFiles

image

Line 1 creates a file in Windows directory named DeleteOldFiles.bat. If your directory is somewhere else, change it accordingly. If the path to the folder includes spaces, surround it with quotation marks. The .BAT file looks like this:

image

Line 2 creates a scheduled task for running the .BAT file under SYSTEM account daily at 01:00. The task can be modified later on Task Scheduler:

image

Line 3 run’s the scheduled task right away.

After running the task I returned to my PowerShell window and rechecked the result:

image

So it seems, like I got almost 20GB of free space Smile

04 January 2013

How to enable Active Directory Recycle Bin and restore deleted objects (users, groups etc)

In Windows Server 2003 and Windows Server 2008 the best option to restore a deleted user account was the command line utility adrestore.exe from http://live.sysinternals.com/ website. The restore option worked fairly well. It will keep the same security ID (SID) and logon name so user can log on to same profile on Windows. Side-effect is lost password, phone number, group membership etc. And the account is in disabled state, so you need to enable the acoount and assign a new password.

Since Windows Server 2008 R2 you have the option to enable the Active Directory Recycle Bin. For that you need:

  1. All domain controllers must be Windows Server 2008 R2 (or later). So remove older ones by running dcpromo wizard on them. And if you don’t have W2008R2 domain controller, install one first.
  2. Forest and domain functional levels must be Windows Server 2008 R2. To change it, use domain.msc (Active Directory Domains and Trusts). Remember, that this change is irreversible. And be sure that you don’t have older domain controllers.
    imageimage
  3. AD Recycle Bin must be activated by using the following PowerShell command:
    Enable-ADOptionalFeature -Identity 'CN=Recycle Bin Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=contoso,DC=com' -Scope ForestOrConfigurationSet -Target 'contoso.com'
    You must type your domain name instead of contoso.com.
  4. Delete a sample user account using your favorite tool. For example “net user test /delete /domain
  5. Restore can be easily done using PowerShell commands.
    1. First you need to find the affected object:
      Get-ADObject -Filter {name -like "*PhraseFromUsername*" -and deleted -eq $true} -IncludeDeletedObjects
    2. Make sure your result includes only the deleted account and use the same command and pipe it to Restore-ADObject cmdlet:
      Get-ADObject -Filter {name -like "*PhraseFromUsername*" -and deleted -eq $true} –IncludeDeletedObjects | Restore-ADObject

And now you can use this user account (password is kept, username, group membership etc. will be retained).

For more information please visit http://technet.microsoft.com/en-us/library/dd392261(WS.10).aspx