Thursday, 23 August 2018

Grant a user access to view stored procedures in MSSQL

To grant access to a non admin user (assuming you have created them an SQL login imported from Active Directory), first run this command in a new query window from SSMS, substituting domain\username for the actual users credentials. Make sure you are targeting the correct database in the context menu


select 'GRANT VIEW DEFINITION ON [' + schema_name(schema_id) + '].[' + name +
       '] TO ' + '[domain\username]'
  from sys.all_objects
where type_desc = 'SQL_STORED_PROCEDURE'
   and schema_id <> schema_id('sys')


This will return a list of the commands you need to run to allow the user access to each stored procedure. Right click the table and select all then copy. Now paste this into your query window, overwriting the above command and run it. Voila, it is done.




Monday, 23 July 2018

Problems using a disabled mailbox's email address as an alias on Exchange 2010















If you get an error like this after removing a mailbox or distribution group and adding its address as an alias to another account, it is happening because the auto-complete cache in Outlook and Outlook Web App uses the x500 email address instead of the SMTP (also know as LegacyExchangeDN), and this address was not found as the error is saying. 

To avoid this you need to add the LegacyExchangeDN as a email address to the desired mailbox too. You can find the DN in the error message: 
  1. Remove IMCEAEX- 
  1. Remove the @***************.com at the end 
  1. Replace all _ for / 
  1. Replace +20 for a blank space 
  1. You will have something like this: /O=***/OU=First Administrative Group/cn=Recipients/cn=*****
  1. Add this to the mailbox as a Custom Address by clicking the downwards arrow next to Add... and selecting Custom Address. Enter x500 as the E-mail type 

Wednesday, 20 December 2017

Wait Stats MS SQL

Run the following query to see the PAGEIOLATCH wait stats for your database server

select *
from sys.dm_os_wait_stats 
where wait_type like 'PAGEIOLATCH%'
order by wait_type asc

Index Fragmentation on MS SQL

Run the following SQL query to see the fragmentation of table indexes. In this example I am checking my SolarWindsOrion database

SELECT OBJECT_NAME(OBJECT_ID), index_id,index_type_desc,index_level,
avg_fragmentation_in_percent,avg_page_space_used_in_percent,page_count
FROM sys.dm_db_index_physical_stats
(DB_ID(N'SolarWindsOrion'), NULL, NULL, NULL , 'SAMPLED')
ORDER BY avg_fragmentation_in_percent DESC

Wednesday, 13 December 2017

Allow SSH to Cisco ASA

Three commands you need to run
 
aaa authentication ssh console LOCAL
 
This first sets it to allow SSH authentication
 
crypto key generate rsa mod 2048 
 
This generates the SSH key to be used.
 
ssh 192.168.0.0 255.255.255.0 outside
 
This allows access in from the outside interface range 192.168.1.0/16 

Sunday, 13 August 2017

Windows 2012 Remote Desktop or RemoteApp session log off

To automatically clear disconnected sessions off of your RDS host, open up 'Edit Group Policy' and browse to Computer Configuration\Administrative Templates\Windows Components\Remote Desktop Services\Remote Desktop Session Host\Session Time Limits. Enable the policies 'Set time limit for disconnected sessions' and 'Set time limit for logoff of RemoteApp sessions'. Set both time limits to 5 minutes.

Remotely sending and executing files to Linux servers

1 - Create a file with a list of server names. For this example I will use /home/scott/servers.txt as my list. Each server name should be on a separate line

2 - Setup passwordless login to remote servers using SSH keys unless you want to keep typing in passwords

3 - Create this script for sending the file out to servers. I call this script SEND:

[ $# -lt 2 ] && { echo 'usage: SEND <file to send> <path at remote server>'
echo '  e.g. SEND file1 /home/test '
exit 0
}
echo "Send ${1} to ${2} all servers listed in /home/scott/servers.txt?    y/n "
read i
if test "$i" = y
        then
        for SERVER in `cat /home/scott/servers.txt`
        do
        echo "Sending to ${SERVER}"
        scp -p $1 $SERVER:$2
        done
exit 0
fi
echo 'Not sent!'



4 - Create this script for executing the file you have just sent. I call this script RCMD

[ $# -lt 1 ] && { echo 'usage: RCMD <command-to-run>'
echo ' e.g. RCMD l /home/test '
exit 0
}
echo "Run  ${1} ${2} ${3} ${4} on all servers listed in /home/scott/servers.txt?    y/n "
read i
if test "$i" = y
        then
        for SERVER in `cat /home/scott/servers.txt`
        do
        echo "Running at ${SERVER}"
        ssh $SERVER ${1} ${2} ${3} ${4}
        done
exit 0
fi
echo 'Not run!'




5 - For the file you want to send, run /Path/To/SEND/Script '/Path/To/File/You/Are/Sending' /Where/You/Want/To/Put/It/On/Remote/Server

6 - To execute the file you have just sent, run /Path/To/RCMD/Script '/Path/To/File/On/Remote/Server'