15 Replies Latest reply on Sep 13, 2017 3:24 PM by stuartwhyte

    Executing NCM script with PowerShell


      I'm just starting to get my head around the powershell/sdk goodness and have a few queries based on the example here: https://github.com/solarwinds/OrionSDK/blob/master/Samples/PowerShell/NCM.ExecuteScript.ps1.




      If I configure the logon as username password :


      $hostname = "MyOrionServerName"
      $username = "MyUSerName"
      $plainpass = "MyPlainTextPassword"
      $swis = Connect-Swis -v2 -host $hostname -username $username -password $plainpass


      The script completes and produces the results as expected.


      However, I'd rather not have plain text username/password combination in my script, so changing to certificate based credentials, and running the script in ISE as administrator:


      $hostname = "MyOrionServerName"
      $username = "MyUSerName"
      $swis = Connect-Swis -Certificate


      I get the error:


      Invoke-SwisVerb : System.Data.SqlClient.SqlException --> String or binary data would be truncated.
      The statement has been terminated.
      At C:\scripts\NCM.ps1:45 char:1
      + Invoke-SwisVerb $swis Cirrus.ConfigArchive Execute @($nodeIdList, $script, $user ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [Invoke-SwisVerb], FaultException`1
          + FullyQualifiedErrorId : SwisError,SwisPowerShell.InvokeSwisVerb

      at this:


       Invoke-SwisVerb $swis Cirrus.ConfigArchive Execute @($nodeIdList, $script, $username) | Out-Null 



      and the job fails to complete.


      Any input here appreciated.




      I have added the (working) code to a template we have for sending emails.  When the job completes, Write-Host $output presents to the debug window nicely formatted text.



      If however I send $output to the email, the text just becomes a single continuous string:


      I've tried ConvertTo-HTML:


      $($output | ConvertTo-Html -fragment | out-string)


      which produces the completely non-helpful:

      Now, in all honesty, I'm nowhere near a PowerShell expert, so I'd be gratful for any pointers on what I am (clearly) doing wrong that is stopping the text being a nicely formatted table