Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Run a script with Invoke-Sqlcmd in SSIS Package

$
0
0

Hello everybody :-)

With your help last time, I created a nice script to create views automatically. Now, I need to run the script automatically. How do you think I can launch it in an SSIS Package? Which component? 

Thank you in advance :-)

There is the script:

$server='server'
$Instance='instance'
$SrvInstance="$Server\$Instance"

$Base="baseName"

$Users=Invoke-Sqlcmd -Query "SELECT DISTINCT Name,Login FROM GP" -ServerInstance $SrvInstance -Database $Base 

$Users| Foreach { 
 $checkTable="SELECT TABLE_Name FROM [baseName].[INFORMATION_SCHEMA].[VIEWS] WHERE TABLE_Name = 'GP_$($_.Name)'"				

$result = Invoke-Sqlcmd -Query $checkTable -ServerInstance $SrvInstance -Database $Base

if (!$result)
{
  $Query=@"
  CREATE VIEW [GP_$($_.Name)] AS SELECT [Enabled],[Login]
  FROM A7 CROSS JOIN AD 
  WHERE (A7.Login LIKE '%$($_.Name)%') AND (A7.Name = AD.Login)
"@
  Write-host $_.Name 'View Created' -fore blue
  Invoke-Sqlcmd -Query $Query -ServerInstance $SrvInstance -Database $Base 
 }
 }


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>