Monday, 23 April 2012

Sample powershell scripts

ProjectDir - Project Folder
OutDir - either bin\debug or bin\release or whatever set as output directory

1. To Copy files from 'some folder' into output directory  - below copies everything from 'libs' folder which is at same level as that of our Project directory into Project directory's output.

    copy /Y $(ProjectDir)\..\libs\* $(ProjectDir)\$(OutDir)\

to be contd....

Friday, 13 April 2012

BadImageFormatException in Windows 2008 R2 Server

I successfully imported PowerShell Script written using C#, but it throws System.BadImageFormatException when i tried to execute it. After spending few hours, figured out my Powershell Script was compiled for x86, so i should have used “c:\Windows\SysWOW64\WindowsPowerShell\v1.0”.

Tuesday, 10 April 2012

Useful tips

1. How to load all the assemblies?

var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();

2. Combine absolute & relative paths

var relativePath = "..\\bling.txt";
var baseDirectory = "C:\\blah\\";
var absolutePath = Path.GetFullPath(baseDirectory + relativePath);

3. Get x86 Program folder

    static string ProgramFilesx86()
    {
       if( 8 == IntPtr.Size
       || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable( 
                "PROCESSOR_ARCHITEW6432"))))
       {
            return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
       }

        return Environment.GetEnvironmentVariable("ProgramFiles");
    }

4. Delete a windows server

   sc delete [servicename]

5. Sometimes Server.Databases[name].Drop() will fail with 'Currently in use' error 
   or FailedOperationException. These scenarios we have to 'Server.KillDatabase()).

6. Script to create User with server admin role

 USE [master];
 GO
 CREATE LOGIN SimpleUser
    WITH PASSWORD    = N'SimpleUser',
    CHECK_POLICY     = OFF,
    CHECK_EXPIRATION = OFF;
 GO
 EXEC sp_addsrvrolemember
    @loginame = N'SimpleUser',
    @rolename = N'sysadmin';

7. Sn -T [assembly] to get PublicKeyToken.

8. Remove database(s) based on name

DECLARE @Temp TABLE (Id INT IDENTITY(1, 1), name nvarchar(max));
DECLARE @RowCounter INT;
DECLARE @i INT;

INSERT INTO @Temp select name from sys.databases where name like N'GS_81%'

SELECT @RowCounter = MAX(Id) FROM @Temp

SET @i = 1

DECLARE @DBDeleteByName NVARCHAR(max);

WHILE @i <= @RowCounter
BEGIN
    SELECT @DBDeleteByName = 'DROP DATABASE [' + name + ']'  FROM @Temp WHERE Id = @i

    EXEC sp_executesql @DBDeleteByName;

    SET @i = @i + 1;
END

Thursday, 15 March 2012

Smartbear Code Collaborator GUI client not recognizing Subversion repository

Sometimes creating SCM configuration in Code Collaborator GUI client for a SVN server will not work and might get 'svn not found' or 'path not found' error. Please visit this link for fix