{"id":1290,"date":"2011-02-01T08:50:15","date_gmt":"2011-02-01T08:50:15","guid":{"rendered":"https:\/\/www.wapshere.com\/missmiis\/?p=1290"},"modified":"2011-02-01T08:56:53","modified_gmt":"2011-02-01T08:56:53","slug":"a-simple-powershell-script-to-copy-tables-to-another-database","status":"publish","type":"post","link":"https:\/\/www.wapshere.com\/missmiis\/a-simple-powershell-script-to-copy-tables-to-another-database","title":{"rendered":"A simple powershell script to copy tables to another database"},"content":{"rendered":"<p>I&#8217;ve finally started using SQL 2008 Reporting Services in earnest to provide access to all that useful data in the FIM Metaverse. Like a good girl I&#8217;m replicating the tables to another database, instead of pointing straight at the active FIMSynchronizationService database. Here&#8217;s a simple little script that I&#8217;ve tacked on to the end of my regular run cycles.<br \/>\n<!--more--><\/p>\n<pre># Copies tables from the FIMSync DB to the FIMReporting DB\r\n\r\n$tables = @('mms_metaverse','mms_metaverse_multivalue','mms_mv_link')\r\n\r\nif(@(get-pssnapin | where-object {$_.Name -eq \u00e2\u20ac\u0153sqlserverprovidersnapin100\u00e2\u20ac\u009d} ).count -eq 0) {add-pssnapin sqlserverprovidersnapin100}\r\nif(@(get-pssnapin | where-object {$_.Name -eq \u00e2\u20ac\u0153sqlservercmdletsnapin100\u00e2\u20ac\u009d} ).count -eq 0) {add-pssnapin sqlservercmdletsnapin100}\r\n\r\nset-location SQLSERVER:\\SQL\\&lt;sqlserver&gt;\\&lt;instance&gt;\\Databases\\FIMReporting\r\n\r\nforeach ($table in $tables)\r\n{\r\n  $SqlQuery = \"if exists (select * from sys.tables where name = N'$table') drop table $table\"\r\n  Invoke-SQLCmd $SqlQuery -SuppressProviderContextWarning\r\n\r\n  $SqlQuery = \"select * into $table FROM FIMSynchronizationService.dbo.$table\"\r\n  Invoke-SQLCmd $SqlQuery -SuppressProviderContextWarning\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve finally started using SQL 2008 Reporting Services in earnest to provide access to all that useful data in the FIM Metaverse. Like a good girl I&#8217;m replicating the tables to another database, instead of pointing straight at the active FIMSynchronizationService database. Here&#8217;s a simple little script that I&#8217;ve tacked on to the end of&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[42,23,5],"tags":[],"class_list":["post-1290","post","type-post","status-publish","format-standard","hentry","category-fim-2010","category-powershell","category-sql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pkp1o-kO","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/comments?post=1290"}],"version-history":[{"count":4,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1290\/revisions"}],"predecessor-version":[{"id":1293,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1290\/revisions\/1293"}],"wp:attachment":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/media?parent=1290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/categories?post=1290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/tags?post=1290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}