Posts

Showing posts from 2019

ConvertTo-Html in Powershell

# This PowerShell script gives information about the events of ERROR,CRITICAL and WARNING, and this provides today data alone.     cls $Computername = $env:COMPUTERNAME   $a = get-date $month = $a . tostring( "MM" ) $day = $a . tostring( "dd" ) $year = $a . tostring( "yyyy" ) $OutFile = "D:\ServerList\" + $Computername + "_Error_Warning_Critical.html" $csname = $Computername + "_Warning_Error_Critical" Get-WinEvent ` -LogName Application , System | Select-Object @{Name = "Service" ;expression = { $_ . ProviderName}} , TimeCreated , Id , @{Name = "Level" ;expression = { $_ . LevelDisplayName}} , Message | Where-Object {(( $_ . Level -eq 'warning' ) -or ( $_ . Level -eq 'Error' ) -or ( $_ . Level -eq 'Critical' )) -and ( $_ . Timecreated -like "* $month / $day / $year...

When the SQL Server Services Started and Stopped in Windows server

<# Events that occur after stopping services. #19032:SQL Trace was stopped due to server shutdown. Trace ID = '1'. This is an informational message only; no user action is required. #6527.NET Framework runtime has been stopped. 17148.NET Framework runtime has been stopped. 17148SQL Server is terminating in response to a 'stop' request from Service Control Manager. This is an informational message only. No user action is required. 102SQLServerAgent service successfully stopped. 15457Configuration option 'Agent XPs' changed from 1 to 0. Run the RECONFIGURE statement to install. #> clear Get-EventLog -LogName Application | Where-Object { $_ . EventID -in ( 19032 , 6527 , 17148 , 102 , 15457 )} | Format-Table -AutoSize Sort-Object Time -Descending <# 3408:Recovery is complete. This is an informational message only. No user action is required. 9688:Service Broker manager has started. 17137:Starting up database ...

Backup preferences in Always on AG

Image

Accessing out side folder from VM

Image
If we want to access folder outside of VM, we can access it by using the below check box.

tempdb monitoring queries.

--Script to find historic tempdb usage by session. SELECT TOP 5 * FROM sys.dm_db_task_space_usage WHERE session_id > 50 ORDER BY user_objects_alloc_page_count + internal_objects_alloc_page_count DESC ; -- Finding the top 5 sessions running tasks that use tempdb SELECT * FROM sys.dm_db_session_space_usage WHERE session_id > 50 ORDER BY user_objects_alloc_page_count + internal_objects_alloc_page_count DESC ; -- Script to total tempdb usage by type across all files. SELECT SUM(user_object_reserved_page_count) AS user_object_pages, SUM(internal_object_reserved_page_count) AS internal_object_pages, SUM(version_store_reserved_page_count) AS version_store_pages, total_in_use_pages = SUM(user_object_reserved_page_count) + SUM(internal_object_reserved_page_count) + SUM(version_store_reserved_page_count), SUM(unallocated_extent_page_count) AS total_free_pages FROM sys.dm_db_file_space_usage ; --- To get text and plan SELECT session_id, text, query_plan FROM sys...

SQL Server Services and cluster info along with last reboot time of Server

The below powershell script provide the information of when the server was last rebooted and the status of SQL Server Services and Cluster resources if the sql server is clustered environment. clear $servernames = "C:\ServerList\ServerList.txt" Get-Content $servernames | ForEach-Object { $ComputerName = $_ $S = Get-WmiObject ` -Class Win32_SystemServices ` -ComputerName $ComputerName IF ( $S | Select PartComponent | Where-Object { $_ -like "*ClusSvc*" }) { Write-OutPut " $ComputerName is clustered" Invoke-command ` -ComputerName $ComputerName ` -ScriptBlock { Get-WmiObject Win32_operatingsystem | Select-Object CSName , @{Label = 'LastBootTime' ;EXPRESSION = { $_ . ConverttoDateTime( $_ . lastbootuptime)}} } Invoke-Command ` -ComputerName $ComputerName ` -ScriptBlock { Get-Service -Name "*sql*" } | Format-Table -AutoSize Invoke-Command ` -ComputerName ...

database mirroring queries

SELECT db.name, m.mirroring_role_desc,mirroring_state_desc,mirroring_safety_level, mirroring_partner_name,mirroring_partner_instance,mirroring_witness_name,mirroring_witness_state_desc,* FROM sys.database_mirroring m JOIN sys.databases db ON db.database_id = m.database_id where db.name='DBNamehere' SELECT     databases.name AS DatabaseName,    database_mirroring.mirroring_state_desc,    database_mirroring.mirroring_role_desc,    database_mirroring.mirroring_safety_level,    database_mirroring.mirroring_safety_level_desc,    database_mirroring.mirroring_safety_sequence,    database_mirroring.mirroring_witness_name,    database_mirroring.mirroring_witness_state,    database_mirroring.mirroring_witness_state_desc    FROM sys.database_mirroring     INNER JOIN sys.databases ON databases.database_id=database_mirroring.database_id WHERE databases.database...

Script out table along with Data in SQL Server

Image
Right click on any d atabase and --->Task-->Generate Scripts and you can see the wizard like below. Now click on Next button, you will get the below image, choose required table or all the tables based on your requirement . After you click on next button,it will show you below image and ask for the options like  do you want to scipt ou the info to file or new query editor winow. In my case i have chosen to new query editor window. And you can also see an advanced tab where you can level schema level permissions. After you click on Advanced button, change this below option and it will script out table with data. Once you click on okay and go next this will generate a table with data.

How to get the system info of server

---sytem information msinfo32--> provide system information. dxdiag--> Whether system is VM or not

How to take a backup of Database in MongoDB

Image
The below command will take teh backup of "learn" database in  MongoDB. You have to run this sepately by executing "mongodump". Please find the below steps 1) First i figure out where i have installed Mongodb, it is the C:\Program Files\MongoDB\Server\4.0\bin 2) Then go that folder  by using "CD" command 3) chose "mongodump" and provide parameters like --db --out backup --Out command will create a backup folder in the same drive, it will dump all the documents to that particular folder And the backup files look like below(as mentioned in the below image) If you want to take the same backups to another drive provide the path like below.
Image
The below command will drop all the databases at at time in MongoDB.

Uninstalling sql server through command prompt

Image
We can run the below command to uninstall sql server instances from command prompt. After you run the below command pop up will will appear and it will redirect you to wizard where you need to choose those features for uninstalling.

Installing SQL Server with Powershell

This original script written by Niall Brady, i just changed this script according my requirement <# # Installs SQL Server 2017, 2018/4/5 Niall Brady, https://www.windows-noob.com # # This script:             Installs SQL Server 2017, CU5, SSMS and RS # Before running:          Edit the variables as necessary (lines 17-79). Copy the SQL Service Management Studio (SSMS-Setup-ENU.exe) and Reporting Services (SQLServerReportingServices.exe) files to $folderpath\ in advance if you don't want the script to download the exe's # Usage:                   Run this script on the ConfigMgr Primary Server as a user with local Administrative permissions on the server #>   If ( -NOT ( [ Security.Principal.WindowsPrincipal ] [ Security.Principal.WindowsIdentity ]:: GetCurrent()) . IsInRole...