/*============================================================================= 
TPDT-283

Update central system_site values for a specific OU

Parameters
----------------------
In script parameters updated from Powershell are present:
    @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

Context
----------------------
This script is called from a powershell in the task sequence during the migration to Azure.
The excution context is the local pharmacy being moved to Azure, but updating the central via the linked server arizonaCash.
It ensure that the point_of_sale table reflect the new hostname and mac address of the machine migrating to Azure

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 = $ou_id; 
DECLARE @fqdn VARCHAR(100) = '$fqdn';
DECLARE @mac VARCHAR(100) = '$mac';

--local
UPDATE ps
    SET [ps].[POS_MAC_address] = @mac
    , [ps].[POS_hostname]      = @fqdn
FROM [arizona].[dbo].[Point_of_sale] ps
WHERE [ps].[POS_organizational_unit] = @ou_id
AND [ps].[POS_number]=99;