Error Length 92

This topic contains 7 replies, has 3 voices, and was last updated by  postanote 4 months, 2 weeks ago.

  • Author
  • #88936

    Helder Guzman

    I'm trying to run this simple script

    $ServerNameshort= "LPVWA00A0413"
    $Domain = ""

    $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


    any ideas.

    I want to covnert it from object to string

  • #88939

    Don Jones

    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

    Helder Guzman

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


    $out = Get-OUInfo -Credential $cred
    $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';

    '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;

    ConvertTo-Html @params |out-file $OutFile

    ii $outfile

    any thought

  • #88945

    Don Jones

    What does $out contain?

  • #88946

    Don Jones

    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

    Helder Guzman

    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{



    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


      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

    Don Jones

    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.

You must be logged in to reply to this topic.