functions/public/Add-DiscoveryRegistrationSql.ps1
function Add-DiscoveryRegistrationSql { [CmdletBinding()] param ( $discoveryPostBody, $connectionString ) if ($null -eq $discoveryPostBody.isHidden){ $discoveryPostBody.isHidden = $true } if ($null -eq $discoveryPostBody.iconTxt){ $discoveryPostBody.iconTxt = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGwAAABsCAYAAACPZlfNAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTZEaa/1AAARf0lEQVR4Xu2deYyURRrGXV3dqHHVGHc12XjsJhv/UGM8spt4ZDUeCN73bVSIGo8ooKgIion3hSDHeCHXDMoxHiOKcigiCoo3qMBwDAJeIIjAOAxT+/xqqoZv+pqe7q+756gnedPd31Ff1fvU8b5vVX29XUBAQEB6vPzyyztNnDjxH+PHjz9U34/R58kvvfRSN4TvHCsvLz+Ua7jW3RZQaEyZMmXXcePGHSUiekgGS6ZJlku2igiTjejaen0uc/cO0vfuIvXIUaNG7eoeE5ArysrKdnQE9ZNiZ+lzs1c8MmHCBPPKK6+Yd955x8yaNcvMnTvXfPbZZ+bLL780X3/9tRW+c4xz77//vr2We7g3mpbS3qTPmZK7JUfMmDHjzy4bAZkgZe1QUVFxrBRIC1qNMhG1AvPWW2+Zjz/+2FRXV5s1a9aYP/74w+QK7iUN0iJN0uYZ/nl69irJIFWYo++5557tXfYCPDS+/E0K6y0lLfJKoyV8+OGHZtmyZXmRky1qa2vN0qVL7TMrKyuj5C3UZy997u2y23khJRwoGSqhS7Jd1QcffGBWrlxp6uvrnSqLD579/fff267WtzzlcaNksMg8wGW/82DMmDH7q/BlUkQdynj99dfN/PnzzebNm53K2g42bdpk8/baa6/5VlcrGSbZzxWn40Ld3G4iaoAKaw2IN954w44jW7dudeppuyCP5JU8k3d6BUn/DmthagDvqgIup7CvvvqqWbx4cbsgKhHkedGiRbYM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kMG/lnffPON/R0F6aQ7995775k5c+a4X82B0r799lszadIkM3r0aKvAH374wZ1tBGmSdir55Zdf3FW5AQ7QhxrQIY6eZOhkDy6KI3ZIP3ziiSeaa665xlo+HuzW79atW5Oy165da2644QZz8cUXmyeeeMI8/fTT5rrrrjPnn39+xqUI5513niUeUCl41rXXXmt/R0FvcdJJJ5mhQ4e6I43g+eTjjDPOML///rs72gjyKMfVnHPOOebhhx82Q4YMMXfccYc59dRT7e4UD45fdNFF5sEHH0wSyp8PIrHFHo6eZOik9b+YCc0XZPi0004zN954oxk1apQ72pwwavGdd95pbrnllmYtithlWVmZOffcc5u1xCgSCUOZl156qZ2q8CD9m2++2VxxxRVJhD333HPm/vvvNzfddJNtRVHw7MsuuyxJD3J5zPXXX2/LACDsrrvust/jBi3UEZbeH9PJaYSj4jA4IKxr167mu+++s7UYhxBECWP1ELU/VbySkNiZZ55pu6JUSEXYsGHDzJNPPmmPgZqaGnvd448/3owwykcL/vTTT236PXr0aFqnwrmzzjrLTne0hEIShp4gTDLV0ZMMEbYchzkOQBhKBM8884xtRSglShivFILUdA76rbfemtQyPFIRRjdy9tlnN1W4F154wQwaNMgMHDiwWTos5qTVkR+6QyrGggUL7DmW71GJosMC+SPfXnx+IYyu/LHHHmsmlDcO0PLFyRJHT3OIyZ10ciurouJAlDC6NbqYqqqqZoQx4ENYuumb3r17t4ow0qGLY0MdyxlQJoqPEua7Sbq99evXW3nggQesAN/qo4TxZhzy6cW3egi7+uqr7cb0qDDhGwfcqqraTz75ZEdH0zZMbHw9nX2JVhyIEgawehjEV69e3UTYqlWrrHKwxhKBwmktkJwKqQgDKKtnz572ed4IiRLGUodTTjnFph0ViPjtt99shUrsEjnGOYQ0/blCdokALkRYvazU5LUectR436DtpuJAImHgoYceMn379jWnn356k9GBcrHAErtFajWKpAWkQjrC1q1bZ9Pv169fkzERJYwukjzwPC9UDqxZyg8g4vLLL096Nl3tlVde2VSJCk0YXChPvC7jIEfTNujEMWQYfygOpCIMq4tW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CPOO0fcwakRmRj3iLJ3k59pYEywL9H1ATSkkHL8mRJ+HO3/ZzaSgv+VNqTRvcYxrRGsiJhp6XS0b+cutoGmBZQxmz3iCHSma1Hyh4xMBbps220rEQoY/sog3PIKGvXO6Ofhp+Fu+PIml3yMasllJWV7aJMTiDDOIgsye4soKyU2ZE1rmTWYGvh/DSca/761g68HTlgTNmIDVJWlbtO5e6lw8X1s+KACnCsCoB1ZCPTcWwUbGugTC7qjlQXLdxUKKgQu0tGi7gGaiBWZBxbcksNyoAV6IK4W1W+EQUP5BYTKhDzadXURPp51oi0R0uSPLMGw03rI4tFWmHms0oNEbaz5F7JBgrLSiGW0OWyw6PYII8sRSPPjijWYNzdbgyLfDBx4sR9RdpwCQO0bXGsMG6LbgB5YkWub1HKc61kiL7Hs2CmPYE/6FThWaxKbbXjARsw2MFRylbH6jDyQF7cGIWskzyV97rBjoDKyso9RBx/4bhAnw0oiD1SbCpkNyK1vJDhLtLmGTyLKI3bn0Vr4m/n50t65rx8uiMD/41/ppOCBklWoDSEWs4uS95uwJjHDs1c92AD7mXrLWMSuyhZ2RxpSUiNnj+QLT+6vP35U6UAipLCDpfy2HM9XcIfx0SVarfQ4gOxpwrF4zLgpDPmIHznGOe4hmu5JzEdkbNGMk3SV78PCyTFACmSl5cdIukhoQWi4CUSjADeeGa70jRC11bvrq2WTNWxp1QhuksO1vfMr1YIiA+8hF/jy74yBg5St0Z3eoIEnw85gWOcEyn7pH0rWkBAQICw3Xb/B+xpzGHxSTPuAAAAAElFTkSuQmCC" } $query = "DECLARE @InsertBuildNumberTXT nvarchar(100) = '' DECLARE @InsertListBuildNumberTXT nvarchar(50) = '' DECLARE @UpdateBuildNumberTXT nvarchar(100) = '' DECLARE @InsertOrUpdateService varchar(max) = '' IF EXISTS (SELECT * FROM sys.columns WHERE name = 'BuildNumberTXT' AND OBJECT_ID = OBJECT_ID('CatalystAdmin.DiscoveryServiceBASE')) BEGIN SET @InsertBuildNumberTXT = ',''' + @BuildNumberTXT + ''''; SET @InsertListBuildNumberTXT = ',[BuildNumberTXT]'; SET @UpdateBuildNumberTXT = ',BuildNumberTXT = ''' + @BuildNumberTXT + ''''; END IF EXISTS ( SELECT * FROM [CatalystAdmin].[DiscoveryServiceBASE] WHERE ServiceNM = @ServiceNM AND ServiceVersion = @ServiceVersion ) BEGIN SET @InsertOrUpdateService = ' UPDATE [CatalystAdmin].[DiscoveryServiceBASE] SET [ServiceUrl] = ''' + @ServiceUrl + ''', DiscoveryTypeCD = ''' + @DiscoveryTypeCD + ''', HiddenFLG = ' + CAST(@HiddenFLG AS NVARCHAR(1)) + ', FriendlyNM = ''' + @FriendlyNM + ''', IconTXT = ''' + @IconTXT + ''', DescriptionTXT = ''' + @DescriptionTXT + '''' + @UpdateBuildNumberTXT + ' WHERE ServiceNM = ''' + @ServiceNM + ''' AND ServiceVersion = ' + CAST(@ServiceVersion AS NVARCHAR(1)) + ';' END ELSE BEGIN SET @InsertOrUpdateService = ' INSERT INTO [CatalystAdmin].[DiscoveryServiceBASE] ([ServiceNM], [ServiceUrl], [ServiceVersion], [DiscoveryTypeCD], [HiddenFLG], [FriendlyNM], [IconTXT], [DescriptionTXT]' + @InsertListBuildNumberTXT + ' ) VALUES (''' + @ServiceNM + ''',''' + @ServiceUrl + ''',' + CAST(@ServiceVersion AS NVARCHAR(20)) + ',''' + @DiscoveryTypeCD + ''',' + CAST(@HiddenFLG AS NVARCHAR(1)) + ',''' + @FriendlyNM + ''',''' + @IconTXT + ''',''' + @DescriptionTXT + '''' + @InsertBuildNumberTXT + ' );' END EXEC(@InsertOrUpdateService);" Invoke-Sql -connectionString $connectionString -sql $query ` -parameters @{ServiceNM=$($discoveryPostBody.serviceName);` ServiceVersion=$($discoveryPostBody.serviceVersion);` ServiceUrl=$($discoveryPostBody.serviceUrl);` DiscoveryTypeCD=$($discoveryPostBody.discoveryType);` FriendlyNM=$($discoveryPostBody.friendlyName);` DescriptionTXT=$($discoveryPostBody.description);` BuildNumberTXT=$($discoveryPostBody.buildVersion);` HiddenFLG=$($discoveryPostBody.isHidden);` IconTXT=$($discoveryPostBody.iconTxt)} } |