forked from jarulvalan/SSAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeploySSASForODBC.ps1
144 lines (104 loc) · 4.99 KB
/
DeploySSASForODBC.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<#
Running this script will deploy the SSAS Tabular Model to the SSAS Server mentioned by using the build files of the SSAS Tabular Model Project
Sample Execution: D:\Projects\Kaiser\DeploySSASForODBC.ps1 -path "D:\Projects\Kaiser" -SSASServer "localhost\sqltabular" -bimmodelname "Model" -CubeDB "SSASDev_demo1" -AnalysisServicesDeploymentExePath "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Microsoft.AnalysisServices.Deployment.exe" -SourceDBUserName "phanir@microsoftcom" -SourceDBPassword "aaadd2992"
#>
Param
(
[Parameter(Mandatory = $true)]
[String]$path,
[Parameter(Mandatory = $true)]
[String]$SSASServer,
[String]$BimModelName,
[Parameter(Mandatory = $true)]
[String]$CubeDB,
[Parameter(Mandatory = $true)]
[String]$AnalysisServicesDeploymentExePath,
[Parameter(Mandatory = $true)]
[String]$SourceDBUserName,
[Parameter(Mandatory = $true)]
[String]$SourceDBPassword
)
<#
$path="D:\Projects\Kaiser"
$SSASServer= "localhost\sqltabular"
$BimModelName = "Model"
$CubeDB = "Hitesh_SSASDB"
$AnalysisServicesDeploymentExePath="C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Microsoft.AnalysisServices.Deployment.exe"
$SourceDBUserName="[email protected]"
$SourceDBPassword="sadsadasd"
#>
Write-Host "------------------------------------"
$pwd = pwd
Write-Host "Path of PowerShell Script = $pwd"
$AsDBpath = "$path\$BimModelName.asdatabase"
$DepTargetpath = "$path\$BimModelName.deploymenttargets"
$ConfigPath = "$path\$BimModelName.configsettings"
$DeployOptionPath = "$path\$BimModelName.deploymentoptions"
$SSASConnectionString = "DataSource=$SsasServer;Timeout=0"
$SourceDBConnectionString = "Provider=SQLNCLI11.1;Data Source=$DatabaseServerName;Integrated Security=SSPI;Initial Catalog=$SourceDBname"
if (!(Test-Path $AsDBpath)) {
Write-Warning "$AsDBpath absent from location passed to the input parameter"
Write-Host "Exiting..."
continue
}
#Adjust .deploymenttargets file for SSAS database connectionstring
$xml = [xml](Get-Content $DepTargetpath)
$xml.Data.Course.Subject
$node = $xml.DeploymentTarget
$node.Database = $CubeDB
$node = $xml.DeploymentTarget
$node.Server = $SsasServer
$node = $xml.DeploymentTarget
$node.ConnectionString = $SSASConnectionString
$xml.Save($DepTargetpath)
#Adjust .deploymentoptions file database connectionstring
$xml = [xml](Get-Content $DeployOptionPath)
$xml.Data.Course.Subject
$node = $xml.DeploymentOptions
$node.ProcessingOption = "DoNotProcess"
$xml.Save($DeployOptionPath)
# Create the xmla script with AnalysisServices.Deployment wizard
Write-Host "Creating XMLA for : $CubeDB"
$path = $path
cd $path
$path
$exe = "$AnalysisServicesDeploymentExePath" #"C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Microsoft.AnalysisServices.Deployment.exe"
$param1 = $BimModelName+".asdatabase"
$param2 = "/s:" + $BimModelName+ ".txt"
$param3 = "/o:" + $BimModelName+".xmla"
$param4 = "/d"
&($exe)($param1)($param2)($param3)($param4)
$xmlafilepath = $BimModelName+".xmla"
$xmladata = Get-Content -Path $xmlafilepath | ConvertFrom-Json
foreach ($ds in $xmladata.createOrReplace.database.model.dataSources){
$ds.Credential.Username = $SourceDBUserName
#Adding password property to the object.
$ds.credential | Add-Member -NotePropertyName Password -NotePropertyValue $SourceDBPassword
}
$xmladata | ConvertTo-Json -depth 100 | Out-File $xmlaFilePath
Write-Host "Importing SQL modules..."
#Get the location of the libarary file location
#if ((Get-Module -ListAvailable | where-object {($_.Name -eq 'SqlServer') -and ($_.Version.Major -gt 20) } |Measure).Count -eq 1){
Import-Module SqlServer -DisableNameChecking
#}
Write-Host "Importing SQL modules...Done"
Write-Host "Path = $path"
Write-Host "Deploying XMLA script to the $SSASServer with DB name as $CubeDB..."
<#
$Result=Invoke-ASCmd -InputFile $path\$BimModelName.xmla -Server:$SSASServer | Out-File $path\$BimModelName.xml
write-host "**************************************************"
write-host "$?"
write-host "$Result"
write-host "***************************************************"
Write-Host "Deploying XMLA script done..."
dir $path
Write-Host "Please check $path\$BimModelName.xmla as this is XMLA output of this Script"
Write-Host "Done."
Write-Host "------------------------------------"
Write-Host "Process the databases started :$CubeDB "
Invoke-ProcessASDatabase -Server $SSASServer -RefreshType Full -DatabaseName $CubeDB | Out-File $path\$BimModelNameFullProcess.xml
Write-Host "Full Process Done for the database $CubeDB \n \n"
Write-Host "------------------------------------\n"
# Changing to the path where the PowerShell Script is saved
cd $pwd
#>