19 April 2012

Extended Windows Volume

Extending Volume on virtualized Windows server is so easy this days. You just go to your virtual host server and extend virtual disk. After this is done login to your Windows server and open Disk Management then right-click Disk Management and select Refresh.


After this you'll see some Unallocated space.


Now right-click on Volume that you want to extend (in-front of unallocated space) and select Extend Volume ...


Extend Volume Wizard opens and by clicking Next you'll arrive to the part where you need to specify for how much you'll extend selected Volume. In my case I'll use all available space.


Click Next and Finish. After this your Volume will be extended and you'll have additional space on your server that you can use :)


But it's not always that easy. Sometimes can happen that you'll get an error: "The parameter is incorrect."



After that Disk Management shows different size of extended disk as if you check disk properties.



Solution for this problem is simple. Open Command Line (CMD) as Administrator and type DISKPART.

Diskpart
List Volume
Select Volume # (this is the number of the volume listed by the above ‘List Volume’ command)
Extend Filesystem
Exit


All good and now you can recheck disk properties for just in case.


Disk properties also show that disk was successfully extended :)

Few useful links:
http://support.microsoft.com/kb/325590
http://www.jonathanmedd.net/2010/10/windows-server-2008-extend-system-volume-error-the-parameter-is-incorrect.html

This is it for today. Have fun!

02 March 2012

Blocking P2P programs with Group Policy

Some time ago I needed to block as many as possible torrent and other P2P clients with Windows Group Policy. To do this I needed to find as many as possible names of torrent clients executables and prepare a list. The result of all this is this list:

ABC.exe
Ares.exe
Azerues.exe
BitComet.exe
BitLord.exe
BitThief.exe
BitTornado.exe
BitTorrent.exe
Btdownloadgui.exe
Deluge.exe
Emule.exe
Fdm.exe
FlashGet.exe
Giftl.exe
Imesh.exe
KGet.exe
KTorrent.exe
LimeWire.exe
Mediaget.exe
Miro.exe
MLDonkey.exe
Mp3rocket.exe
Msohtmed.exe
µTorrent.exe
Utorrent-2-0-beta.exe
Utorrentportable.exe
OneSwarm.exe
Opera.exe
qBittorrent.exe
Shareaza.exe
Tonido.exe
Swapper.exe
Tribler.exe
Vuze.exe
Wyzo.exe


I hope you'll find this list useful and I'd also like to invite all of you to post me names of the executables that I missed. This way we'll keep this list up-to-date :)

Here are two articles that describe how to block applications with Windows Group Policy:
http://www.technipages.com/prevent-users-from-running-certain-programs.html
http://www.windowsnetworking.com/articles_tutorials/Software-Restriction-Policies.html

This is it for today. Have fun!

28 December 2011

Remove Receive Connector permissions

Few days ago I started playing with permissions on our Exchange 2010 Receive Connector. I wanted to achieve that one of my service accounts users could send emails. During this testing I added all sorts of permissions to this Receive Connector. After I finished testing I wanted to get rid of all permissions I gave to this user. And how did I do it?

First I wanted to see all permissions that I gave to this user:

Get-ReceiveConnector "Server\Full Connector Name" | Get-ADPermission -User "Domain\Username"  |? {$_.extendedrights} | select identity,user,extendedrights | Format-List

Second I got rid of all permissions that I got from previous command:

Get-ReceiveConnector "Server\Full Connector Name" | Remove-ADPermission -User "Domain\Username" -ExtendedRights ms-Exch-SMTP-Accept-Any-Recipient,ms-Exch-SMTP-Accept-Authoritative-Domain-Sender,ms-Exch-Accept-Headers-Routing,ms-Exch-SMTP-Accept-Any-Sender

At the end I run first command set again just to check if I really got rid of everything.

I hope this will help you clean up your Exchange server as it helped me.

This is it for this year. Have fun!

17 October 2011

Change Internet Explorer default save location

I’m sure some of you are interested how to change default save location in Internet Explorer (IE) because I know I was as soon as I started using it.
Until now I found two ways how to do this.

1. Users friendly version:- Open Internet Explorer and press Ctrl+J (I love shortcuts don’t you) to open View Downloads window.

- At the lower left corner find Options and click it.

- Choose folder by clicking on Browse and selecting new default Save folder of your choice.

- Confirm changes by clicking OK few times.

2. Advanced users version:- Open Windows Registry Editor (regedit.exe)
- Browse to HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main

- Find String “Default Download Directory” and Modify it.
- Enter new default Save folder location. For example: c:\temp
- Exit Windows Registry Editor

Now you can just press Save button in IE and items will be saved to new location without the need of selecting Save As all the time :)

This is it for today. Have fun!

11 August 2011

Window7 SP1 and group policy exception for RDP on clients firewalls

I’ve been struggling with annoying problem on one of my virtual test machines running Windows 7 SP1. One of them suddenly decided that I can’t log on to it using Remote Desktop Services (RDP).

I know that I created group policy (GPO) exception to allow Remote Desktop connections for all my PC’s from LAN and VPN. For configuring I used this link.

I also know that it worked just fine not long ago. So I checked it and it seemed OK.

Group policy for Remote Desktop exceptions:

 
 
 
 
 
 
 
 

Group policy exceptions:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

I did some Googling and found similar problem which lead me to solution. It seems that the problem was in Windows 7 SP1.
 
And finally the recipe for solution:
Solution was that I just needed to open for editing GPO that controlled RDP on computer running Windows 7 SP1 or on Windows 2008 R2 server with SP1. After I did that and run “gpupdate /force” on problematic PC I could finally connect to it using RDP.

This is it for today. Have fun!

31 July 2011

Backing up all MS SQL databases

Today I got a task to backup all databases on our Microsoft SQL 2005 running on Windows 2008. The solution also needed to satisfy two conditions:
- must always backup all databases even if we add new one's
- must remove backup files older than 3 days

So I started Googling for solutions. At the end I combined different solutions into script below. This script can be used on Windows server 2003 and 2008 with MS SQL 2005 and 2008 with slight difference in one line:

SQL 2008:
sqlcmd -E -S "%ServerName%" -h-1 -W -Q "SET NoCount ON;SELECT NAME FROM sys.sysdatabases WHERE [Name] NOT IN ('master','model','msdb','tempdb')" > %DBList%

SQL 2005
sqlcmd -E -S "%ServerName%" -h-1 -W -Q "SET NoCount ON;SELECT NAME FROM master.dbo.sysDatabases WHERE [Name] NOT IN ('master','model','msdb','tempdb')" > %DBList%

And what this script does?
- Gets system date for later use in backup file names.
- Saves names of all databases in temporary file.
- Removes backup files older than 3 days.
- Backup each database, prepending the server name and date to the filename.
- Clean up the temp file.
Warning: Text marked as this should be customized according to your specifications!

***************************************************

REM @ECHO OFF
SETLOCAL


REM: get computer name ad write it into variable
set ServerName=%computername%


REM: Get System Date to be used for DB backup file namesSETLOCAL ENABLEEXTENSIONS
if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
for /f "tokens=2-4 delims=(-)" %%a in ('echo:^|date') do (
for /f "tokens=%toks% delims=.-/ " %%i in ('date/t') do (
 set '%%a'=%%i
 set '%%b'=%%j
 set '%%c'=%%k))
if %'yy'% LSS 100 set 'yy'=20%'yy'%
set Today=%'yy'%-%'mm'%-%'dd'%
ENDLOCAL & SET v_year=%'yy'%& SET v_month=%'mm'%& SET v_day=%'dd'%


REM Build a list of databases to backup
SET DBList=C:\BackupSQL\SQLDBList.txt
echo %DBList%
sqlcmd -E -S "%ServerName%" -h-1 -W -Q "SET NoCount ON;SELECT NAME FROM sys.sysdatabases WHERE [Name] NOT IN ('master','model','msdb','tempdb')" > %DBList%


REM Remove backup files older than 3 days
REM /d -3 defines how old must be files before they are deleted
IF EXIST "%DBList%" forfiles /p C:\BackupSQL /s /m * /d -3 /c "cmd /c del @file"


REM Backup each database, prepending the servername and date to the filename
FOR /F "tokens=*" %%I IN (%DBList%) DO (
ECHO Backing up database: %%I
SqlCmd -E -S "%ServerName%" -Q "BACKUP DATABASE [%%I] TO Disk='C:\BackupSQL\Backup_%ServerName%_%v_year%_%v_month%_%v_day%_%%I.bak'"
ECHO
)


REM Clean up the temp file
IF EXIST "%DBList%" DEL /F /Q "%DBList%"

ENDLOCAL

***************************************************

Now just copy/paste this script into BackupSQL.bat file and run it from Scheduled Tasks.

I also suggest to all that they test restore of their databases because you never know if it's OK until you try :)

This is it for today. Have fun!

17 June 2011

Useful Command prompt (CMD) and PowerShell commands

This time I’ll make it short. In this blog I’ll start collecting useful Command prompt and PowerShell commands that I frequently use. Commands are inside the quotes:

Command prompt:

Did you ever search what is the username of the currently logged in user? Here is an answer:
Windows XP: “echo %username%
Windows 7: “whoami” or “echo %username%

And command that shows computer name:
Windows XP, 7, 2003, 2008: “hostname


************************************************
On the file server you need a list of all opened files:
net file
net file < .\desktop\openfiles.txt if the list is too long and doesn’t fit into command prompt window.
net file | find "Search string"
filter results by specified search string.


************************************************
Get a list of all drivers installed to Windows computer:
driverquery


************************************************Display user logon server (domain controller) in command line:
set
echo %logonserver%


************************************************
This tool displays operating system configuration information for a local or remote machine, including service pack levels, original install date, system boot time, total physical memory, available physical memory, page file max size, page file available, page file in use and much more:
"systeminfo"


************************************************
Get a list of all roles applied to Windows 2008 server:
servermanagercmd -q


************************************************
Detecting memory leaks:
Create memory snapshots into a file, if you run this command repeatedly new memory snapshots will be added to the end of the file:
"memsnap /m memsnap.log"
Analyze memory snapshots for memory leaks:
"memsnap /ah memsnap.log"


 
************************************************
This tool enables an administrator to display the MAC address for network adapters on a system:
"getmac /v"



************************************************
Group Policy Results (GPResult.exe) is a command line tool that displays Group Policy Settings that are in effect for a specific user or computer.
"gpresult /s ComputerName /user UserName /r /v > gpresult_filename.txt"


************************************************
Display / list Active directory FSMO (Flexible Single Master Operations) roles. Run this command on domain controller:
netdom query fsmo




************************************************
Get a list of group members from AD:
dsget group "CN=Domain Admins,CN=Users,DC=domain,DC=local" –members


************************************************
Get a list of disabled user accounts from AD:
DSQUERY USER -disabled


************************************************
Get a list of inactive user accounts from AD (in weeks):
DSQUERY USER -inactive 4


************************************************
Get a list of inactive computer accounts from AD (in weeks):
DSQUERY computer -inactive 4



************************************************
Get a list of all computer accounts and servers from AD (name and OS):
dsquery * -filter "(&(objectClass=Computer)(objectCategory=Computer))" -attr sAMAccountName operatingSystem -limit 1000


************************************************
Get AD schema version. Run this command on domain controller:
dsquery * cn=schema,cn=configuaration,dc=domain,dc=local -scope base -attr objectVersion


************************************************
Klist is a command line utility included in the default installation of Windows Server 2008 and Windows Server 2008 R2 which can be used to list and purge Kerberos tickets on a given computer. To run KLIST, open a command prompt in Windows Server 2008 and type Klist:
klist tickets


************************************************
Get Exchange schema version:
dsquery * CN=ms-Exch-Schema-Version-Pt,cn=schema,cn=configuration,dc=domain,dc=local -scope base -attr rangeUpper



************************************************
Get a list of Service Principal Name (SPN) for specified server:
setspn -l ServerName


************************************************
Get AD site information for computer on which you're running this command:
Nltest.exe /dsgetsite


************************************************
Get DFS server list for computer on which you're running this command:
dfsutil /pktinfo


This is it for today. Have fun!