-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateWebConfigRemote.ps1
64 lines (54 loc) · 2.1 KB
/
UpdateWebConfigRemote.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
#$SQLServerName = '10.0.2.4'
param (
[string]$SQLServerName
)
#notepad (Get-WebConfigFile 'IIS:\Sites\Default Web Site\simple2tierweb_deploy')
Write-output "Executing powershell through VM custom script extension ....... "
Write-output "The SQL Server Name to set is " + $SQLServerName
$site = Get-WebApplication -Site "Default Web Site"
#Login-AzureRmAccount
#$SQLServerName = 'drasrsqlSrv14-test'
#$site=Get-Website -Name "Default Web Site"
#$site.Application
#$rootpath = $site.physicalpath
#$rootpath
$FolderPath=Get-WebConfigFile 'IIS:\Sites\Default Web Site\simple2tierweb_deploy'
$FolderPath
$confipath=$FolderPath.DirectoryName+"\web.config"
$confipath
#$confipath= "C:\Inetpub\wwwroot\simple2tierweb_deploy\web.config"
$xml = [xml](get-content $confipath -ErrorAction Stop)
$cname = "miniappdbConnectionString1"
$dbInfo = $xml.SelectNodes("/configuration/connectionStrings/add [@name='$cname']")
$xml
$ConnectionString=$dbInfo.connectionString
$ConnectionString
$connectionName=$dbInfo.name
$arr=$ConnectionString.split(";")
$ConnectionStringNew=""
foreach($str in $arr)
{
if($str -like "Data Source*")
{
$str="Data Source="+$SQLServerName
}
if(!$str.Equals(""))
{
$ConnectionStringNew+=$str+";"
}
}
$ConnectionStringNew
Stop-Service w3svc;
$pathVariable=$env:windir+"\system32\inetsrv"
cd $pathVariable
$site.name
try
{
.\appcmd set config 'Default Web Site/simple2tierweb_deploy' -section:connectionStrings /"[name='$connectionName'].connectionString:$connectionstringnew"
#.\appcmd set config $site.name -section:connectionStrings /"[name='$connectionName'].connectionString:$connectionstringnew"
}
catch
{
throw("Unable to update Server farm")
}
Start-Service w3svc