USE master
GO
DECLARE @LoginName varchar(256)
SET @LoginName ='joe'
SELECT 'USE [' + Name + ']'
+ ';'
+ 'CREATE USER [' + @LoginName + '] FOR LOGIN [' + @LoginName + '] WITH DEFAULT_SCHEMA =dbo'
+ ';'
+ 'EXEC sp_addrolemember ''db_datareader'', '''+ @LoginName + ''''
AS ScriptToExecute
FROM sys.databases
WHERE name NOT IN ('Master','tempdb','model','msdb') -- Avoid System Databases
AND (state_desc ='ONLINE') -- Avoid Offline Databases
AND (source_database_id Is Null) -- Avoid Database Snapshot
ORDER BY Name
Share on Facebook
Tags: SQL
Many people fail to realize it but Exchange versions 2007 and newer come with a native utility to export and import PST files to/from your Exchange server. With previous versions you had to rely on third-party tools or use Microsoft’s EXMerge (which sucks, by the way…mostly because of the 2GB limit on their default ANSI PST file, but I digress…). The commands here aren’t case-sensitive but CamelCase makes them easier to read.
To export a PST file from Exchange:
Give yourself the necessary rights:
Add-MailboxPermission -Identity %username% -User %youradminusername% -AccessRights FullAccess
And then export the mailbox:
Export-Mailbox -Identity %username% -PSTFolderPath %exportpath%
To import a PST file in-to Exchange:
Give yourself the necessary rights:
Add-MailboxPermission -Identity %username% -User %youradminusername% -AccessRights FullAccess
And then import the mailbox:
Import-Mailbox -Identity %username% -PSTFolderPath C:\pstexport\%username%.pst
One important thing to know is that the default options for ‘Import-Mailbox’ DO NOT create duplicates. So if your import fails for some reason, you can just re-run the import command and it will skip everything that’s already in the destination mailbox.
You can also do a cross export/import between mailboxes/stores if you want (although doing moves between MDBs is easy through the EMC UI). You can read more about that on the Microsoft Exchange site. There are a ton of other import options too, like only importing certain date ranges, etc… but I won’t go in-to that here. More info for import options is here.
Share on FacebookTags: Server Management
Every developer has needed this at some point in time, especially when you’re dealing with a database schema that you didn’t create yourself. I found it here and am re-posting it for the sake of convenience.
CREATE PROC SearchAllTables
(
@SearchStr nvarchar(100)
)
AS
BEGIN
-- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
-- Purpose: To search all columns of all tables for a given search string
-- Written by: Narayana Vyas Kondreddi
-- Site: http://vyaskn.tripod.com
-- Tested on: SQL Server 7.0 and SQL Server 2000
-- Date modified: 28th July 2002 22:50 GMT
CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
WHILE @TableName IS NOT NULL
BEGIN
SET @ColumnName = ''
SET @TableName =
(
SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
AND OBJECTPROPERTY(
OBJECT_ID(
QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
), 'IsMSShipped'
) = 0
)
WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
BEGIN
SET @ColumnName =
(
SELECT MIN(QUOTENAME(COLUMN_NAME))
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = PARSENAME(@TableName, 2)
AND TABLE_NAME = PARSENAME(@TableName, 1)
AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
AND QUOTENAME(COLUMN_NAME) > @ColumnName
)
IF @ColumnName IS NOT NULL
BEGIN
INSERT INTO #Results
EXEC
(
'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
FROM ' + @TableName + ' (NOLOCK) ' +
' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
)
END
END
END
SELECT ColumnName, ColumnValue FROM #Results
END
Tags: SQL
function numeric_only($string)
{
//function to strip characters other than numerals from a string
$numString = ereg_replace("[^[:digit:]]", "", $string);
return $numString;
}
Share on Facebook
Tags: PHP
A handy little command to find out how many rows are within a table and how much space is being used by a single table in a MSSQL DB.
sp_spaceused ‘Tablename’
Share on FacebookTags: SQL
PHP has a built-in function called mysql_real_escape_string() for use in MySQL queries but MSSQL has been left in the lurch for this one. I found this handy function on the StackOverflow forums that works like a charm (renamed for more uniform convention).
function mssql_escape_string($data) {
if ( !isset($data) or empty($data) ) return '';
if ( is_numeric($data) ) return $data;
$non_displayables = array(
'/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15
'/%1[0-9a-f]/', // url encoded 16-31
'/[\x00-\x08]/', // 00-08
'/\x0b/', // 11
'/\x0c/', // 12
'/[\x0e-\x1f]/' // 14-31
);
foreach ( $non_displayables as $regex )
$data = preg_replace( $regex, '', $data );
$data = str_replace("'", "''", $data );
return $data;
}
Share on Facebook
Lessons learned from being a Systems Administrator for an ISP
As one of my first forays into entrepreneurship, I co-founded an Internet Service Provider with a friend of mine. I still own the ISP and somewhat run it (it’s no longer my “day” job but I still get to tinker with the infrastructure…I have a couple of really good employees that run the daily operations). Looking back, there are a lot of things that, if done differently, would have saved me many hours of headaches and lost sleep. I’ve attempted to compile a list of some of those items, both for my own future reference and hopefully to help anyone else that may be setting out to build or maintain a consumer oriented publicly-facing service provider network.
My ISP was/is primarily a Linux shop. I used the following when building the infrastructure:
Tags: ISP, Server Management, System Admin
In the following scenario:
Certain system events will still cause the system to ‘beep’ out of the system speaker. Turning off Windows Sound Schemes doesn’t stop the notification beep. Note this is sound is NOT out of the normal soundcard/external speakers but will be out of the internal speaker on the motherboard. If you’re having this problem, you’ll know how incredibly annoying it is. After hours of digging online and trying different scenarios, I stumbled across a fix and have documented it here.
On the terminal server, open Regedit and navigate to the following key:
Tags: terminal server, terminal services, Win2008
So I was going to setup a website for my wife’s new gig on my web-server. I created the MySQL database, FTP account and configured Apache accordingly. After downloading the Joomla 1.5.15 tarball and starting the FTP upload to my web-server, I went looking for the Joomla quickstart guide. To my astonishment, the “quickstart” guide is a full 49 pages long. Awesome, to say the least…and not too quick.
Here’s another one of those blog posts that’s mostly self-serving but hopefully helps a few other Joomla hopefuls.
To install Joomla 1.5 on a LAMP (Linux+Apache+MySQL+PHP) server:
What’s great is that with the newer versions of Joomla, the admin console actually connects to your web-server using FTP to make changes to your config files and to upload Themes/Plugins, etc.. No more chmod’ing files on your web-server!
Share on FacebookTags: how-to, joomla installation, lamp
I’m posting this here as a reference for myself and for anyone else who might be scouring the net looking for the easiest way to jailbreak their iPhone. I found some other guides but the utilities either crashed on my machine (Windows 7 beta), or the download links were broken. I watched this video, then downloaded the utils from his links, then watched again and jailbroke my phone while I followed his example. Worked like a charm….
Check out the video on YouTube
I’ve got some hacks that I’ve put together for a very specific purpose. I’m sure they’ll be useful to others but I can’t share them yet. I’ll post back here oneday when sharing them will be constructive :)
Share on FacebookTags: hack, jailbreak iphone