Hello all,
I have been working on a script to assign AppInsight for SQL to nodes using the API. There was a great starter script on the GitHub but I'm running into a strange issue. When running the script I'm getting it to fully execute but it will only execute with a result of -1 regardless of setting the duplication flag as true or false. Nothing shows up in the SWIS logs nor the APM businesslayer logs to help me investigate this. I was even trying to change up how some of the script was putting the info together just in case it was a weird formatting bug but I've not come to any conclusions on that. Where should I look next?
Import-Module SwisPowerShell $username = "REMOVED" $SecurePassword = ConvertTo-SecureString -AsPlainText -Force -String "REMOVED" $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $Securepassword $hostname = "REMOVED" $swis = Connect-Swis -host $hostname -cred $Cred <# $appSettings = @{}; #$appSettings.Add('InstanceName', ''); #instance name is not required, if not specified than default instance name will be used $appSettings.Add('PortType', 'default'); #default or static, when static than PortNumber needs to be set $appSettings.Add('PortNumber', '1433'); #> $appSettings = @{ #InstanceName = '' PortType = 'default' #PortNumber = '1433' } $swis = Connect-Swis -host $hostname -cred $cred $nodeId = 13542 $credentialSetId = 50 #-3 means take it from node $template = "AppInsight for SQL" $applicationTemplateId = Get-SwisData $swis "SELECT ApplicationTemplateID FROM Orion.APM.ApplicationTemplate WHERE Name=@template" @{ template = $template } if (!$applicationTemplateId) { Write-Host "Can't find template with name '$template'." exit 1 } Write-Host "Creating application on node '$nodeId' using template '$applicationTemplateId' and credential '$credentialSetId'." $applicationId = (Invoke-SwisVerb $swis "Orion.APM.Application" "CreateApplication" @( $nodeId, $applicationTemplateId, $credentialSetId, "true", $appSettings )).InnerText # Check if the application was created if ($applicationId -eq -1) { Write-Host "Application wasn't created. Likely the template is already assigned to node and the skipping of duplications are set to 'true'." #exit 1 } else { Write-Host "Application created with ID '$applicationId'." }
Maybe tdanner or KMSigma.SWI might have answered this many times and I can't google to for the life of me ;)