Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Extracting user-defined assemblies


In this recipe, we will extract user-defined assemblies and resave these back to the filesystem as DLLs.

Getting ready

We can use the SampleDB database that we used in the previous recipe, or you can substitute this with any database that is accessible to you that has some user-defined assemblies.

How to do it...

These are the steps required to extract user-defined assemblies:

  1. Open PowerShell ISE as an administrator.

  2. Import the SQLPS module as follows:

    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
  3. First, we will create a bcp format file. Add the following script and run it:

    $VerbosePreference = "Continue"
    $instanceName = "localhost"
    
    $timestamp = Get-Date -format "yyyy-MMM-dd-hhmmtt"
    $emptyBLOB = "SampleDB.dbo.EmptyBLOB"
    
    $formatFileName = "C:\CLR Files\clr$($timestamp).fmt"
    
    $fmtcmd = "bcp `"$emptyBLOB`" format nul -T -N  -f `"$formatfilename`" -S $instanceName"
    
    #create the format file
    Invoke-Expression -Command  $fmtcmd
    
    #now there is a problem...