Tuesday, 3 December 2019

Schedule Jobs through command prompt

@echo off
setlocal enabledelayedexpansion
set numberofthreads=1
set iterationcount=5000
set stophour=22
set stopmin=40
echo Starting All
echo %time%
for /l %%x in (1, 1, %iterationcount%) do (
    Echo Success %%x %%x %%x %%x %%x %%x %%x %%x
    set currTime=!time!
    set currhour=!currTime:~0,2!
    set currmin=!currTime:~3,2!
    echo !time!
    if !currhour! EQU !stophour! (
    if !currmin! GEQ !stopmin! (
    echo "Stop 1 "
    goto :eof
        )
    )
    for /l %%x in (1, 1, %numberofthreads%) do (
        start "" "E:\BatchJobs\BatchFile.bat"
        timeout 5 > NUL
    )
    echo[
    Echo ------
    echo[
    timeout 55 > NUL
)

In Batch process

  • Start - Will create new command prompt and run
  • Call - will Use the same window to execute

Monday, 18 February 2019

Creating Your Own Run Commands

  • Win+R to open the Run dialog 
  • Enter %windir% to open the Windows directory
  • Create a shortcut to the desired program or Move the short cut to the above folder 
  • The name you give the shortcut is what you type in the Run dialog to start the program

Thursday, 14 February 2019

SQL Server Reindexing Query (by Table)

The below query to reindex the SQL Server database index by table

DECLARE @TableName VARCHAR(255) 
DECLARE @sql NVARCHAR(500) 
DECLARE @fillfactor INT 

SET @fillfactor = 80 

DECLARE tablecursor CURSOR FOR 
  SELECT '[' + Object_schema_name([object_id]) + '].[' 
         + NAME + ']' AS TableName 
  FROM   sys.tables 
  ORDER  BY NAME 

OPEN tablecursor 

D365 V9 CRM SDK

This Powershell script will be used to download the SDK tools from the nuget site.

$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = ".\nuget.exe"
Remove-Item .\Tools -Force -Recurse -ErrorAction Ignore
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
Set-Alias nuget $targetNugetExe -Scope Global -Verbose

##
##Download Plugin Registration Tool
##
./nuget install Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool -O .\Tools
md .\Tools\PluginRegistration
$prtFolder = Get-ChildItem ./Tools | Where-Object {$_.Name -match 'Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool.'}
move .\Tools\$prtFolder\tools\*.* .\Tools\PluginRegistration
Remove-Item .\Tools\$prtFolder -Force -Recurse

Tuesday, 12 February 2019

SQL Server Row count on all the tables

This SQL script is used to get the number of records in each tables

SELECT o.NAME, 
       i.rowcnt 
FROM   sysindexes AS i 
       INNER JOIN sysobjects AS o 
               ON i.id = o.id 
WHERE  i.indid < 2 
       AND Objectproperty(o.id, 'IsMSShipped') = 0 
ORDER  BY o.NAME 

Wednesday, 30 January 2019

SQL Server Mising Index

The SQL script is used to identify the missing index in SQL Server
       SELECT dm_mid.database_id                                         AS DatabaseID, 
       dm_migs.avg_user_impact * ( dm_migs.user_seeks + dm_migs.user_scans ) 
       Avg_Estimated_Impact, 
       dm_migs.last_user_seek                                     AS 
       Last_User_Seek, 
       Object_name(dm_mid.object_id, dm_mid.database_id)          AS [TableName] 
       , 

SQL Server Reindexing Query (By Index)

This query is used to reindex the SQL Server database tables index by index

DECLARE @tableName NVARCHAR(500) 
DECLARE @indexName NVARCHAR(500) 
DECLARE @indexType NVARCHAR(55) 
DECLARE @sql NVARCHAR(500) 
DECLARE @percentFragment DECIMAL(11, 2) 
DECLARE fragmentedtablelist CURSOR FOR 
  SELECT '[' + Object_schema_name(ind.object_id)