Error Length 92

Welcome Forums General PowerShell Q&A Error Length 92

This topic contains 7 replies, has 3 voices, and was last updated by

 
Participant
1 year ago.

  • Author
    Posts
  • #88936

    Participant
    Points: 1
    Rank: Member

    I'm trying to run this simple script

    $ServerNameshort= "LPVWA00A0413"
    $Domain = "ent.wfb.bank.corp"

    $OU = Get-ADComputer -ldapFilter "(CN=$ServerNameShort)" -Server $Domain -Credential $Cred | select -expandproperty DistinguishedName

    $OU |select *

    and I want the object to output the string

    but it show as a length property

    Length
    ——
    91

    any ideas.

    I want to covnert it from object to string

  • #88939

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    After your Select -ExpandProperty, what you've got is a string object. $OU will contain the string. By piping $OU to "Select *," you're asking the shell to display the properties of $OU, rather than its contents – and Length is the only property of a String object.

    You can't "convert from an object to a string;" a String is a kind of object. But by using -ExpandProperty you've already converted from an ADComputer object to just a string.

    Just run $OU.

  • #88943

    Participant
    Points: 1
    Rank: Member

    ok, I'm running the function now
    $params = @{'AS'='Table';
    'PreContent'='♦ OU Information';
    'Properties' = 'OU Path' ;

    }

    $out = Get-OUInfo -Credential $cred
    $out
    $ou1_html = $out |ConvertTo-EnhancedHTMLFragment @params

    I can see it on my console the output but on the html
    is only the title but no data

    $params = @{ 'Title'='Windows SA SIC Validation';

    'CssUri'=$CSSPath;
    'Head'= "Windows Sic Verification Step $step Validation`
    $ServerName `
    Report run: $(Get-Date -Format D) By: $env:USERNAME (ver $version) `
    Start Time: $StartTime End time: $(Get-Date)" ;

    'body'= $ou1_html;
    'PostContent'="";
    }

    ConvertTo-Html @params |out-file $OutFile

    ii $outfile

    any thought

  • #88945

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    What does $out contain?

  • #88946

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    I ask because if $out is just a string, piping it to ConvertTo-EnhancedHTML fragment won't do anything. I'm a bit confused as to what I'm dealing with 🙂 as this doesn't seem to be a follow-on to your question about the string object.

    Also, both the back-ticks and the semicolons are unnecessary in the hash tables you're constructing. Just so you're aware.

  • #88949

    Participant
    Points: 1
    Rank: Member

    I created a customize psobject with OU Name a property and value the string.

    OU Name
    ——-
    CN=WFCP5896I,OU=IIS,OU=Baseline Final,OU=Windows 2008,OU=Servers,OU=Infrastructure Services,DC=wf,DC=local

    What would be the best way to get

    the value from a function and the result to put it on an html fragment.

    here the function
    Function Get-OUInfo{
    [CmdletBinding()]

    param(
    [Parameter(Mandatory=$True)]
    [String]$credential

    )

    Write-Verbose "Getting Computer OU Information..." -Verbose
    $OU = Get-ADComputer -ldapFilter "(CN=$ServerNameShort)" -Server $Domain -Credential $Cred | select -expandproperty DistinguishedName

    $newouobj = New-Object -TypeName PSObject
    Add-Member -InputObject $newouobj -MemberType noteproperty -Name "OU Path" -Value $OU
    Write-Output $newouobj

    }

    • #88990

      Participant
      Points: 332
      Helping Hand
      Rank: Contributor

      QQ. Function notwithstanding. Why so much code, just to do this... (Well other than renaming the DistinguishedName to OUPath)

      Get-ADComputer -Filter * |
      Where Name -eq ($ServerNameshort = $env:COMPUTERNAME) |
      Select Name,DistinguishedName | Format-Table -AutoSize

      # results

      Name DistinguishedName
      —- —————–
      DC01 CN=DC01,OU=Domain Controllers,DC=contoso,DC=com

      # Or this...

      Get-ADComputer -Filter * |
      Where Name -eq ($ServerNameshort = $env:COMPUTERNAME) |
      Select Name,DistinguishedName | ConvertTo-Html

      # Or this...

      Get-ADComputer -Filter * |
      Where Name -eq ($ServerNameshort = $env:COMPUTERNAME) |
      Select Name,DistinguishedName | ConvertTo-Html -Fragment

  • #88952

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    I would start by just piping it to ConvertTo-HTML, to see what it does.

    $out | ConvertTo-HTML -Fragment

    That's the native PowerShell command, and it's what ConvertTo-EnhancedHTMLFragment uses under the hood. If that works, then you can try switching back to enhanced and adding parameters one at a time to get what you're after.

The topic ‘Error Length 92’ is closed to new replies.