Forum Discussion

David Lay's avatar
David Lay
Copper Contributor
Nov 07, 2018

Oracle SQL DB with Powershell

Hi All, I made this script for a client of mine, But I am now trying to make it more intelligent by adding conditions, ie. If statements/Switch But I am hitting that "System.Object[] cannot be Int32

 

Script

$webhookID = $(curl -s https://discordapp.com/api/webhooks/botID jq -r .id)
$webhookToken = $(curl -s https://discordapp.com/api/webhooks/botID | jq -r .token)
$sqlOutput = '@query.sql' | sqlplus -silent username/password@host as sysdba |out-string -stream
$ServiceString = ("The DataBase has only" + $sqlOutput + "%, free space as of and it is considered " + " on " + $(Get-Date -format g))
curl -s --request POST --url https://discordapp.com/api/webhooks/$webhookid/$webhookToken
--header 'Cache-Control: no-cache' --header 'content-type: multipart/form-data;
boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' --form content="$ServiceString"

 Conditional Element:

switch ($int) { {$_ -lt 10} {$strStatus = 'DANGER'}

default {$strStatus = 'OK'} }

Thanks

 

2 Replies

  • One of the things is to identify which lines are producing the Errors.  

    You could pop this in PowerShell ISE *or* Vscode and run an individual trace on each line.  

     

    The other part is to run each individual line in PowerShell (Good only Copy/Paste will work) and show which line is producing the "System.Object" output.   

     

    Once you have that you can try piping that line into Get-Member to see the Object type and properties.   Not knowing the Object I can't comment yet on how to pull the pieces you need out.  But if we can fix the first problem, the rest could be easier to solve or might even just clear up

     

    Let me know how I can help!

    Sean

    • David Lay's avatar
      David Lay
      Copper Contributor

      Hi Sean,

       

      I did use the "get-member" and its shows as an object, despite I ended up making a working solution by running a {if} that compare string as string with a predefined string, given that the output was sent to a webhook as a string.

       

      Thanks though, I did tried using SQL end, but its does not do what I expected. As a result $string -match does the job.

       

      Thanks

Resources