Powershell

Change Registry Using Params in powershell

param (
   
   [string]  $userName = "UserName",
   [Parameter(Mandatory=$true)] [string] $value = "SecretPassword"
   
)

$registryPath = "HKLM:\SOFTWARE\WOW6432Node\TESTAPP"
IF(!(Test-Path $registryPath))

  {

    New-Item -Path $registryPath -Force | Out-Null
    New-ItemProperty -Path $registryPath -Name $userName -PropertyType 'String' -value $value

}

 ELSE {
    New-ItemProperty -Path $registryPath -Name $userName -Value $value -PropertyType 'String' -Force | Out-Null

 }

Modify webconfig connectionstring using powershell


 [CmdletBinding()]
  param ($PT_connectionstring_new =  "newpassword")  
  $webConfig = 'D:\Web.config'

Function updateWebConfig($config) 
{ 
$doc = (Get-Content $config) -as [Xml]
$root = $doc.get_DocumentElement();
$activeConnection = $root.connectionStrings.SelectNodes("add")|?{$_.name -eq "PROD"};
$activeConnection.SetAttribute("connectionString",$PT_connectionstring_new);
$doc.Save($config)
} 

updateWebConfig($webConfig)