Posts

Query to Expand and List All logins within a SQL Server Group

This query will get the details of user logins with in Active directory security group in expanded format which is not available by default in SSMS, this will iterate over all the user logins under Security section and expand and list the users within the group if there are any along with all other logins:
For example DBA team has 10 members who are part of Group Name DBA_GROUP and this Group is added in SQL Server logins so it will list the members with in DBA_GROUP as well (like DOMAIN\DBA1 DOMAIN\DBA2 and so on )instead of just listing DBA_GROUP.

SET NOCOUNT ON CREATE TABLE ##TEMPHOLDUSERS       (        AccountName NVARCHAR(MAX),        AccoutnType NVARCHAR(MAX),        Privilege NVARCHAR(MAX),        MappedLoginName NVARCHAR(MAX),        PermissionPath NVARCHAR(MAX)       ) DECLARE @id NVARCHAR(MAX) DECLARE @getcoinid  CURSOR SET @getcoinid   = CURSOR FOR SELECT name FROM sys.server_principals WHERE TYPE = 'G' AND name NOT LIKE '%$%' and name NOT LIKE 'NT%…

Redirecting all old url to home page or any other page in blogger using script

Adding a 301 redirect for every url which has year older then the value we are setting in our script:

So why this was needed ?

Recently I found in google search console that lot of Page not found errors are triggering for my site and when I looked at the links it was clear that the errors are because the domain was owned by someone else before I got it and google crawlers were still trying to find posts and pages which were published by previous owner.

Although there is a option to create a redirect for links in blogger dashboard but doing that for every single url each and every time was too much of work and also this was a blind game as we don't know for which url the error will trigger next until it was being logged in google search console: So here is quick summary for what I did followed by script and the Long explanations.

Quick Summary: Get current Url user is visiting on my site>Extract Year part from it>If YearFromUrl(is less then)<YearIStartedWritingPostsOnMySite…

SQL Server SSMS Bug: Scripting Delete action to new query window for Maintenance plans is deleting the maintenance plans without even executing the script leaving jobs behind which throws errors during manual delete

Image
SQL Server version: Microsoft SQL Server 2014 (SP2) (KB3171021) - 12.0.5000.0 (X64)
Tested using SSMS 17 and SSMS 12

Scripting Delete action to new query window for Maintenance plans is deleting the maintenance plans without actually executing the script:

Steps to reproduce:
Create a maintenance plan using maintenance plan wizardThis creates maintenance plan under path : Server or Instance Name>Management>Maintenance Plans along with a corresponding job under Sql server agent when viewed from SSMSNow right click on the Maintenance plan that gets created from step 1 in location specified in step 2 above and click deleteBut instead of clicking OK use the script button on top of window and select "script action to new query window" and then click CANCEL in the same window from where we just selected script action.So we just scripted the action and haven't actually deleted the plan nor by clicking OK nor by executing the script that gets created in new window.But now …

Adding copy to clipboard button to every google code prettify pre blocks in blogger

It's a 2 part process:
The script part to find all the pre blocks having code in it and append a copy button to it dynamically.The style part to place our copy button at the specified location(on top right of every code block in this case) The script part:
<script> var pre = document.getElementsByTagName('pre'); for (var i = 0; i < pre.length; i++) {             var button = document.createElement('button');                     button.className = 'copy-button';                     button.textContent = 'Copy';                     var s = pre[i].innerText;                     button.setAttribute("data-clipboard-text",s);                     pre[i].appendChild(button);        } var clipboard = new Clipboard('.copy-button'); clipboard.on('success', function(e) {     console.info('Action:', e.action);     console.info('Text:', e.text);     console.info('Trigger:', e.trigger);     e.trigg…

Enabling fixed Sidebar for blogger Contempo template for screen sizes smaller than 1440px

Image
Here is how to do it :

Add this code in your blogger template(where to add this code is mentioned before 2nd code snippet of this post) ,now the value 1300px is the screen size for which I want the sidebar to be always visible for, you can reduce this value as you like, but be aware that reducing this value to much smaller digit will result in showing the overlapped sidebar instead of content body for your blog readers who are using much smaller screen devices such as mobiles which you might not want to happen so be wise :

@media screen and (max-width: 1300px) {   .sidebar-container {     bottom: 0;     position: fixed;     top: 0;   }   .sidebar-container {     left: 0;     right: auto;   }   .sidebar-container.sidebar-invisible {     -webkit-transition-timing-function: cubic-bezier(0.4,0.0,0.6,1);             transition-timing-function: cubic-bezier(0.4,0.0,0.6,1);   }   .sidebar-container.sidebar-invisible {     -webkit-transform: translateX($(sidebar.width * -1));         -ms-tran…

Connecting Microsoft SQL Server using PHP

Throwing Steps Right away without wasting much time :
3 things you need to have: WAMP/XAMPP installed on your system to run PHP.SQL Server for creating and connecting to Databases etc.PHP Drivers : For bridging SQL Server and PHP. Latest version of PHP Drivers can be download from this Download link which now supports PHP version 7.x.

Steps for installing PHP drivers:
The file that you will download is a nothing but a zip containing some dll files which are nothing but PHP extensions.Find the PHP extension folder for the version you are using and place the files inside that folder.Next open the Php.ini files for the version in use and add the initialization for the dll/plugins files that you just placed in extensions folder cos without initialization those files are good for nothing.Restart the wamp services.Goto Php extension from wamp menu and select the options which are having the same name as those files. This completes the installation part and now we are all ready to test the con…

Call vs Start: Reasons why your batch script might not be writing output to file

Image
If you are calling another batch script from your source script you need to call it by preceding keywords Call or Start before the script name.
But here also there is a catch:
Start will open a new cmd window and execute command there and will not write the output in external text file if you have redirected it there:
For example if you execute BatchScriptSource.bat it will not write anything in SomeTextFile.txt although it will be created.
Contents of BatchScriptSource.bat
start BatchScript.bat >> SomeTextFile.txt Contents of BatchScript.bat
tasklist  Output Using Start:

On the other hand Call will execute BatchScript.bat in the scope of same cmd session/window where BatchScriptSource.bat is being executed and will execute commands sequentially and write the output in SomeTextFile.txt as expected.
Contents of BatchScriptSource.bat
call BatchScript.bat >> SomeTextFile.txt Contents of BatchScript.bat
tasklist Output Using Call:

Things you might not know unless you Automate your first task using task scheduler

If you scheduled some script execution using task scheduler and its running fine only when you are logged in the system and failing when you are not logged in than keep reading !

Few months back I got moved to a new team to take on new challenges within my company where I had to pull some daily reports as a part of my new role apart from technical work.

The process of pulling daily reports included logging into a SSL gateway,RDP a client domain server/jump server run few batch scripts there which in turn would produce few excel report files compressed within a single .rar file as output, ready to be copied to my local desktop, simple enough.

As the batch scripts were to be executed at a particular time I chose windows task scheduler to do this work automatically for me instead of doing it manually as it was perfect fit for my need and moreover I dint had to write a single line of code or any other new script to serve my purpose,scheduling a task with task scheduler is easy, few click…