Tài liệu Kiểm tra SQL Server bằng Windows PowerShell – Phần 4 pdf

9 358 0
Tài liệu Kiểm tra SQL Server bằng Windows PowerShell – Phần 4 pdf

Đang tải... (xem toàn văn)

Thông tin tài liệu

Kim tra SQL Server bng Windows PowerShell Phn 4 Phn 1 ca lot bài này ã gii thiu v kim tra u tiên trên SQL Server các ping mt host. Phn 2 là gii thiu v cách kim tra tt c các dch v ca Windows có liên quan n SQL Server và phn ba là cách kim tra các thông tin phn cng và phn mm. Trong phn tip theo này, chúng tôi s gii thiu cho các bn các thu thp các thông tin v card mng và  a cng t máy ch. Bc 1 ánh hoc copy và paste on mã di ây vào C:\CheckSQLServer\Checkhd.ps1. #Function to check the HDD information on the host machine Function checkHD([string] $Hostname ) { $drives=get-wmiobject -class Win32_LogicalDisk -computername $hostname -errorvariable errorvar if (-not $errorvar) { foreach ($drive in $drives) { if ($drive.drivetype -eq "3" ) { $message= "DeviceID="+$drive.Deviceid+" Size="+ $drive.size/1048576+"MB Free Space="+ $drive.freespace/1048576 +"MB Percentage Used=" + (($drive.Size/1048576)-($drive.freespace/1048576))/ ($drive.Size/1048576) *100+"% " write-host $message -background "GREEN" -foreground "BLACk" } } } } Bc 2 ánh hoc copy và paste on mã di ây vào C:\CheckSQLServer\Checknet.ps1. #Function to check the Network netadapter information on the host machine Function checknet([string] $Hostname ) { $netadapter=get-wmiobject -class win32_networkadapter -computername $hostname -errorvariable errorvar if (-not $errorvar) { foreach ($netadapter in $netadapter) { write-host " " -background "Blue" -foreground "BLACk" #$message= "netadapter Enabled="+$netadapter.Enable #write-host $message -background "GREEN" -foreground "BLACk" $message= "netadapterType="+$netadapter.netadapterType write-host $message -background "GREEN" -foreground "BLACk" $message= "Description="+$netadapter.Description write-host $message -background "GREEN" -foreground "BLACk" $message= "Manufacturer="+$netadapter.Manufacturer write-host $message -background "GREEN" -foreground "BLACk" $message= "NetworkAddresses="+$netadapter.NetworkAddresses write-host $message -background "GREEN" -foreground "BLACk" $message= "PermanentAddress="+$netadapter.PermanentAddress write-host $message -background "GREEN" -foreground "BLACk" $message= "Physicalnetadapter="+$netadapter.Physicalnetadapter write-host $message -background "GREEN" -foreground "BLACk" $message= "ProductName="+$netadapter.ProductName write-host $message -background "GREEN" -foreground "BLACk" $message= "ServiceName="+$netadapter.ServiceName write-host $message -background "GREEN" -foreground "BLACk" $message= "StatusInfo="+$netadapter.StatusInfo write-host $message -background "GREEN" -foreground "BLACk" $message= "Speed="+$netadapter.Speed write-host $message -background "GREEN" -foreground "BLACk" $message= "Status="+$netadapter.Status write-host $message -background "GREEN" -foreground "BLACk" } } } Bc 3 Gán vào file C:\CheckSQLServer\CheckSQL_Lib.ps1 on mã di ây. . ./checkhd.ps1 . ./checknet.ps1 Lúc này C:\CheckSQLServer\CheckSQL_Lib.ps1 s có pinghost, checkservices, checkhardware, checkOS, checkHD và checknet nh th hin bên di. #Source all the functions relate to CheckSQL . ./PingHost.ps1 . ./checkservices.ps1 . ./checkhardware.ps1 . ./checkOS.ps1 . ./checkHD.ps1 . ./checknet.ps1 Lu ý: File CheckSQL_Lib.ps1 này s c cp nht vi ngun dn ca các kch bn mi nh checkhd.ps1 và checknet.ps1. Bc 4 Gn thêm vào file C:\CheckSQLServer\CheckSQLServer.ps1 on mã di ây. Write-host "Checking HDD Information " Write-host " " checkHD $Hostname Write-host "Checking Network Adapter Information " Write-host " " checknet $Hostname Lúc này C:\CheckSQLServer\CheckSQLServer.ps1 s có c checkhd và checknet nh th hiên di. Chúng tôi ã thêm mt s tuyên b write-host  hin toàn b quá trình. #Objective: To check various status of SQL Server #Host, instances and databases. #Author: MAK #Date Written: June 5, 2008 param ( [string] $Hostname ) $global:errorvar=0 . ./CheckSQL_Lib.ps1 Write-host "Checking SQL Server " Write-host " " Write-host " " Write-host "Arguments accepted : $Hostname" write-host " " Write-host "Pinging the host machine" write-host " " pinghost $Hostname if ($global:errorvar -ne "host not reachable") { Write-host "Checking windows services on the host related to SQL Server" write-host " " checkservices $Hostname Write-host "Checking hardware Information " Write-host " " checkhardware $Hostname Write-host "Checking OS Information " Write-host " " checkOS $Hostname Write-host "Checking HDD Information " Write-host " " checkHD $Hostname Write-host "Checking Network Adapter Information " Write-host " " checknet $Hostname } Lu ý: CheckSQLServer.ps1 s c cp nht các iu kin mi và các tham s mi trong các phn sau ca lot bài này. Ngun dn c bn load các hàng c lit kê trong file kch bn và làm cho nó tr lên hin hu trong toàn b PowerShell session. Trong trng hp này, chúng tôi dn ngun mt kch bn, kch bn này li ly ngun t nhiu kch bn khác. Bc 5 Chúng ta hãy thc thi kch bn CheckSQLServer.ps1 bng cách passing “Powerpc” host nh mt i s, xem th hin di ây. ./CheckSQLServer.ps1 PowerServer2 Các kt qu bn thu c nh th hin bên di (tham kho hình 1.0) Checking SQL Server Arguments accepted : PowerServer2 Pinging the host machine PowerServer2 is REACHABLE Checking windows services on the host related to SQL Server Host=PowerServer2 MSSQLSERVER Running OK True .\Administrator Host=PowerServer2 MSSQLServerADHelper100 Stopped OK False NT AUTHORITY\NETWORK SERVICE Host=PowerServer2 MSSQLServerOLAPService Stopped OK False .\Administrator Host=PowerServer2 SQLBrowser Stopped OK False NT AUTHORITY\LOCAL SERVICE Host=PowerServer2 SQLSERVERAGENT Stopped OK False .\Administrator Host=PowerServer2 SQLWriter Stopped OK False LocalSystem Checking hardware Information Host=PowerServer2 Description=AT/AT COMPATIBLE NumberOfLogicalProcessors=2 NumberOfProcessors=1 TotalPhysicalMemory=2145738752 Model=OptiPlex GX270 Manufacturer=Dell Computer Corporation PartOfDomain=True CurrentTimeZone=-240 DaylightInEffect=True Checking OS Information OSArchitecture=32-bit OSLanguage=1033 OSProductSuite=274 OSType=18 BuildNumber=6001 BuildType=Multiprocessor Free Version=6.0.6001 WindowsDirectory=C:\Windows PlusVersionNumber= FreePhysicalMemory=1492684 FreeSpaceInPagingFiles=2402648 FreeVirtualMemory=3948148 PAEEnabled=False ServicePackMajorVersion=0 ServicePackMinorVersion=0 Checking HDD Information DeviceID=C: Size=38143.99609375MB Free Space=23761.51953125MB Percentage Used=37.7057414937619 Checking Network Adapter Information netadapterType= Description=WAN Miniport (SSTP) Manufacturer=Microsoft NetworkAddresses= PermanentAddress= Physicalnetadapter= ProductName=WAN Miniport (SSTP) ServiceName=RasSstp StatusInfo= Speed= Status= netadapterType= Description=WAN Miniport (L2TP) Manufacturer=Microsoft NetworkAddresses= PermanentAddress= Physicalnetadapter= ProductName=WAN Miniport (L2TP) ServiceName=Rasl2tp StatusInfo= Speed= Status= netadapterType= Description=WAN Miniport (PPTP) Manufacturer=Microsoft NetworkAddresses= PermanentAddress= Physicalnetadapter= ProductName=WAN Miniport (PPTP) ServiceName=PptpMiniport StatusInfo= Speed= Status= netadapterType= Description=WAN Miniport (PPPOE) Manufacturer=Microsoft NetworkAddresses= PermanentAddress= Physicalnetadapter= ProductName=WAN Miniport (PPPOE) ServiceName=RasPppoe StatusInfo= Speed= Status= netadapterType= Description=WAN Miniport (IPv6) Manufacturer=Microsoft NetworkAddresses= PermanentAddress= Physicalnetadapter= ProductName=WAN Miniport (IPv6) ServiceName=NdisWan StatusInfo= Speed= Status= netadapterType= Description=WAN Miniport (Network Monitor) Manufacturer=Microsoft NetworkAddresses= PermanentAddress= Physicalnetadapter= ProductName=WAN Miniport (Network Monitor) ServiceName=NdisWan StatusInfo= Speed= Status= netadapterType= Description=Intel(R) PRO/1000 MT Network Connection Manufacturer=Intel NetworkAddresses= PermanentAddress= Physicalnetadapter= ProductName=Intel(R) PRO/1000 MT Network Connection ServiceName=E1G60 StatusInfo= Speed=100000000 Status= netadapterType= Description=Microsoft ISATAP Adapter Manufacturer=Microsoft NetworkAddresses= PermanentAddress= Physicalnetadapter= ProductName=Microsoft ISATAP Adapter ServiceName=tunnel StatusInfo= Speed=100000 Status= netadapterType= Description=WAN Miniport (IP) Manufacturer=Microsoft NetworkAddresses= PermanentAddress= Physicalnetadapter= ProductName=WAN Miniport (IP) ServiceName=NdisWan StatusInfo= Speed= Status= netadapterType= Description=Microsoft Tun Miniport Adapter Manufacturer=Microsoft NetworkAddresses= PermanentAddress= Physicalnetadapter= ProductName=Microsoft Tun Miniport Adapter ServiceName=tunmp StatusInfo= Speed=1073741824 Status= netadapterType= Description=RAS Async Adapter Manufacturer=Microsoft NetworkAddresses= PermanentAddress= Physicalnetadapter= ProductName=RAS Async Adapter ServiceName=AsyncMac StatusInfo= Speed= Status= Hình 1.0 T các kt qu thu c, bn có th thy c các thông tin v   a c!ng và card mng. Bc 6 Chúng ta hãy thc thhi kch bn trên máy không có   a c!ng hay card mng. ./CheckSQLServer.ps1 TestMachine Kt qu mà bn nhn c c th hin bên di (tham kho hình 1.1) Kt qu Checking SQL Server Arguments accepted : TestMachine Pinging the host machine TestMachine is NOT reachable Hình 1.1 Lu ý: bn có th download mã cho phn 3 mi nht  ây. Kt lun Phn 4 này ã gii thiu cho các bn cách truy cp  thu thp các thông tin v   a c!ng và card mng bng Windows PowerShell và WMI-Object. . Kim tra SQL Server bng Windows PowerShell – Phn 4 Phn 1 ca lot bài này ã gii thiu v kim tra u tiên trên SQL Server – các ping mt. services on the host related to SQL Server Host=PowerServer2 MSSQLSERVER Running OK True .Administrator Host=PowerServer2 MSSQLServerADHelper100 Stopped

Ngày đăng: 20/01/2014, 18:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan