And in case it isn't clear, specifically what you will do is this:

                $foo | ft -auto | out-string | write-verbose

From: Michael B. Smith [mailto:mich...@smithcons.com]
Sent: Wednesday, April 11, 2012 4:48 PM
To: NT System Admin Issues
Subject: RE: Powershell verbose pref

Use the pipeline, Luke.

                $foo | Write-Verbose

That "unrolls" the object.

From: Joseph L. Casale 
[mailto:jcas...@activenetwerx.com]<mailto:[mailto:jcas...@activenetwerx.com]>
Sent: Wednesday, April 11, 2012 3:10 PM
To: NT System Admin Issues
Subject: RE: Powershell verbose pref

Yeah, problem is, the return that gets shoved into a variable appears to be an 
array of System.Object?
If I simply `$foo|ft -auto` I get a nice table, but I can't execute 
`Write-Verbose $foo` as a result of the System.Object type of its elements.
When I loop through element of the return, I am expecting a hash but I get 
system.management.automation.pscustomobject?

The output is the return of this function:

Function Get-StatementResult
{
    Param
    (
        [System.Data.Odbc.OdbcConnection] $databaseHandle,
        [String] $sql
    )
    $databaseCommand = New-Object System.Data.Odbc.OdbcCommand
    $databaseCommand.Connection = $databaseHandle
    $databaseCommand.CommandType = [System.Data.CommandType]::Text
    $databaseCommand.CommandText = $sql
    $reader = $databaseCommand.ExecuteReader()
    $objectArray = @()
    While ($reader.Read() -eq $True)
    {
        $hash = @{}
        Foreach ($i in 0..($reader.FieldCount - 1))
        {
            $hash.$($reader.GetName($i)) = $reader.GetValue($i)
        }
        $objectArray += New-Object PSObject -property $hash
    }
    $databaseCommand.Cancel()
    $databaseCommand = $null
    Return $objectArray
}

Thanks!
jlc
________________________________
From: Michael B. Smith [mich...@smithcons.com]
Sent: Wednesday, April 11, 2012 12:31 PM
To: NT System Admin Issues
Subject: RE: Powershell verbose pref
Have you taken a look at Write-Verbose ???

From: Joseph L. Casale 
[mailto:jcas...@activenetwerx.com]<mailto:[mailto:jcas...@activenetwerx.com]>
Sent: Wednesday, April 11, 2012 2:26 PM
To: NT System Admin Issues
Subject: Powershell verbose pref

I have a script where I simply piped a hash into a ft -auto to print it.
Now I am trying to only do this when the verbose flag is set and have all the 
lines prefixed with VERBOSE:.

Is there a simple way to do this, or must I test for verbose, then iterate 
through the hash?

Thanks!
jlc

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to listmana...@lyris.sunbeltsoftware.com
with the body: unsubscribe ntsysadmin

Reply via email to