Table of Contents
Understanding Microsoft Windows powershell and SQL server 2005 smo - part 2 is easier when the main points are organized clearly. This guide brings together the essential details and practical considerations.

How Microsoft Windows Powershell and SQL Server 2005 SMO - Part 2 Works
The MAK
Part I of this series shows how to set up and use simple PowerShell and SMO commands. In Part II we will learn more about PowerShell as well as its features associated with SMO.If you've ever known programming languages like PERL, Python or C, you can find similarities with the syntax used in PowerShell.In addition, it is compatible with operating systems like UNIX, Linux, MS-DOS. Although PowerShell has great power, not all tasks can be handled with PowerShell. However, Power Shell's shortcomings can be filled using. NET classes and Window managers, such as WMI. Automation techniques of the Power Shell cmdlets can be completed by creating script code. Restore system date and time using Power Shell A simple date and time value of the system can be restored using a simple 'date' cmdlet. [Figure 1.0]
Cmdlet:DateResult:Tuesday, June 12, 2007 8:52:27 AM
Figure 1.0
The system's Date and Time value can be recovered by using a. NET class, following the following cmdlets. [Figure 1.1]
Figure 1.1
We can even give detailed information like Year, Month and Day. [Figure 1.2]
Cmdlet:[System. DateTime]:: get_now (). Year[System. DateTime]:: get_now (). Month[System. DateTime]:: get_now (). DayResult:20076Twelfth
Figure 1.2
Use the WMI cmdlet to recover Date and Time information. [Figure 1.3]
Cmdlet:Get-wmiobject -Namespace rootcimv2 -Class Win32_CurrentTimeResult:__GENUS: 2__CLASS: Win32_LocalTime__SUPERCLASS: Win32_CurrentTime__DYNASTY: Win32_CurrentTime__RELPATH: Win32_LocalTime = @__PROPERTY_COUNT: 10__DERIVATION: {Win32_CurrentTime}__SERVER: HOME__NAMESPACE: rootcimv2__PATH: HOMErootcimv2: Win32_LocalTime = @Day: 12DayOfWeek: 2Hour: 9Milliseconds:Minute: 3Month: 6Quarter: 2Second: 0WeekInMonth: 3Year: 2007__GENUS: 2__CLASS: Win32_UTCTime__SUPERCLASS: Win32_CurrentTime__DYNASTY: Win32_CurrentTime__RELPATH: Win32_UTCTime = @__PROPERTY_COUNT: 10__DERIVATION: {Win32_CurrentTime}__SERVER: HOME__NAMESPACE: rootcimv2__PATH: HOMErootcimv2: Win32_UTCTime = @Day: 12DayOfWeek: 2Hour: 13Milliseconds:Minute: 3Month: 6Quarter: 2Second: 0WeekInMonth: 3Year: 2007
Figure 1.3
Power Shell also allows you to run or execute ad-hock SQL queries for SQL 2000 or SQL 2005 databases. We can get the Date and Time value from SQL Server using SQLServer Management Object and Getdate () Function. In this example, we make a simple connection to a SQL Server and execute the simple Getdate () function To recover the Date and Time value according to the commands below. [Figure 1.4]
Figure 1.4
Cmdlets$ SqlConnection = New-Object System. Data. SqlClient. SqlConnection$ SqlConnection. ConnectionString = "Server = HOMESQLEXPRESS; Database = master; Integrated Security = True"$ SqlCmd = New-Object System. Data. SqlClient. SqlCommand$ SqlCmd. CommandText = "select getdate () as MyDate"$ SqlCmd. Connection = $ SqlConnection$ SqlAdapter = New-Object System. Data. SqlClient. SqlDataAdapter$ SqlAdapter. SelectCommand = $ SqlCmd$ DataSet = New-Object System. Data. DataSet$ SqlAdapter. Fill ($ DataSet)$ SqlConnection. Close ()$ DataSet. Tables [0]ResultMyDate------December 6, 2007 9:35:18 AM
This same example can be used for any adhoc query. Please execute the stored procedure 'sp_helpdb' shown below.
Cmdlets$ SqlConnection = New-Object System. Data. SqlClient. SqlConnection$ SqlConnection. ConnectionString = "Server = HOMESQLEXPRESS; Database = master; Integrated Security = True"$ SqlCmd = New-Object System. Data. SqlClient. SqlCommand$ SqlCmd. CommandText = "sp_helpdb"$ SqlCmd. Connection = $ SqlConnection$ SqlAdapter = New-Object System. Data. SqlClient. SqlDataAdapter$ SqlAdapter. SelectCommand = $ SqlCmd$ DataSet = New-Object System. Data. DataSet$ SqlAdapter. Fill ($ DataSet)$ SqlConnection. Close ()$ DataSet. Tables [0]ResultName: masterDb_size: 4.75 MBOwner: saDbid: 1Created: Apr 8 2003Status: Status = ONLINE, Updateability = READ_WRITE, UserAccess = MULTI_USER, Recovery = SIMPLE, Version = 611, ColLation = SQL_Latin1_General_CP1_CI_AS, SQLSortOrder = 52, IsAutoCreateStatistics, IsAutoUpdateStatistIcsCompatibility_level: 90Name: modelDb_size: 1.69 MBOwner: saDbid: 3Created: Apr 8 2003Status: Status = ONLINE, Updateability = READ_WRITE, UserAccess = MULTI_USER, Recovery = SIMPLE, Version = 611, ColLation = SQL_Latin1_General_CP1_CI_AS, SQLSortOrder = 52, IsAutoCreateStatistics, IsAutoUpdateStatistIcsCompatibility_level: 90Name: msdbDb_size: 5.44 MBOwner: saDbid: 4Created: Oct 14 2005Status: Status = ONLINE, Updateability = READ_WRITE, UserAccess = MULTI_USER, Recovery = SIMPLE, Version = 611, ColLation = SQL_Latin1_General_CP1_CI_AS, SQLSortOrder = 52, IsAutoCreateStatistics, IsAutoUpdateStatistIcs, IsFullTextEnabledCompatibility_level: 90Name: tempdbDb_size: 2.50 MBOwner: saDbid: 2Created: Jun 12 2007Status: Status = ONLINE, Updateability = READ_WRITE, UserAccess = MULTI_USER, Recovery = SIMPLE, Version = 611, ColLation = SQL_Latin1_General_CP1_CI_AS, SQLSortOrder = 52, IsAutoCreateStatistics, IsAutoUpdateStatistIcsCompatibility_level: 90Name: testDb_size: 2.68 MBOwner: HOMEMAKDbid: 5Created: Jan 15 2007Status:Compatibility_level: 90Name: VixiaTrackDb_size: 6.94 MBOwner: HOMEMAKDbid: 6Created: Apr 22 2007Status:Compatibility_level: 90Name: XMLTestDb_size: 2.68 MBOwner: HOMEMAKDbid: 7Created: Apr 17 2007Status: Status = ONLINE, Updateability = READ_WRITE, UserAccess = MULTI_USER, Recovery = SIMPLE, Version = 611, ColLation = SQL_Latin1_General_CP1_CI_AS, SQLSortOrder = 52, IsAutoClose, IsAutoCreateStatistics, IsAutoUpdateStatistics, IsFullTextEnabledCompatibility_level: 90
Conclude In Part II, we introduced various methods (WMI,. Net classes.) that you can use to recover information on Windows servers and SQL Server.
Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 3
Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 4
Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 5
Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 6
Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 7
Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 8
Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 9
Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 10
Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 11
FAQ
What is the main benefit of Microsoft Windows powershell and SQL server 2005 smo - part 2?
The main benefit is a clearer understanding of the topic and a practical way to apply the information covered in this guide.
What should I check before using Microsoft Windows powershell and SQL server 2005 smo - part 2?
Confirm compatibility, review the required settings, protect important data, and use the latest supported version whenever possible.
What should I do if the result is different?
Repeat the steps carefully, verify permissions and version differences, and consult the product's official support documentation for changes not shown in the article.
Reader Comments 0
Sign in with email or Google to join the discussion.