Importing BizTalk Application bindings
Hi All,
This is the continuation for the below blog post.
once you exported the bindings , you can copy the entire folder and try to run the below script.
In the same script folder.
If any error occurs , it halts the processing.
#region WriteLog function
function WriteLog($LogMessage, $LogDateTime, $LogType)
{
write-host
“$LogType, [“+ $LogDateTime +”]: “+ $LogMessage | Add-Content -Path $MainLogFilepath
}
$BiztalkSrvInfo = @{
‘MgmtDbname’=Get-CimInstance MSBTS_GroupSetting -namespace root\MicrosoftBizTalkServer|select MgmtDbName
‘MgmtDbServerName’=Get-CimInstance MSBTS_GroupSetting -namespace root\MicrosoftBizTalkServer|select MgmtDbServerName
}
$Obj = New-Object -TypeName PSObject -Property $BiztalkSrvInfo
$MgmtDbServerName = $Obj.MgmtDbServerName.MgmtDbServerName
$MgmtDbname = $Obj.MgmtDbname.MgmtDbName
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
$inputFiles = “$dir\Bindings\”
$LogFilepath = “$Dir\Logs\”
if(!(Test-Path $LogFilepath))
{
New-Item -ItemType directory -Path $LogFilepath
}
$LogFile = “$LogFilepath\ImportLogfile.txt”
TRY
{
Get-ChildItem -path $inputFiles -Filter *.xml -Recurse |ForEach-Object -Process{
$Actfilepath = $_.FullName
$filename = $_.BaseName
$LogDateTime = get-date
Write-host “***Starting Importing of Bindings for Application : $filename in” + $inputFiles “folder” -ForegroundColor Cyan
$run = “BTSTask.exe ImportBindings /Source:$Actfilepath /ApplicationName:$filename /Server:$MgmtDbServerName /Database:$MgmtDbname”
Invoke-Expression $run | Add-Content $LogFile
if ($LASTEXITCODE -eq 1)
{
$LogMessage = throw $_.Exception.Message
}
$LogDateTime = get-date
Write-host “Finished Extracting of Bindings for Application : $filename in ” + $inputFiles “folder” -ForegroundColor green
}
}
CATCH
{
$_.Exception.Message|Add-Content $LogFile
}
Let me know if you have any questions.
Regards,
Chaitanya
Set Process Priority
You can set the priority of the process by using the priority class parameter. Below is small snippet for that
(Get-Process -Id $processID).priorityclass =2
Below are the priority values.
-2="Idle";-1="BelowNormal";0="Normal";1="AboveNormal";2="High";3="RealTime"
Regards,
Chaitanya
find Nodes in Windows Cluster
below is the snippet for that
Get the node names from the cluster
$ClusterName=’ClusterName’
Get-WmiObject -Namespace root/mscluster -Class MSCluster_Node -ComputerName $ClusterName -EnableAllPrivileges -Authentication 6
Regards,
Chaitanya
get the System time zones in your local system
get the System time zones in your local system using powershell,below is command for that
[System.TimeZoneInfo]::GetSystemTimeZones()
Regards,
Chaitanya
Upload files to Azure Blobs using PowerShell
Below is the sample script for that.
$StorageAccountName = "storageaccountname"
$StorageAccountKey = "storageaccountkey"
$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey # get the context
$ContainerName = "yourcontainer"
New-AzureStorageContainer -Name $ContainerName -Context $ctx -Permission Blob
$localFileDirectory = "C:\work\UploadFilestoBlob\FileDrop\"
$BlobName1 = "yourblob.txt"
$localFile1 = $localFileDirectory + $BlobName1
Set-AzureStorageBlobContent -File $localFile1 -Container $ContainerName1 -Blob $BlobName1 -Context $ctx -Force
Regards,
Chaitanya
Check the Installed PowerShell version
below is the snippet for that
$PSVersionTable.PSVersion
If you want to check this on remote servers, use invoke-command which connects using WinRM service.
Invoke-command -computername server1,server2 -scriptblock ( $PSVersionTable.PSVersion)
Regards,
Chaitanya
Compare files in folders Using PowerShell
below is the snippet for that
get-childitem -File -Recurse -Path C:\work | Group-Object -Property { ($_ | Get-FileHash).Hash } | Where-Object Count -gt 1
Regards,
Chaitanya
Check Service Status Parallelly across multiple servers using PowerShell
Hi All,
If you want to check the services across multiple remote servers , below script will be useful. It uses PowerShell work flow and works in multi-threaded way.
workflow parallelServiceCheck {
param(
[String[]]$ComputerName,
[string]$Status,
[String]$serviceName
)
$obj =New-Object –TypeName PSObject
$Services=$null
if (!([String]::IsNullOrEmpty($serviceName)))
{
$Services = Get-Service -Name $($serviceName) | where { $_.Status -eq $Status }
}
else
{
$Services = Get-Service| where { $_.Status -eq $Status }
}
Add-Member -InputObject $obj -MemberType NoteProperty -Name Services -Value $Services -Force
$obj| select servername, services|select -ExpandProperty services|select Name,Status
}
Clear-Host
parallelServiceCheck -PSComputerName Server1,Server2 `
-Status ‘running’ ` # status is mandatory
-Servicename ” `
|select PSComputerName,Name,Status | Out-GridView
Regards,
Chaitanya
How to find Existing File types in the Folder path
below is the snippet for that
get-childitem -Path c:\work -Recurse |select -Unique Extension
Regards,
Chaitanya
Open Website using PowerShell
below are the ways to do that.
Start-Process -filepath "https://sqlblogging.com/"
[System.Diagnostics.Process]::Start("https://sqlblogging.com/")
(New-Object -Com Shell.Application).Open("https://sqlblogging.com/")
Regards,
Chaitanya