Skip to main content

SQL Tips: Powershell Basics for DBAs

We have been discussing about PowerShell in a regular interval. In such a way, this is another tip for you about PowerShell. Using PowerShell is as easy as it presents you with things as drives. If you wish to use C drive, you can use “CD C:” in PowerShell as you do in DOS. Moreover, if you wish to access your registry, you can do it by typing “CD HKLM:”. If you wish to access SQL Server via PowerShell, it is required to type “CD SQLSERVER:”. Now, let’s try connecting to a SQL Server and to a specific DB. If you wish to do so, you can simply type the following command.
>cd SQLServer:\SQL\ServerName\Default\Databases\DBName
As you’ve clearly understood the structure of PowerShell, you can easily switch between servers, databases or any other objects as you’ve to replace the name of the objects and leave the rest the same. Now, let’s have a look about the different drives with you can work. The command we’ve provided is “psdrive” and it is required to type it as follows in the PowerShell Prompt.

If you run this command, you’ll get output as shown below. Moreover, the output will be slightly different depending upon what you’ve loaded on your box and most will be the same. However, I’ve provided some interesting ones.
•    HKCU – HKey_Current_User registry hive.
•    Env – here you can see all the environment variables and values for your box.
•    HKLM – Hkey_Local_Machine registry hive.
•    Variable – here you can see all the built-in and user-defined variables for your active session.
•    Function -- here you can see all the built-in and user-defined functions for your active session.
Another most aspect of PowerShell is cmdlet. It is as same as commands in DOS and is easy to work with. The consistence of cmdlet makes it easier to work with. Some of the examples of cmdlets are get-service, out-file, get-process, format-table and get-content. If you wish to pass a parameter to a cmdlet, simply type “-“ followed by the parameter name and then a space. Check the following examples out.
>get-service –computername Server1

See, no more wondering if you have to use a dash or a slash, and no more wondering if you have to put a space between the parameter or not. They all work the same. Of course, for all string inputs you’re welcome to use double or single quotes if there aren’t any spaces in the string it isn’t necessary. All cmdlets handle errors in the same way too. Each one has a set of common parameters that they all support: debug, errorAction, ErrorVariable, and WarningAction, just to name a few. This means that error handling and debugging are built into every cmdlet so functionality will be the same across the board no matter if you’re working with SQL Server, IIS, Exchange, or anything else. It’s all the same.
In this command, dash and slash work same. Moreover, if you wish you can put a space between the parameter or you can simply avoid it. All of the cmdlets work same in handling errors, debug, error action, error variable and warning action. Therefore, if you’re working in SQL Server, IIS, Exchange or anything else, they’re all the same.

B y

Popular posts from this blog

New Micro battery, power packed for high performance

For a size of a few millimetres, the new micro-batteries are powerful enough to jump start a car battery and then quickly charge the cell phone. Researchers from the University of Illinois have developed the micro batteries which can be used to drive compact electronic devices and new applications for radio communications. The micro batteries are so good that they can even out power the super capacitors. The results were published in ‘Nature Communications’ in the April 16 issue. The micro batteries have energy and power and with the researchers tweaking the structure of the micro batteries a little bit, its use can be for wide range applications. The high performance of the micro battery is based on its 3-dimensional micro-structure. Based on the design of fast charging cathode by Professor Paul Braun’s group, researchers developed the matching anode and integrated it with the fast charging cathode at a micro-scale and made a complete battery with high performance. These batteries cou

HTC Touch Diamond SmartPhone!

The phones design is an innovative in which the user has the geometric form language to make sure a clutter-free environment for screening content. The San Francisco based studio One & Co collaborated with HTC Taiwan Design team to create Diamond HTC smartphone. The HTC phone is quite wonderful with design and the rapid development in the smartphone market the HTC has taken innovative steps to capture the SmartPhone market HTC develops these kind of new inventive designs. Inspired

Google Health Login Page is Ready!

Google's Marissa Mayer announced that the Google Health will be launched on 2008. The service of the Google Health Login Page is ready. It's only the first intro page is displayed and I didn't get passed to the next page. In the same page y0u can see the information displaying on the Google Health. If you point your mouse on the below link you can visit the Google Health Page With Google Health, you can: * Build online health profiles that belong to you * Download medical records from doctors and pharmacies * Get personalized health guidance and relevant news * Find qualified doctors and connect to time-saving services * Share selected information with family or caregivers This will be a nice development about caring health and this will helps in having some cautious about health. Inspired