diff --git a/TPDT-268 - ACP in task sequence/20_update_system_site_centrale.sql b/TPDT-268 - ACP in task sequence/20_update_system_site_centrale.sql
index ebf73c3..1fc18d5 100644
--- a/TPDT-268 - ACP in task sequence/20_update_system_site_centrale.sql
+++ b/TPDT-268 - ACP in task sequence/20_update_system_site_centrale.sql
@@ -6,7 +6,7 @@ Update central system_site values for a specific OU
Parameters
----------------------
In script parameters updated from Powershell are present:
- @ou_id The id ofthe OU we need to update. This id is fetched from the local machine being migrated.
+ @ou_id The id of the OU we need to update. This id is fetched from the local machine being migrated.
@fqdn The FQDN of the machine being migrated to Azure. This is fetched from a DNS request, not built.
@alias The alias of the machine being migrated to Azure. This is logically built from the FQDN
@@ -20,38 +20,14 @@ Creation : 04.03.2024 / TSC
Modifications:
07.03.2024 TSC Rewrote to connect to the central through the pharmacy linked server ArizonaCash
The values in the local pharmacy are updated as well
+ 15.03.2024 TSC Went back to a local update. this script will be run both locally and on the central from the powershell executing it
=============================================================================*/
USE [master];
-DECLARE @ou_id INT;
+DECLARE @ou_id INT = $ou_id;
DECLARE @fqdn VARCHAR(100) = '$fqdn';
DECLARE @alias VARCHAR(100) = '$alias';
-EXECUTE [Arizona].[dbo].[sp_bmc_Bmc_Applic_Default]
- @in_job_type = 3,
- @in_param_int_1 = NULL, /* Company */
- @in_param_int_2 = NULL, /* Subsidiary */
- @in_param_varchar_1 = 'cvCurrentOrganizationalUnit',
- @out_default_value = @ou_id OUTPUT,
- @out_param_int_1 = NULL;
-
---central
-UPDATE ss
- SET [ss].[SS_server_name] = @alias
- , [ss].[SS_IP_server_address] = @alias
- , [ss].[SS_domain_name] = @fqdn
-FROM [arizonaCash].[arizona].[dbo].[Organizational_unit] ou
- JOIN [arizonaCash].[arizona].[dbo].[System_site] ss ON ss.[System_site_ID] = ou.[OU_system_site]
-WHERE ou.[Organizational_unit_ID] = @ou_id;
-
-UPDATE ssi
- SET [ssi].[SSSI_SQL_instance_name] = @alias+'\APSSQL'
-FROM [arizonaCash].[arizona].[dbo].[Organizational_unit] ou
- JOIN [arizonaCash].[arizona].[dbo].[System_site] ss ON ss.[System_site_ID] = ou.[OU_system_site]
- JOIN [arizonaCash].[arizona].[dbo].[System_site_SQL_instance] ssi ON ssi.[SSSI_system_site] = ss.[System_site_ID]
-WHERE ou.[Organizational_unit_ID] = @ou_id;
-
---local
UPDATE ss
SET [ss].[SS_server_name] = @alias
, [ss].[SS_IP_server_address] = @alias
diff --git a/TPDT-268 - ACP in task sequence/21_update_point_of_sale_centrale.sql b/TPDT-268 - ACP in task sequence/21_update_point_of_sale_centrale.sql
index 1a97d4c..c27e09c 100644
--- a/TPDT-268 - ACP in task sequence/21_update_point_of_sale_centrale.sql
+++ b/TPDT-268 - ACP in task sequence/21_update_point_of_sale_centrale.sql
@@ -6,7 +6,7 @@ Update central system_site values for a specific OU
Parameters
----------------------
In script parameters updated from Powershell are present:
- @ou_id The id ofthe OU we need to update. This id is fetched from the local machine being migrated.
+ @ou_id The id of the OU we need to update. This id is fetched from the local machine being migrated.
@fqdn The FQDN of the machine being migrated to Azure. This is fetched from a DNS request, not built.
@mac The MAC address fetched from the local machine
@@ -20,29 +20,14 @@ Creation : 04.03.2024 / TSC
Modifications:
07.03.2024 TSC Rewrote to connect to the central through the pharmacy linked server ArizonaCash
The values in the local pharmacy are updated as well
+ 15.03.2024 TSC Went back to a local update. this script will be run both locally and on the central from the powershell executing it
=============================================================================*/
USE [master];
-DECLARE @ou_id INT;
+DECLARE @ou_id INT = $ou_id;
DECLARE @fqdn VARCHAR(100) = '$fqdn';
DECLARE @mac VARCHAR(100) = '$mac';
-EXECUTE Arizona.[dbo].[sp_bmc_Bmc_Applic_Default]
- @in_job_type = 3,
- @in_param_int_1 = NULL, /* Company */
- @in_param_int_2 = NULL, /* Subsidiary */
- @in_param_varchar_1 = 'cvCurrentOrganizationalUnit',
- @out_default_value = @ou_id OUTPUT,
- @out_param_int_1 = NULL;
-
---central
-UPDATE ps
- SET [ps].[POS_MAC_address] = @mac
- , [ps].[POS_hostname] = @fqdn
-FROM [arizonaCash].[arizona].[dbo].[Point_of_sale] ps
-WHERE [ps].[POS_organizational_unit] = @ou_id
-AND [ps].[POS_number]=99;
-
--local
UPDATE ps
SET [ps].[POS_MAC_address] = @mac
diff --git a/TPDT-268 - ACP in task sequence/9_Update_FTPLogin_Central.sql b/TPDT-268 - ACP in task sequence/9_Update_FTPLogin_Central.sql
index 3023aa4..dfddd98 100644
--- a/TPDT-268 - ACP in task sequence/9_Update_FTPLogin_Central.sql
+++ b/TPDT-268 - ACP in task sequence/9_Update_FTPLogin_Central.sql
@@ -1,67 +1,46 @@
-/*=============================================================================
-
-Update the ftp password in system_site_transfert table on the central from a pharmacy, for this pharmacy
-
-Parameters
-----------------------
-
-
-Context
-----------------------
-This script is run in a pharmacy, during the preparation / migration of the pharmacy
-
-Creation : 07.03.2024 / TSC
-Modifications:
-
-=============================================================================*/
-IF EXISTS ( SELECT 1
- FROM [ARIZONACASH].[Arizona].[dbo].[System_site] SS
- JOIN [ARIZONACASH].[Arizona].[dbo].[System_site_transfer] SST
- ON [SST].[SST_dest_system_site] = [SS].[System_site_ID]
- WHERE [SS].[SS_server_name] = '$fqdn'
- AND [SST].[SST_bmc_task] = 109)
+IF EXISTS ( SELECT 1
+ FROM [Arizona].[dbo].[System_site] SS
+ JOIN [Arizona].[dbo].[System_site_transfer] SST
+ ON SST.SST_dest_system_site = SS.System_site_ID
+ WHERE SS.SS_server_name = '$fqdn'
+ AND SST.SST_bmc_task = 109)
BEGIN
-
- UPDATE [ARIZONACASH].[Arizona].[dbo].[System_site_transfer]
- SET [SST_connection_info] = ''
- FROM [ARIZONACASH].[Arizona].[dbo].[System_site] SS
- JOIN [ARIZONACASH].[Arizona].[dbo].[System_site_transfer] SST
- ON [SST].[SST_dest_system_site] = [SS].[System_site_ID]
- WHERE [SS].[SS_server_name] = '$fqdn';
-
+ UPDATE [Arizona].[dbo].[System_site_transfer]
+ SET SST_connection_info = ''
+ FROM [Arizona].[dbo].[System_site] SS
+ JOIN [Arizona].[dbo].[System_site_transfer] SST
+ ON SST.SST_dest_system_site = SS.System_site_ID
+ WHERE SS.SS_server_name = '$fqdn';
END;
ELSE
BEGIN
-
- IF EXISTS ( SELECT 1
- FROM [ARIZONACASH].Arizona.[dbo].[System_site]
- WHERE [SS_server_name] = '$fqdn')
- BEGIN
-
- UPDATE [ARIZONACASH].Arizona.[dbo].[Bmc_ID_counter]
- SET [BMCID_last_number] = ( SELECT [BMCID_last_number] + 1
- FROM [ARIZONACASH].Arizona.[dbo].[Bmc_ID_counter]
- WHERE [BMCID_key] = 'system_site_transfer')
- FROM [ARIZONACASH].Arizona.[dbo].[Bmc_ID_counter]
- WHERE [BMCID_key] = 'system_site_transfer';
-
- INSERT INTO [ARIZONACASH].[Arizona].[dbo].[System_site_transfer] ([System_site_transfer_ID],
- [SST_source_system_site],
- [SST_dest_system_site],
- [SST_bmc_task],
- [SST_transfer_type],
- [SST_VGUID],
- [SST_master_ID],
- [SST_connection_info],
- [SST_start_date],
- [SST_end_date])
- VALUES (( SELECT [BMCID_last_number]
- FROM [ARIZONACASH].Arizona.[dbo].[Bmc_ID_counter]
- WHERE [BMCID_key] = 'system_site_transfer'), 102, ( SELECT [System_site_ID]
- FROM [ARIZONACASH].Arizona.[dbo].[System_site]
- WHERE [SS_server_name] = '$fqdn'), 109, 1, DEFAULT,
- NULL, '',
- (SELECT CONVERT(CHAR(10), GETDATE(), 126)), NULL);
-
- END;
-END;
+ IF EXISTS ( SELECT 1
+ FROM Arizona.dbo.System_site
+ WHERE SS_server_name = '$fqdn')
+ BEGIN
+ UPDATE Arizona.dbo.Bmc_ID_counter
+ SET BMCID_last_number = ( SELECT BMCID_last_number + 1
+ FROM Arizona.dbo.Bmc_ID_counter
+ WHERE BMCID_key = 'system_site_transfer')
+ FROM Arizona.dbo.Bmc_ID_counter
+ WHERE BMCID_key = 'system_site_transfer';
+ INSERT INTO [Arizona].[dbo].[System_site_transfer] ([System_site_transfer_ID],
+ [SST_source_system_site],
+ [SST_dest_system_site],
+ [SST_bmc_task],
+ [SST_transfer_type],
+ [SST_VGUID],
+ [SST_master_ID],
+ [SST_connection_info],
+ [SST_start_date],
+ [SST_end_date])
+ VALUES (( SELECT BMCID_last_number
+ FROM Arizona.dbo.Bmc_ID_counter
+ WHERE BMCID_key = 'system_site_transfer'), 102, ( SELECT System_site_ID
+ FROM Arizona.dbo.System_site
+ WHERE SS_server_name = '$fqdn'), 109, 1,
+ DEFAULT, NULL,
+ '',
+ (SELECT CONVERT(CHAR(10), GETDATE(), 126)), NULL);
+ END;
+END;
\ No newline at end of file
diff --git a/TPDT-268 - ACP in task sequence/acp_auto.ps1 b/TPDT-268 - ACP in task sequence/acp_auto.ps1
index 8790725..4006a2b 100644
--- a/TPDT-268 - ACP in task sequence/acp_auto.ps1
+++ b/TPDT-268 - ACP in task sequence/acp_auto.ps1
@@ -143,6 +143,7 @@ $keyVaultName = "kv-ApoLsPoc-Tde"
$secretFtpPassword ="centralinfra---svc-APH-trans"
$secretMasterKey ="MasterKey"
$secretTriaPharmSQLCert = "TriaPharmSQLCert"
+$secretSqlAzureMigration = "sqlAzureMigration"
# Convert the client secret to a secure string
$securePassword = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
@@ -153,9 +154,11 @@ $psCred = New-Object System.Management.Automation.PSCredential -ArgumentList $cl
# Authenticate using the service principal
$null = Connect-AzAccount -ServicePrincipal -Credential $psCred -TenantId $tenantId
-# Get the secret from Azure Key Vault
-# $secret = Get-AzKeyVaultSecret -VaultName $keyVaultName -Name $secretName
-# write-host "domain: $($ua.Tags["domain"])"
+# Get the login for sqlAzureMigration from Azure Key Vault
+$secret_central = Get-AzKeyVaultSecret -VaultName $keyVaultName -Name $secretSqlAzureMigration
+$login_central = "sqlAzureMigration"
+$psCredCentral = New-Object System.Management.Automation.PSCredential($login_central, $secret_central.SecretValue)
+
# Display the secret value
#Write-Host "Secret Value: $($secret.SecretValue | ConvertFrom-SecureString -AsPlainText)"
@@ -308,55 +311,14 @@ if($true -eq $checkoutGit){
#$instanceReachable = $false
if($true -eq $instanceReachable){
- ##fetch OU details from control center
- ## CLA: can be ignored due to SWITCH directly after this QUERY
- <#
- $query=@"
- SELECT LOWER([SERV].[SE_DNS]) AS SE_DNS,
- CASE
- WHEN UPPER(LEFT([SERV].[SE_DNS], 3)) = 'SCV' THEN 'CVI'
- WHEN UPPER(LEFT([SERV].[SE_DNS], 3)) = 'SSU' THEN 'SUN'
- WHEN UPPER(LEFT([SERV].[SE_DNS], 3)) = 'SAM' THEN 'AMA'
- ELSE UPPER(LEFT([SERV].[SE_DNS], 3))END AS [customer],
- CASE
- WHEN UPPER([SERV].[SE_designation]) LIKE '%ACCEPTANCE%' THEN 'ACCE'
- WHEN UPPER([SERV].[SE_designation]) LIKE '%FORMATION%' THEN 'FORM'
- WHEN UPPER([SERV].[SE_designation]) LIKE '%SCHULUNG%' THEN 'FORM'
- ELSE 'PROD' END AS [context],
- LEFT(LTRIM([cfg].[CF_value]), 4) AS [version],
- LOWER([SERV].[SE_DNS] + '\' + [SERV].[SE_instance_name]) AS [aliasInstance]
- FROM [ControlCenter].[dbo].[Server] SERV
- JOIN [ControlCenter].[dbo].[Config] cfg
- ON [cfg].[CF_server] = [SERV].[SE_id]
- JOIN [ControlCenter].[dbo].[ConfigType] cfgt
- ON [cfgt].[CFTY_id] = [cfg].[CF_configtype]
- JOIN [ControlCenter].[dbo].[Entity] ent
- ON [ent].[EN_id] = [SERV].[SE_entity]
- WHERE [cfgt].[CFTY_type] = 'TriaPharmVersion'
- AND [SERV].[SE_status] = 1
- AND ( ([SERV].[SE_end_prod_date] > GETDATE())
- OR ([SERV].[SE_end_prod_date] IS NULL))
- AND [SERV].[SE_designation] NOT LIKE '%Fermé%'
- AND [SERV].[SE_designation] NOT LIKE '%REF%'
- AND [ent].[EN_code] IN ( 'AMA', 'SUN', 'CVI' )
- AND LOWER([SERV].[SE_DNS]) LIKE '$alias%'
- ORDER BY [SERV].[SE_entity],
- SE_DNS;
-"@ #>
-
- # $dbacc = Invoke-Sqlcmd -ServerInstance hcimon -Database ControlCenter -Query $query
- if($null -eq $dbacc){
- Write-Output "No results in HCIMON, faking them"
- $dbacc = New-Object psobject
- #$dbacc | Add-Member -MemberType NoteProperty -Name "context" -Value "DEVE"
- $dbacc | Add-Member -MemberType NoteProperty -Name "context" -Value $ContextType
- $dbacc | Add-Member -MemberType NoteProperty -Name "customer" -Value $customer
- $dbacc | Add-Member -MemberType NoteProperty -Name "version" -Value -1
- $dbacc | Add-Member -MemberType NoteProperty -Name "SE_DNS" -Value $hostname
- $dbacc | Add-Member -MemberType NoteProperty -Name "aliasInstance" -Value $sqlVariables
+ $dbacc = New-Object psobject
+ $dbacc | Add-Member -MemberType NoteProperty -Name "context" -Value $ContextType
+ $dbacc | Add-Member -MemberType NoteProperty -Name "customer" -Value $customer
+ $dbacc | Add-Member -MemberType NoteProperty -Name "version" -Value -1
+ $dbacc | Add-Member -MemberType NoteProperty -Name "SE_DNS" -Value $hostname
+ $dbacc | Add-Member -MemberType NoteProperty -Name "aliasInstance" -Value $sqlVariables
- }
##step 1: configure SQL instance max memory
Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -InputFile .\1_Configure_InstanceMemory.sql
Write-Output "Executed 1_Configure_InstanceMemory.sql"
@@ -392,10 +354,9 @@ if($true -eq $instanceReachable){
$query = $query.Replace("`$fqdn", $alias)
#Invoke-Sqlcmd -ServerInstance gcmPrdCent -Database arizona -Query $query
- Invoke-Sqlcmd -ServerInstance $SqlInstance -Database arizona -Query $query
+ Invoke-Sqlcmd -ServerInstance $CentraleServer -Database arizona -Query $query -Credential $psCredCentral
Write-Output "Executed 9_Update_FTPLogin_Central.sql"
-
##step 6: execute all DBA packages
$LogFile = "C:\Temp\DBApackagesCLA.log"
@@ -532,21 +493,44 @@ if($true -eq $instanceReachable){
##step 20: update system_site on the central
$fqdn = [System.Net.Dns]::GetHostByName($alias)
+ #Get pharmacy OU_id
+ $query=@"
+ USE [master];
+
+ DECLARE @ou_id INT;
+
+ EXECUTE [Arizona].[dbo].[sp_bmc_Bmc_Applic_Default]
+ @in_job_type = 3,
+ @in_param_int_1 = NULL, /* Company */
+ @in_param_int_2 = NULL, /* Subsidiary */
+ @in_param_varchar_1 = 'cvCurrentOrganizationalUnit',
+ @out_default_value = @ou_id OUTPUT,
+ @out_param_int_1 = NULL;
+
+ SELECT @ou_id as ou_id
+"@
+ $ou_dataset = Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -Query $query
+
+
#update the centrale
$query=Get-Content -Path .\20_update_system_site_centrale.sql
$query = $query.Replace("`$fqdn", $fqdn.HostName)
$query = $query.Replace("`$alias", $alias)
+ $query = $query.Replace("`$ou_id", $ou_dataset.ou_id)
Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -Query $query
- Write-Output "Executed 20_update_system_site_centrale.sql"
+ Write-Output "Executed 20_update_system_site_centrale.sql locally"
- ##step 21: update Point_of_sale on the central
+ Invoke-Sqlcmd -ServerInstance $CentraleServer -Database master -Query $query -Credential $psCredCentral
+ Write-Output "Executed 20_update_system_site_centrale.sql on the central $CentraleServer"
+
+ ##step 21: update Point_of_sale
#fetch a list of mac adresses
$macs = @{}
$pos = 0
- Get-NetAdapter | Select-Object ifIndex, Name, MacAddress | ForEach-Object {
- $macs.Add($pos, $_.MacAddress)
+ Get-NetAdapter | Where-Object -Property status -eq up | Group-Object -Property MacAddress | ForEach-Object {
+ $macs.Add($pos, $_.Name)
$pos++
}
@@ -556,11 +540,12 @@ if($true -eq $instanceReachable){
exit 42102
}
else{
- $query=Get-Content -Path .\21_update_point_of_sale_centrale.sql
- $query = $query.Replace("`$fqdn", $fqdn.HostName)
- $query = $query.Replace("`$mac", $macs[0].value)
+ $query=Get-Content -Path C:\Users\ua208700\Documents\21_update_point_of_sale_centrale.sql
+ $query = $query.Replace("`$fqdn", $hostname)
+ $query = $query.Replace("`$mac", $macs[0])
- Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -Query $query
+ #Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -Query $query
+ Write-Output $query
Write-Output "Executed 21_update_point_of_sale_centrale.sql"
}