Ranadip_Dutta

Core_Assessment

Oct 22nd, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #[String]$Global:var=$args[0]----Inputs will come from Java in the below format
  2. $Global:var="ILITIES01,ILITIES01\Username1,Password1:ILITIES02,ILITIES02\Username2,Password2:ILITIES03,ILITIES03\Username3,Password3:"
  3. function LoadDllWithNoLock([string] $filePath)
  4. {
  5.     $fileStream = ([IO.FileInfo] (Get-Item $filePath)).OpenRead();
  6.     $assemblyBytes = new-object byte[] $fileStream.Length
  7.     $fileStream.Read($assemblyBytes, 0, $fileStream.Length);
  8.     $fileStream.Close();
  9.     return [Reflection.Assembly]::Load($assemblyBytes);
  10. }
  11.  
  12. function GetDecryptedString( [string] $encryptedString )
  13. {
  14.     [string]$ec = 'eV5OuC0kd9f7g62hTemDbgTPNXms4emgkl51XDHnodg=';
  15.     [string]$dk = [NextGen.Core.Cryptography.NGEncrypt]::DecryptAES( $ec, [NextGen.Core.Cryptography.NGEncrypt]::sNG_PASSWORD_KEY );
  16.     [string]$decrypted = [NextGen.Core.Cryptography.NGEncrypt]::DecryptAES( $encryptedString, $dk );
  17.    
  18.     return $decrypted;
  19. }
  20.  
  21. ############################# Client Info Details #########################################################
  22. function Get-ClinetInfo()
  23. {
  24.             $global:ng_home           = (get-childitem env:NEXTGEN_SHARE_HOME).value
  25.             $global:confPath          = "$global:ng_home\conf";
  26.             $sharePropData            = Get-Content "$confPath\share.properties";
  27.             $global:shareProps        = $sharePropData -join [Environment]::NewLine | ConvertFrom-StringData ;
  28.             $global:DBUserName        = $shareProps.'nga.database.username';
  29.             $global:DBServerName      = $shareProps.'nga.database.serverName';
  30.             $nextgenCore              = LoadDllWithNoLock -filePath "$ng_home\Rosetta\NextGen.Core.dll"
  31.     [string]$global:dbpwd             = GetDecryptedString -encryptedString $global:shareProps.'nga.database.password';
  32.             $global:GCN               = $shareProps.'share.gcn';
  33.             $global:ShareSiteKey      = $shareProps.'share.sitekey';
  34. ################################## OBJECT Creation for Client Info #############################################################
  35.  
  36. $global:ClinetInfo_Object = New-Object PSObject -Property @{            
  37.         GCN              = $GCN                
  38.         "SAP ID"           = $null              
  39.         "SalesForce ID"    = $null            
  40.         "ShareSiteKey"     = $ShareSiteKey            
  41.         "Client Name"      = $null
  42.         "Site Name"        = $null
  43.         "Domain Name"      = $null
  44.         "Site Address"     = $null          
  45.     }
  46.  
  47.  
  48.  
  49. }
  50. ############################# License Info Details ###########################################################
  51.  
  52. function Get-LicenseInfo()
  53. {
  54. $Global:encryptedKeys=New-Object System.Collections.ArrayList
  55.             $global:ng_home           = (get-childitem env:NEXTGEN_SHARE_HOME).value
  56.             $global:confPath          = "$global:ng_home\conf";
  57.             $sharePropData            = Get-Content "$confPath\share.properties";
  58.             $global:shareProps        = $sharePropData -join [Environment]::NewLine | ConvertFrom-StringData ;
  59.             $global:DBUserName        = $shareProps.'nga.database.username';
  60.             $global:DBServerName      = $shareProps.'nga.database.serverName';
  61.             $nextgenCore              = LoadDllWithNoLock -filePath "$ng_home\Rosetta\NextGen.Core.dll"
  62.     [string]$global:dbpwd             = GetDecryptedString -encryptedString $global:shareProps.'nga.database.password';
  63.  
  64.             $connectionString ="server=$DBServerName; uid=$DBUserName; pwd=$dbpwd;Integrated Security=False;"
  65.             $connection = New-Object System.Data.SqlClient.SqlConnection -ErrorAction Stop
  66.             $connection.ConnectionString = $connectionString
  67.             $connection.Open()
  68.             $query ="select license_key from NGProd.dbo.license_mstr"
  69.             $command = $connection.CreateCommand()
  70.             $command.CommandText = $query
  71.             $result = $command.ExecuteReader()
  72.             $dt = new-object System.Data.DataTable
  73.             $dt.Load($result)
  74.             $Global:LicenseKey=$dt.license_key
  75.  
  76.             foreach($key in $LicenseKey)
  77.             {
  78.  
  79.  
  80. ################################## OBJECT Creation & DB Connection Closure for License Info #############################################################
  81.  
  82. $global:LicenseInfo_Object = New-Object PSObject -Property @{            
  83.        "License Key"             = "$Key"
  84.        "Products Licensed"       = 0
  85.        "Active Date"             = $null
  86.        "Authorized By"           = $null
  87.        "Client Information"      = $null
  88.        "Customer Representative" = $null
  89.        "Date Issued"             = $null
  90.        "Database Name"           = $null
  91.        "Expiry Date"             = $null
  92.        "Prod"                    = $null
  93.        "Server Information"      = $null
  94.        "Version"                 = $null            
  95.     }
  96.     $encryptedKeys.Add($global:LicenseInfo_Object)|Out-Null
  97.             }
  98. $connection.Close()
  99.  
  100. }
  101. ############################# Hardware Info Details ###########################################################
  102. Function Get-HardwareInfo()
  103. {
  104. # Remote System Information
  105. # Shows hardware and OS details from a list of PCs
  106. #[String]$var=$args[0]
  107. #$var="BLRVDILITIES01,BLRVDILITIES01\ITest,Pass@123:BLRVDILITIES02,BLRVDILITIES02\ITest,Pass@123:BLRVDILITIES03,BLRVDILITIES03\ITest,Pass@123:"
  108.  
  109.             $LocalNetwork=Get-WmiObject Win32_Computersystem
  110.     ########### Iterative Function Call based on the number of Inputs in Args[0] ########
  111.                 function HardwareDetails($Computer,$cred)
  112.                 {
  113.  
  114.                 if($LocalNetwork.Name -eq $computer){
  115.  
  116.                 $computerSystem = Get-WmiObject -Class Win32_ComputerSystem  
  117.                 $computerOS     = Get-WmiObject -Class Win32_OperatingSystem
  118.                 $computerCPU    = Get-WmiObject -Class Win32_Processor
  119.                 $computerHDDs   = Get-WmiObject -Class Win32_LogicalDisk -filter "DriveType ='3'"
  120.                 $Network        = Get-WmiObject Win32_NetworkAdapterConfiguration -filter "ipenabled = 'True'"
  121.                 $HotFix         = Get-WmiObject -Class win32_quickfixengineering |?{$_.InstalledOn -ne $null} |sort InstalledOn -Descending | select HotFixID,Description,InstalledOn -First 1
  122.                 }
  123.                 else{
  124.  
  125.                 $computerSystem = Get-WmiObject -Class Win32_ComputerSystem  -Computer $Computer -cred $cred
  126.                 $computerOS     = Get-WmiObject -Class Win32_OperatingSystem -Computer $Computer -cred $cred
  127.                 $computerCPU    = Get-WmiObject -Class Win32_Processor -Computer $Computer -cred $cred
  128.                 $computerHDDs   = Get-WmiObject -Class Win32_LogicalDisk -Computer $Computer -cred $cred -filter "DriveType ='3'"
  129.                 $Network        = Get-WmiObject Win32_NetworkAdapterConfiguration -Computer $Computer -cred $cred -filter "ipenabled = 'True'"
  130.                 $HotFix         = Get-WmiObject -Class win32_quickfixengineering -Computer $Computer -cred $cred |?{$_.InstalledOn -ne $null} |sort InstalledOn -Descending | select HotFixID,Description,InstalledOn -First 1
  131.                 }
  132.  
  133.                 $logicalDisks = @()
  134.                     foreach($item in $computerHDDs)
  135.                     {
  136.                         $logicalDisk =[ordered]@{
  137.                         Name=$item.DeviceID -replace ':' ,'';
  138.                         DiskSize="{0:N2}" -f ($item.Size/1GB) + " GB";
  139.                         UsedSpace="{0:N2}" -f (($item.Size - $item.FreeSpace)/1GB) +" GB"
  140.                         }
  141.                         $logicalDisks +=$logicalDisk    
  142.                     }
  143.                 if($computerCPU.Name -is [system.array]){
  144.                 $Processor = $computerCPU.Name[0]+" & "+($computerCPU.NumberOfLogicalProcessors[0]*$computerCPU.Name.count)
  145.                 }
  146.                 else{
  147.                 $Processor = $computerCPU.Name+" & "+$computerCPU.NumberOfLogicalProcessors
  148.                 }
  149.         ############################# Hardware Info Object Creation based on the number of inputs in Args[0] ########################################
  150.                 $Hardware_Info_Object = [ordered] @{
  151.                 "Machine Name" =$Computer
  152.                 "IP Address" =$Network.IPAddress[0]
  153.                 "Processor"   = $Processor
  154.                 "OS Version"   =$computerOS.caption
  155.                 "Architecture"=$computerOS.OSArchitecture
  156.                 "ServicePack"=$computerOS.ServicePackMajorVersion
  157.                 "Physical Memory" = "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + " GB"
  158.                 "PhysicalDisk Spaces" =$logicalDisks
  159.                 "OS HotFix" = $HotFix
  160.                 }
  161.  
  162.                 return $Hardware_Info_Object
  163.  
  164.                 }
  165.                  try
  166.                  {  
  167.                     $var1=$var.Remove($var.Length -1)
  168.                     $parameter= @($var1)
  169.                     $Splitted= $parameter -split ':'
  170.                     $Length=$Splitted.Length
  171.  
  172.                    # $arrCredentials = $parameter -split ','
  173.                     [int32]$i=0;
  174.  
  175.                      foreach ($splits in $Splitted)
  176.                         {
  177.                             if($i -lt $Length)
  178.                             {
  179.                                 $array=$splits.split(',')
  180.                                 $computer=$array[0]
  181.                                 $username = $array[1]
  182.                                 $password = $array[2]
  183.                                 $secstr = New-Object -TypeName System.Security.SecureString
  184.                                 $password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
  185.                                 $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
  186.                                 HardwareDetails $computer $cred
  187.                                 $i++
  188.                             }
  189.                         }
  190.  
  191.      
  192.                  }
  193.                  catch
  194.                 {  
  195.                     getErrorMessage
  196.    
  197.                 }
  198.  
  199. }
  200. ############################# Version Info Details ###########################################################
  201. Function Get-VersionInfo()
  202. {
  203.             $global:ng_home           = (get-childitem env:NEXTGEN_SHARE_HOME).value
  204.             $global:confPath          = "$global:ng_home\conf";
  205.             $sharePropData            = Get-Content "$confPath\share.properties";
  206.             $global:shareProps        = $sharePropData -join [Environment]::NewLine | ConvertFrom-StringData ;
  207.             $global:DBUserName        = $shareProps.'nga.database.username';
  208.             $global:DBServerName      = $shareProps.'nga.database.serverName';
  209.             $nextgenCore              = LoadDllWithNoLock -filePath "$ng_home\Rosetta\NextGen.Core.dll"
  210.     [string]$global:dbpwd             = GetDecryptedString -encryptedString $global:shareProps.'nga.database.password';
  211.  
  212.             $connectionString ="server=$DBServerName; uid=$DBUserName; pwd=$dbpwd;Database='NGProd';Integrated Security=False;"
  213.             $connection = New-Object System.Data.SqlClient.SqlConnection -ErrorAction Stop
  214.             $connection.ConnectionString = $connectionString
  215.             $connection.Open()
  216.     ######################## KBM Version ##########################################
  217.     $locationquery =select  distinct TOP 1 Description,version from version limit  where product_id like '%KBM%' order by version desc"
  218.    $locationcommand = $connection.CreateCommand()
  219.    $locationcommand.CommandText = $locationquery
  220.    $locationresult = $locationcommand.ExecuteReader()
  221.    $locationdt = new-object “System.Data.DataTable”
  222.    $locationdt.Load($locationresult)
  223.    $global:loc = $locationdt.Version
  224.  
  225.    ########################## Rosetta Branch Version ##################################
  226.    $locationquery = “select option_value AS Branch from configuration_options where instance_name like '%Version.Rosetta%' and key_name like '%Branch%'"
  227.     $locationcommand = $connection.CreateCommand()
  228.     $locationcommand.CommandText = $locationquery
  229.     $locationresult = $locationcommand.ExecuteReader()
  230.     $locationdt = new-object “System.Data.DataTable”
  231.     $locationdt.Load($locationresult)
  232.     $global:loc2 = $locationdt.Branch
  233.  
  234.     ########################### Rosetta Build Version ###################################
  235.  
  236.     $locationquery =select option_value AS Build from configuration_options where instance_name like '%Version.Rosetta%' and key_name like '%Build%'"
  237.    $locationcommand = $connection.CreateCommand()
  238.    $locationcommand.CommandText = $locationquery
  239.    $locationresult = $locationcommand.ExecuteReader()
  240.    $locationdt = new-object “System.Data.DataTable”
  241.    $locationdt.Load($locationresult)
  242.    $global:loc3 = $locationdt.Build
  243.    ########################### DASHBOARD Version #########################################
  244.    
  245.    $locationquery = “select * from version where product_id='DASHHSP' order by 8 desc"
  246.     $locationcommand = $connection.CreateCommand()
  247.     $locationcommand.CommandText = $locationquery
  248.     $locationresult = $locationcommand.ExecuteReader()
  249.     $locationdt = new-object “System.Data.DataTable”
  250.     $locationdt.Load($locationresult)
  251.     $global:dashboard = $locationdt.version
  252.  
  253.     ####################### NGShare Version & HotFix #############################################################
  254.  
  255.  
  256.     $locationquery = “create table #temp_version
  257.         (
  258.         Product_id char(10),
  259.         version varchar(20),
  260.         description varchar(80),
  261.         modify_timestamp datetime
  262.         )
  263.         "
  264.        $locationcommand = $connection.CreateCommand()
  265.        $locationcommand.CommandText = $locationquery
  266.        $locationresult = $locationcommand.ExecuteReader()
  267.        $locationdt = new-object “System.Data.DataTable”
  268.        $locationdt.Load($locationresult)
  269.  
  270.  
  271.        $locationquery = “insert into #temp_version select distinct TOP 1 Product_id,version,Description,modify_timestamp  from version  where Product_id like '%HF%' and description like '%NextGen%' order by modify_timestamp ;"
  272.         $locationcommand = $connection.CreateCommand()
  273.         $locationcommand.CommandText = $locationquery
  274.         $locationresult = $locationcommand.ExecuteReader()
  275.         $locationdt = new-object “System.Data.DataTable”
  276.         $locationdt.Load($locationresult)
  277.  
  278.        
  279.  
  280.         $locationquery = “insert into #temp_version  select  distinct TOP 1 Product_id,version,Description,modify_timestamp from version   where description like '%NextGen Package%' order by version desc ;"
  281.         $locationcommand = $connection.CreateCommand()
  282.         $locationcommand.CommandText = $locationquery
  283.         $locationresult = $locationcommand.ExecuteReader()
  284.         $locationdt = new-object “System.Data.DataTable”
  285.         $locationdt.Load($locationresult)
  286.  
  287.  
  288.  
  289.         $locationquery =select top 1 * from #temp_version order by modify_timestamp; "
  290.         $locationcommand = $connection.CreateCommand()
  291.         $locationcommand.CommandText = $locationquery
  292.         $locationresult = $locationcommand.ExecuteReader()
  293.         $locationdt = new-object “System.Data.DataTable”
  294.         $locationdt.Load($locationresult)
  295.         $loc11 = $locationdt
  296.  
  297.  
  298.             If ($loc11.Product_Id -match "HF*")
  299.                 {$global:loc12 = $loc11.Description}
  300.             else
  301.                 {$global:loc12 = $loc11.Version}
  302.                # "value 4 $global:loc4"
  303.            
  304.         $locationquery = “drop table #temp_version "
  305.         $locationcommand = $connection.CreateCommand()
  306.         $locationcommand.CommandText = $locationquery
  307.         $locationresult = $locationcommand.ExecuteReader()
  308.         $locationdt = new-object “System.Data.DataTable”
  309.         $locationdt.Load($locationresult)
  310. ################################## OBJECT Creation & DB Connection Closure for Version Info #############################################################
  311.  
  312. $global:VersionInfo_Object = New-Object PSObject -Property @{
  313.        "NextGen Ambulatory EHR"                              = "$loc12"
  314.        "NextGen Practice Management"                         = "$loc12"
  315.        "NextGen Dashboard"                                   = "$dashboard"
  316.        "NextGen Document Management"                         = "$loc12"
  317.        "NextGen Knowledge Base Module"                       = "$loc"
  318.        "Pophealth"                                           =  $null
  319.        "eRx"                                                 =  $null
  320.        "NextGen Background Business Processes"               = "$loc12"
  321.        "NextGen Appointment Scheduling"                      = "$loc12"
  322.        "NextGen Real-Time Edits(NG RTE)"                     = "$loc12"
  323.        "NextGen CHC Reporting Module"                        =  $null
  324.        "NextGen Optical Management"                          = "$loc12"
  325.        "NextGen Real Time Services"                          = "$loc12"
  326.        "NextGen Remote Patient Chart Synchronization"        = "$loc12"
  327.        "NextGen RTF Document Import"                         = "$loc12"
  328.        "Case Management"                                     = "$loc12"
  329.        "Enterprise Case"                                     = "$loc12"
  330.        "Enterprise Chart"                                    = "$loc12"
  331.        "Rosetta Holding Tank(Build)"                         = "$loc3"
  332.        "Rosetta Holding Tank(Branch)"                        = "$loc2"
  333.        "Provider Approval queue"                             = "$loc12"
  334.      
  335.     }
  336.         $connection.Close()
  337.  
  338.  
  339. }
  340. ############################# Interop Services Details ########################################################
  341. Function Get-InteropServices()
  342. {
  343.             $global:ng_home           = (get-childitem env:NEXTGEN_SHARE_HOME).value
  344.             $global:confPath          = "$global:ng_home\conf";
  345.             $sharePropData            = Get-Content "$confPath\share.properties";
  346.             $global:shareProps        = $sharePropData -join [Environment]::NewLine | ConvertFrom-StringData ;
  347.             $global:DBUserName        = $shareProps.'nga.database.username';
  348.             $global:DBServerName      = $shareProps.'nga.database.serverName';
  349.             $nextgenCore              = LoadDllWithNoLock -filePath "$ng_home\Rosetta\NextGen.Core.dll"
  350.     [string]$global:dbpwd             = GetDecryptedString -encryptedString $global:shareProps.'nga.database.password';
  351.  
  352.             $connectionString ="server=$DBServerName; uid=$DBUserName; pwd=$dbpwd;Database='NGProd';Integrated Security=False;"
  353.             $connection = New-Object System.Data.SqlClient.SqlConnection -ErrorAction Stop
  354.             $connection.ConnectionString = $connectionString
  355.             $connection.Open()
  356.  
  357.         ##################### NGShare Installed or Not #####################################
  358.         If((get-childitem env:NEXTGEN_SHARE_HOME).value)
  359.         {
  360.         $locationquery =SELECT key_name FROM configuration_options WHERE app_name = 'NGSHARE ' AND instance_name = 'NextGenShare.Service'"
  361.        $locationcommand = $connection.CreateCommand()
  362.        $locationcommand.CommandText = $locationquery
  363.        $locationresult = $locationcommand.ExecuteReader()
  364.        $locationdt = new-object “System.Data.DataTable”
  365.        $locationdt.Load($locationresult)
  366.        $global:loc4 = $locationdt
  367.            If($global:loc4)
  368.                {
  369.                $global:loc5="Installed"
  370.                }
  371.  
  372.         }
  373.        else {$global:loc5="Not Installed"}
  374.        #######################  Patient Portal Installed or Not ###############################
  375.  
  376.        $locationquery = “select pl.user_id, pl.preference_id, pl.preference_value,
  377.        p.preference_name, p.group_id, p.preference_type, p.value_type
  378.        from preference_list pl, preferences p
  379.        where pl.preference_id = p.preference_id and pl.user_id= -1 and p.preference_id in (707)
  380.        "
  381.                 $locationcommand = $connection.CreateCommand()
  382.                 $locationcommand.CommandText = $locationquery
  383.                 $locationresult = $locationcommand.ExecuteReader()
  384.                 $locationdt = new-object “System.Data.DataTable”
  385.                 $locationdt.Load($locationresult)
  386.                 $global:loc6 = $locationdt
  387.  
  388.             If($loc6)
  389.             {$global:loc7="Active"} else{$global:loc7="InActive"}
  390.         ########################## HQM Installed or Not ########################################
  391.         If((Get-Service | ? {$_.Name -like 'HQMDataPush*'}) -and (Get-Service -ComputerName blrvdilities02 | ? {$_.Name -like 'HQMWatchDog*'}))
  392.         {$Global:hqmversion="Installed"}
  393.         else{$Global:hqmversion="Not Installed"}
  394. ################################## OBJECT Creation & DB Connection Closure for Interop Services #############################################################
  395.  
  396. $global:InteropServices_Object = New-Object PSObject -Property @{
  397.        "NgShare Version & hotfix"             = "$loc5"
  398.        "Patient Portal version and hotfix"    = "$loc7"
  399.        "HQM version & hotfix"                 = "$hqmversion"
  400.        
  401.      
  402.     }
  403.         $connection.Close()
  404. }
  405. ############################# System Version Details ######################################################
  406. Function Get-SystemVersionDetails()
  407. {
  408. $Global:myArray = New-Object System.Collections.ArrayList
  409.                         function SysVersionDetails($Computer,$cred)
  410.                         {
  411.                                 if((Get-WmiObject win32_computersystem).Name -eq $Computer)
  412.                                 {
  413.                                     #--------------JAVA If Machine is local------------------------#
  414.                                     If($java_version=dir "HKLM:\SOFTWARE\JavaSoft\Java Runtime Environment"  | select -expa pschildname -Last 1)
  415.            
  416.                                     {$Global:java_version|Out-Null}
  417.                                     else{$Global:java_version=$null}
  418.                                     #--------------DOTNET If Machine is local------------------------#
  419.                                     If($DotNet_version = gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' | sort pschildname -des |select -fi 1 -exp pschildname)
  420.            
  421.                                     {$Global:DotNet_version|Out-Null}
  422.                                     else{$Global:DotNet_version = $null}
  423.                                 }
  424.                                 #"printing the value of $computer"
  425.                                 #####  JAVA Version ############
  426.                                 else
  427.                                 {    
  428.                                     If($java_version=Invoke-command -ComputerName $computer -Credential $cred -ScriptBlock {dir "HKLM:\SOFTWARE\JavaSoft\Java Runtime Environment"  | select -expa pschildname -Last 1})
  429.                                             #Get-WmiObject -Class Win32_Product -ComputerName $computer -Credential $cred -Filter "Name like 'Java%'" | Select -Expand Version)
  430.    
  431.                                     {$Global:java_version|Out-Null}
  432.                                     else{$Global:java_version=$null}
  433.  
  434.                                 #####  DOTNET Version ############
  435.  
  436.                                     If($DotNet_version = Invoke-command -ComputerName $computer -Credential $cred -ScriptBlock {gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' | sort pschildname -des |select -fi 1 -exp pschildname})
  437.                                             #(Get-WmiObject win32_product -ComputerName $computer -Credential $cred | ?{$_.Name -like "Microsoft .NET Framework*"}).Version)
  438.    
  439.                                     {$Global:DotNet_version|Out-Null}
  440.                                     else{$Global:DotNet_version = $null}
  441.  
  442.                                 }
  443.                                    
  444.               ############# Object Creation for System Version Details #########################
  445.  
  446.                     $Global:System_Version_Object = [PSCustomObject]@{
  447.                             "Machine Name"        = [String]$computer                
  448.                             "Java Version"       = [String]$java_version              
  449.                             "DotNet Version"     = [String]$DotNet_version
  450.                               }              
  451.                                    
  452.    
  453.        ##-------------- End of Internal Function --------------##
  454.                         }
  455.                                      try
  456.                                      {
  457.                                       $ErrorActionPreference = 'SilentlyContinue'
  458.                                         $var1=$var.Remove($var.Length -1)
  459.                                         $parameter= @($var1)
  460.                                         $Splitted= $parameter -split ':'
  461.                                         $Length=$Splitted.Length
  462.  
  463.                                        # $arrCredentials = $parameter -split ','
  464.                                         [int32]$i=0;
  465.  
  466.                                          foreach ($splits in $Splitted)
  467.                                             {
  468.                                                 if($i -lt $Length)
  469.                                                 {
  470.                                                     $array=$splits.split(',')
  471.                                                     $Global:computer=$array[0]
  472.                                                     $username = $array[1]
  473.                                                     $password = $array[2]
  474.                                                     $secstr = New-Object -TypeName System.Security.SecureString
  475.                                                     $password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
  476.                                                     $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
  477.                                                     SysVersionDetails $computer $cred
  478.                                                     $myArray.Add($System_Version_Object) | Out-Null
  479.                                                     $i++
  480.                                                 }
  481.                                             }
  482.                                  #########################  DB PART for SQL Server Version ##########################################
  483.                                                 $global:ng_home           = (get-childitem env:NEXTGEN_SHARE_HOME).value
  484.                                                 $global:confPath          = "$global:ng_home\conf";
  485.                                                 $sharePropData            = Get-Content "$confPath\share.properties";
  486.                                                 $global:shareProps        = $sharePropData -join [Environment]::NewLine | ConvertFrom-StringData ;
  487.                                                 $global:DBUserName        = $shareProps.'nga.database.username';
  488.                                                 $global:DBServerName      = $shareProps.'nga.database.serverName';
  489.                                                 $nextgenCore              = LoadDllWithNoLock -filePath "$ng_home\Rosetta\NextGen.Core.dll"
  490.                                         [string]$global:dbpwd             = GetDecryptedString -encryptedString $global:shareProps.'nga.database.password';
  491.  
  492.                                                 $connectionString ="server=$DBServerName; uid=$DBUserName; pwd=$dbpwd;Database='NGProd';Integrated Security=False;"
  493.                                                 $connection = New-Object System.Data.SqlClient.SqlConnection -ErrorAction Stop
  494.                                                 $connection.ConnectionString = $connectionString
  495.                                                 $connection.Open()
  496.                                                 $locationquery =select @@Version as Version"
  497.                                                $locationcommand = $connection.CreateCommand()
  498.                                                $locationcommand.CommandText = $locationquery
  499.                                                $locationresult = $locationcommand.ExecuteReader()
  500.                                                $locationdt = new-object “System.Data.DataTable”
  501.                                                $locationdt.Load($locationresult)
  502.                                                $global:sqlversion = $locationdt.Version
  503.                                              
  504.                                   ###--------------- SQL Object Creation and adding it to the arraylist --------------------###            
  505.                                                $Global:SQL_Version_Object = [PSCustomObject]@{
  506.                                                               "SQL Version" = [String]$sqlversion }                  
  507.                                                                
  508.                                                $myArray.Add($SQL_Version_Object) | Out-Null
  509.                                      }
  510.                                      catch
  511.                                      {  
  512.                                        $Exception= $_.Exception.Message
  513.    
  514.                                      }
  515.  
  516. }
  517.  
  518. ################################### Network Details ########################################################
  519. Function Get-NetworkDetails()
  520. {
  521. $Global:myArrayfornetwork1=New-Object System.Collections.ArrayList
  522.                    ###-- Internal Function ---------######
  523.                     function Get-StatusFromValue($Global:computer,$cred)
  524.                     {"Writing logs"
  525.                    
  526.                                    
  527.                                    if((Get-WmiObject win32_computersystem).Name -eq $Computer)
  528.                                    {
  529.                                    "Inside Network If"
  530.                                    $Global:Network_Details=Get-WmiObject -Class win32_networkadapter |Select-Object Name,NetConnectionId,AdapterType,Speed
  531.                                    }
  532.                                    else
  533.                                    {
  534.                                    "Inside Network Else"
  535.                                    $Global:Network_Details=Get-WmiObject -Class win32_networkadapter -computer $computer -Credential $cred  |Select-Object Name, NetConnectionId,AdapterType,Speed
  536.                                    }
  537.                                #####--- Object for Network ----------#############
  538.  
  539.                                foreach($network in $Network_Details)
  540.                                {"Inside Foreach loop" +$network.Name
  541.                                $Global:name=$network.Name
  542.                                $Global:Adapter=$network.AdapterType
  543.                                $Global:speed=$network.Speed
  544.                                $Global:cid=$network.NetConnectionId
  545.                                $GLobal:machine_name= $Computer
  546.                                                    $Global:Network_Object_Details = [PSCustomObject]@{
  547.                                                            "Name"        = $Name
  548.                                                            "AdapterType"     = $adapter
  549.                                                            "Speed(bps)"   =$speed
  550.                                                            "NetConnectionID" = $cid
  551.                                                              }
  552.                                                                    
  553.                                 }
  554.                            
  555.                             $Global:Network_Object = [PSCustomObject]@{
  556.                                                            "Machine Name" =$machine_name
  557.                                                            "Network Details" = $Network_Object_Details
  558.                                                              }
  559.                                          $myArrayfornetwork1.Add($Network_Object)
  560.                      }#end Get-StatusFromValue function
  561.                             # *** Entry point to script ***
  562.                                    try
  563.                                    {
  564.                                    $ErrorActionPreference = 'SilentlyContinue'
  565.                                    $var1=$var.Remove($var.Length -1)
  566.                                    $parameter= @($var1)
  567.                                    $Splitted= $parameter -split ':'
  568.                                    $Length=$Splitted.Length
  569.  
  570.                                    # $arrCredentials = $parameter -split ','
  571.                                    [int32]$i=0;
  572.  
  573.                                        foreach ($splits in $Splitted)
  574.                                        {
  575.                                            if($i -lt $Length)
  576.                                            {
  577.                                                $array=$splits.split(',')
  578.                                                $Global:computer=$array[0]
  579.                                                $username = $array[1]
  580.                                                $password = $array[2]
  581.                                                $secstr = New-Object -TypeName System.Security.SecureString
  582.                                                $password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
  583.                                                $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
  584.                                                Get-StatusFromValue $computer $cred
  585.                                                #$myArrayfornetwork.Add($Network_Object) | Out-Null
  586.                                                $i++
  587.                                            }
  588.                                        }
  589.                                    }
  590.                                    catch
  591.                                {$Exception_Message = $_.Exception.Message}
  592.                        
  593. }
  594. ############################### Error Message Function to catch the Exceptions ##################################
  595. function Get-ErrorMessage()
  596. {
  597.    $error_object = [ordered] @{
  598.    machineName =$server
  599.    Error =$_.Exception.Message
  600.    }
  601. $errorMessage=ConvertTo-Json $error_object -depth 4 -compress
  602.    return $errorMessage
  603.  
  604. }
  605. #################################### Main Script Block ############################################################
  606. #################################### try block for calling all the functions and creating the final Object ############################
  607. try
  608. {
  609. <#
  610. $global:out1
  611. workflow trigger-functions {
  612.    parallel {
  613.    
  614.    $Using:out1= InlineScript {Get-ClinetInfo}
  615.     InlineScript {Get-LicenseInfo}
  616.     InlineScript {Get-VersionInfo}  
  617.        Checkpoint-Workflow
  618.                     "my out 1 is $out1"
  619.                     }
  620.     trigger-functions
  621. }#>
  622.   Get-ClinetInfo
  623.   Get-LicenseInfo
  624.   Get-VersionInfo
  625.   Get-InteropServices
  626.   Get-SystemVersionDetails
  627.   Get-NetworkDetails
  628.   #$hardware_values=Get-HardwareInfo
  629.    $global:Core_Object = New-Object PSObject -Property @{
  630.    "Client Details"             = $ClinetInfo_Object
  631.    "License Details"            = $encryptedKeys
  632.    "Hardware Details"           = Get-HardwareInfo
  633.    "Network Details"            = $myArrayfornetwork1
  634.    "Version Details"            = $VersionInfo_Object
  635.    "Interop Services"           = $InteropServices_Object
  636.    "SystemVersion Details"      = $myArray
  637.    }
  638. ############################# JSON Conversion ###########################################################
  639. $Core_Object | ConvertTo-Json -Depth 12 -Compress
  640. }
  641. ########################### Catch Block for capturing the Error ######################################################
  642. Catch
  643. {
  644. Get-ErrorMessage
  645. }
Add Comment
Please, Sign In to add comment