Showing posts with label microsoft. Show all posts
Showing posts with label microsoft. Show all posts

Thursday, 26 May 2011

Automate the installation of Active Directory tools with PowerShell

Import-Module Servermanager
Get-WindowsFeature
Add-WindowsFeature RSAT-DNS-Server -restartAdd-WindowsFeature RSAT-ADDS-Tools -restart
Add-WindowsFeature RSAT-AD-AdminCenter -restart
Add-WindowsFeature RSAT-SNIS -restart

Note: These features require Windows to be restarted, so be advised that Windows may restart without prompting when passing the command to add these features in through PowerShell.

Saturday, 14 May 2011

SQL 2008 database Backup and Restore process

Method:
1.Full
2.Differential
3.Transaction Log
4.File and File group backup

Data critical situation level is high. We could use the backup pattern below:
Sun Mon Tue Web Thu Fri Sat
F D D D D D D
T T T T T T
F: weekly Sunday
D: daily Mon, Tue, Web, Thu, Fri, Sat
T: per office hour

Create a backup device
w/ management studio
Server object -> New backup device -> File -> input the name and the location of the backup file

w/ store procedure
use master
exec sp_addumpdevice 'disk', 'MYDATA', 'c:\backup\mydata.bak' //create
exec sp_dropdevice 'disk', 'c:\backup\mydata.bak' //delete
go

Create a backup task
w/ management studio
Server object -> backup database

Setting schedule backup
1.start the sql server agent
start -> all programs -> microsoft sql server 2008 -> configuration tools -> sql server configuration manager -> find 'sql server agent' service
-> start
-> properties -> start method -> automatic

2.start agent xps option
sp_configure 'show advanced options',

go
reconfigure
go
sp_configure 'Agent XPs', 1
go
reconfigure
go

3. create schedule task for automatic backup
w/ management studio
Manage -> Maintenance plan -> maintenance plan wizard -> next -> name 'weekly full', schedule 'change' -> setup the date you need to do the full backup -> choose backup method 'full' -> next -> choose the database you need to backup, check verify backup integrity -> finish.

w/ T-sql
backup database AdventureWorks
to mybackup
with stats = 20

with options
blocksize = if you need to burn the file on a CD, set to 2048, use with format
name = backup set name
description = set backup description
differential: do the differential only, if not set this parameter, full as default
format | no format: set if overwrite the existing backup
compression | no_compression: if need to compress the backup or not, not set as system default value
nounload | unload: set when backup is finished, need to unload the tape or not
restart: if there is a power failure when doing backup, set this option to restart the backup job
stats: sql server is 10% by default, view the backup process percentage frequency

Wednesday, 11 May 2011

讓 Windows 7、Vista 登入畫面不顯示帳號名稱

「HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System」 中的 「DontDisplayLastName」,將它由「0」改為「1」即可。

Thursday, 31 March 2011

Basic Windows PowerShell commands you should already know

1: Get-Help


The first PowerShell cmdlet every administrator should learn is Get-Help. You can use this command to get help with any other command. For example, if you want to know how the Get-Process command works, you can type:


Get-Help -Name Get-Process

and Windows will display the full-command syntax.


You can also use Get-Help with individual nouns and verbs. For example, to find out all the commands you can use with the Get verb, type:



Get-Help -Name Get-*

2: Set-ExecutionPolicy


Although you can create and execute PowerShell scripts, Microsoft has disabled scripting by default in an effort to prevent malicious code from executing in a PowerShell environment. You can use the Set-ExecutionPolicy command to control the level of security surrounding PowerShell scripts. Four levels of security are available to you:


  • Restricted — Restricted is the default execution policy and locks PowerShell down so that commands can be entered only interactively. PowerShell scripts are not allowed to run.

  • All Signed — If the execution policy is set to All Signed then scripts will be allowed to run, but only if they are signed by a trusted publisher.

  • Remote Signed — If the execution policy is set to Remote Signed, any PowerShell scripts that have been locally created will be allowed to run. Scripts created remotely are allowed to run only if they are signed by a trusted publisher.


  • Unrestricted — As the name implies, Unrestricted removes all restrictions from the execution policy.


You can set an execution policy by entering the Set-ExecutionPolicy command followed by the name of the policy. For example, if you wanted to allow scripts to run in an unrestricted manner you could type:

Set-ExecutionPolicy Unrestricted

3: Get-ExecutionPolicy


If you’re working on an unfamiliar server, you’ll need to know what execution policy is in use before you attempt to run a script. You can find out by using the Get-ExecutionPolicy command.


4: Get-Service



The Get-Service command provides a list of all the services that are installed on the system. If you are interested in a specific service, you can append the -Name switch and the name of the service (wildcards are permitted). When you do, Windows will show you the service’s state.


5: ConvertTo-HTML


PowerShell can provide a wealth of information about the system, but sometimes you need to do more than just view the information onscreen. Sometimes, it’s helpful to create a report you can send to someone. One way of accomplishing this is by using the ConvertTo-HTML command.


To use this command, simply pipe the output from another command into the ConvertTo-HTML command. You will have to use the -Property switch to control which output properties are included in the HTML file and you will have to provide a filename.


To see how this command might be used, think back to the previous section, where we typed Get-Service to create a list of every service that’s installed on the system. Now imagine that you want to create an HTML report that lists the name of each service along with its status (regardless of whether the service is running). To do so, you could use the following command:


Get-Service | ConvertTo-HTML -Property Name, Status > C:\services.htm

6: Export-CSV



Just as you can create an HTML report based on PowerShell data, you can also export data from PowerShell into a CSV file that you can open using Microsoft Excel. The syntax is similar to that of converting a command’s output to HTML. At a minimum, you must provide an output filename. For example, to export the list of system services to a CSV file, you could use the following command:

Get-Service | Export-CSV c:\service.csv

7: Select-Object


If you tried using the command above, you know that there were numerous properties included in the CSV file. It’s often helpful to narrow things down by including only the properties you are really interested in. This is where the Select-Object command comes into play. The Select-Object command allows you to specify specific properties for inclusion. For example, to create a CSV file containing the name of each system service and its status, you could use the following command:

Get-Service | Select-Object Name, Status | Export-CSV c:\service.csv

8: Get-EventLog


You can actually use PowerShell to parse your computer’s event logs. There are several parameters available, but you can try out the command by simply providing the -Log switch followed by the name of the log file. For example, to see the Application log, you could use the following command:

Get-EventLog -Log "Application"

Of course, you would rarely use this command in the real world. You’re more likely to use other commands to filter the output and dump it to a CSV or an HTML file.



9: Get-Process


Just as you can use the Get-Service command to display a list of all the system services, you can use the Get-Process command to display a list of all the processes that are currently running on the system.


10: Stop-Process


Sometimes, a process will freeze up. When this happens, you can use the Get-Process command to get the name or the process ID for the process that has stopped responding. You can then terminate the process by using the Stop-Process command. You can terminate a process based on its name or on its process ID. For example, you could terminate Notepad by using one of the following commands:


Stop-Process -Name notepad

Stop-Process -ID 2668

Keep in mind that the process ID may change from session to session.

Thursday, 17 February 2011

Transfer Outlook Express email to Windows 7

A few days back a not-so-tech-savvy friend of mine asked for my help. He had purchased a new laptop and wanted to know how to transfer all the old Outlook Express email messages to Windows 7. He promised a fresh Cuban cigar if I could come down to his office and help move the email messages. The thought of sipping excellent Cognac with a Cuban was enough to drag me out on that cold winter night.


In a few minutes I was in front of a brand new Windows 7 machine ready to transfer Outlook Express email to Windows 7. Now there are two ways to do this. The first is simpler and involves importing the messages from a backup of Outlook Express into Windows Live Mail, the Windows 7 email program. But we were really disappointed when this failed. Probably the backup process wasn't done properly, I thought. Or maybe the email folders were faulty (because my friend used to complain frequently of Outlook Express crashes). There was no option but to take the second, more complex route.



Instructions on how to transfer Outlook Express email to Windows 7 - Windows Live Mail


Since I knew Windows Live Mail could import messages from an existing installation of Outlook Express, Windows Mail and Windows Live Mail, the convoluted path I followed was this.



Get Windows Live Mail (WLM) program on the old Windows XP computer which already had Outlook Express. The newly installed email program will automatically import account settings as well as the messages from Outlook Express. Now export the email from Windows Live Mail on XP and move them to the new Windows 7 computer.



How to transfer the Outlook Express email from your Windows XP computer to Windows 7 running Windows Live Mail - a convoluted path




  • Download Windows Live Mail on the Windows XP computer and install it.

  • When Windows Live Mail installs on your XP computer it will detect Outlook Express and copy the email account settings as well as the messages. If it doesn't, read how to copy email accounts from Outlook Express to Windows 7 and then transfer the email messages.


  • When all the messages have been moved from Outlook Express to Windows Live Mail on XP, use the Export function of the latter to save a back up of the email to a folder of choice. Copy this entire folder on a flash drive or a DVD. Important: Remember to also move the Outlook Express address book and the email accounts data along with the messages. Shutdown the Windows XP computer because it's work is over.

  • Transfer the address book, email account information and exported Windows Live Mail messages (which were originally of Outlook Express) to the Windows 7 computer and dump them in a temporary directory.

  • On the Windows 7 computer, open the Windows Live Mail program - it should be factory installed. If not, refer the instructions on how to install the Windows Live Mail.

  • But before you transfer the Outlook Express email, import the email account data to avoid configuring Windows Live Mail manually. This will save you time as well as a lot of trouble if you had multiple accounts set up in Outlook Express and / or you don't remember the settings for the account (especially the password and the incoming and outgoing email server details).


  • Now with the "File" -> "Export" -> "Messages" functionality, move all the email messages to Windows Live Mail on Windows 7.



As I mentioned at the start, I took this convoluted approach to transfer Outlook Express email to Windows Live Mail on Windows 7 because the O.E. backup failed (for me)... it might just work for you. So try that first - it's easier; read how to copy email from Outlook Express to Windows Live Mail for step by step instructions and screenshots.

Thursday, 9 December 2010

10 Sysinternals tools you shouldn't be without

Sysinternals has been around for quite some time and was acquired by Microsoft in 2006. These are great little tools for getting some heavy-hitting Windows things done and sometimes done better than when using the built-in tools for a task. The entire suite of products is available for download. While this is the easiest way to get the tools because they are bundled together, there are some tools that I find myself using far more than others. Here’s a look at my favorite tools in the Sysinternals collection (or the ones that I use the most).


Note: This article is also available as a TechRepublic photo gallery.



1: PsList and PsKill


I listed these together because I typically use them in this order. The goal here is to see processes on a machine — with PsList, I find the process ID, and then use PsKill to terminate the process.


There are quite a few ways to return information with PsList, and the best part is that it works on local and remote machines. PsKill works similarly to PsList except it is used to terminate processes by process ID.


2: Process Explorer


Process Explorer is a great tool for digging into open files or resources. Trying to open a file, but getting a notification that it’s already open? Process Explorer can help determine which application or process has the file open. It is a GUI-based utility and can be used as a Task Manager replacement. The utility has two panes of information. The top pane shows currently active processes on your system and includes information about the name, the account that owns the process, and the CPU usage of the process.


The bottom pane has two modes of operation, handle mode and DLL mode. When handle mode is enabled, selecting a process in the top portion of the window will show you the handles that the process has open. In DLL mode, the pane displays the DLLs and memory-mapped files loaded by the selected process.



3: ZoomIt


ZoomIt is a utility for the public speaker in all of us. When presenting information, sometimes it is helpful to show a certain area of the screen, magnified to call attention to a dialog box or other item. This is what ZoomIt does. When configured, it will integrate with PowerPoint to allow macro keys to trigger functions during a presentation.


4: PsLoggedOn


PsLoggedOn uses a registry scan to look through the HKEY_USERS key to see which profiles are loaded. Looking at the keys with a user ID SID, PsLoggedOn looks up the username of the SID and displays it. This shows you who is logged on in any session to a PC. When querying remote systems, your userid will be found as a connected user session as well. The remote and local users are returned separately to help distinguish logon types.


5: Autoruns


You know how malware likes to invade the startup folder and other locations on infected systems? Seems that these are the hardest things to find and get rid of when trying to clean up spyware/malware/ infections. Autoruns can help with that. It looks through all possible locations where applications can be listed to automatically launch when Windows starts. Then, it displays them in a tabbed, easy-to-follow GUI. You can hide Microsoft-signed entries to eliminate the good items from the list of things that start up on your system.


6: Contig


Some files have trouble with disk defragmenting applications and for one reason or another, can’t be corrected. This is where you might use Contig. It is a single file defrag utility, which can be helpful if you use a file often and suspect it might be suffering from performance issues due to fragmentation.



7: Disk2vhd


Disk2vhd creates a virtual hard disk file from a physical system for use with Hyper-V or even with Windows 7 or Server 2008 R2. Disk2vhd supports Windows XP SP2 and Windows Server 2003 SP1 and higher, including 64-bit versions of these systems.


A great use of this utility might be to create a snapshot of an entire disk for backup purposes. There are also options that allow Disk2vhd to be run at the command line. You can use these options to script vhd creation. Using the utility in this way would allow you to use Task Scheduler and Disk2vhd to create a snapshot of your PC at scheduled intervals with no user intervention. One caveat: When creating vhds, be sure not to attach them to the same system you created them from if you are going to boot from the vhd.


8: MoveFile


As we all know, there are times when files need to be moved or deleted to help get things cleaned off a PC (malware/bots/viruses). Sometimes, this can’t be done because files are in use, which prevents actions on the files until they are closed or the computer is rebooted. MoveFile provides an API that marks files for move/rename/delete at the next restart of the Windows system. Doing this allows the file to be acted on before it is referenced by the system.


9: PSFile



The PStools utilities are all popular and useful, but one that I recently discovered is PSFile. This utility shows files on a system that are open by remote systems by default but that can be passed parameters to return information about remote systems as well. This tool is a good way to check for open files on file servers when users might report read-only issues or have problems getting files to open properly.


10: Sync


This utility was created to mirror a UNIX utility that will allow you to flush cached file system data to disk. Doing this can help prevent problems with lost system information in the event of a system failure and helps to ensure live system information is getting written to disk.


The way I see this being useful depends on how stable your system is. If your computer tends to crash more than you would like (or if you are testing some scenarios), you might create a scheduled task to ensure that the system info is flushed back to disk once per hour or some other predefined timeframe. Another cool thing about this sync utility is that USB or ZIP drives or other removable drives can be flushed. You will need administrative privileges to use Sync.

Tuesday, 26 October 2010

10 things you should know about IPv6 addressing

Over the last several years, IPv6 has been inching toward becoming a mainstream technology. Yet many IT pros still don’t know where to begin when it comes to IPv6 adoption because IPv6 is so different from IPv4. In this article, I’ll share 10 pointers that will help you understand how IPv6 addressing works.



Note: This article is also available as a PDF download.


1: IPv6 addresses are 128-bit Hexadecimal numbers


The IPv4 addresses we’re all used to seeing are made up of four numerical octets that combine to form a 32-bit address. IPv6 addresses look nothing like IPv4 addresses. IPv6 addresses are 128 bits long and are made up of hexadecimal numbers.


In IPv4, each octet is separated by a period. In IPv6, the hexadecimal characters are separated by colons. A group of hexadecimal characters can range from two to four characters in length.


2: Link local unicast addresses are easy to identify


IPv6 reserves certain headers for different types of addresses. Probably the best known example of this is that link local unicast addresses always begin with FE80. Similarly, multicast addresses always begin with FF0x, where the x is a placeholder representing a number from 1 to 8.



3: Leading zeros are suppressed


Because of their long bit lengths, IPv6 addresses tend to contain a lot of zeros. When a section of an address starts with one or more zeros, those zeros are nothing more than placeholders. So any leading zeros can be suppressed. To get a better idea of what I mean, look at this address:


FE80:CD00:0000:0CDE:1257:0000:211E:729C

If this were a real address, any leading zero within a section could be suppressed. The result would look like this:


FE80:CD00:0:CDE:1257:0:211E:729C

As you can see, suppressing leading zeros goes a long way toward shortening the address.


4: Inline zeros can sometimes be suppressed


Real IPv6 addresses tend to contain long sections of nothing but zeros, which can also be suppressed. For example, consider the address shown below:



FE80:CD00:0000:0000:0000:0000:211E:729C

In this address, there are four sequential sections separated by zeros. Rather than simply suppressing the leading zeros, you can get rid of all of the sequential zeros and replace them with two colons. The two colons tell the operating system that everything in between them is a zero. The address shown above then becomes:


FE80:CD00::211E:729C

You must remember two things about inline zero suppression. First, you can suppress a section only if it contains nothing but zeros. For example, you will notice that the second part of the address shown above still contains some trailing zeros. Those zeros were retained because there are non-zero characters in the section. Second, you can use the double colon notation only once in any given address.


5: Loopback addresses don’t even look like addresses


In IPv4, a designated address known as a loopback address points to the local machine. The loopback address for any IPv4-enabled device is 127.0.0.1.


Like IPv4, there is also a designated loopback address for IPv6:


0000:0000:0000:0000:0000:0000:0000:0001


Once all of the zeros have been suppressed, however, the IPv6 loopback address doesn’t even look like a valid address. The loopback address is usually expressed as ::1


6: You don’t need a traditional subnet mask


In IPv4, every IP address comes with a corresponding subnet mask. IPv6 also uses subnets, but the subnet ID is built into the address.


In an IPv6 address, the first 48 characters are the network prefix. The next 16 characters (which are often all zeros) are the subnet ID. And the last 64 characters are the interface identifier. Even though there is no subnet mask, you have the option of specifying a subnet prefix length.


7: DNS is still a valid technology


In IPv4, Host (A) records are used to map an IP address to a host name. DNS is still used in IPv6, but Host (A) records are not used by IPv6 addresses. Instead, IPv6 uses AAAA resource records, which are sometimes referred to as Quad A records. The domain ip6.arpa is used for reverse hostname resolution.


8: IPv6 can tunnel its way across IPv4 networks


One of the things that has caused IPv6 adoption to take so long is that IPv6 is not generally compatible with IPv4 networks. As a result, a number of transition technologies use tunneling to facilitate cross network compatibility. Two such technologies are Teredo and 6to4. Although these technologies work in different ways, the basic idea is that both encapsulate IPv6 packets inside IPv4 packets. That way, IPv6 traffic can flow across an IPv4 network. Keep in mind, however, that tunnel endpoints are required on both ends to encapsulate and extract the IPv6 packets.



9: You might already be using IPv6


Beginning with Windows Vista, Microsoft began installing and enabling IPv6 by default. Because the Windows implementation of IPv6 is self-configuring, your computers could be broadcasting IPv6 traffic without your even knowing it. Of course, this doesn’t necessarily mean that you can abandon IPv4. Not all switches and routers support IPv6, just as some applications contain hard-coded references to IPv4 addresses.


10: Windows doesn’t fully support IPv6


It’s kind of ironic, but as hard as Microsoft has been pushing IPv6 adoption, Windows does not fully support IPv6 in all the ways you might expect. For example, in Windows, it is possible to include an IP address within a Universal Naming Convention (\\127.0.0.1\C$, for example). However, you can’t do this with IPv6 addresses because when Windows sees a colon, it assumes you’re referencing a drive letter.


To work around this issue, Microsoft has established a special domain for IPv6 address translation. If you want to include an IPv6 address within a Universal Naming Convention, you must replace the colons with dashes and append .ipv6.literal.net to the end of the address — for example, FE80-AB00–200D-617B.ipv6.literal.net.