Error Length 92

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

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.

ok, I’m running the function now
$params = @{‘AS’=‘Table’;
‘PreContent’=‘:diamonds: 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 `
                  <strong>Report run:</strong> $(Get-Date -Format D)   <strong>By:</strong> $env:USERNAME (ver $version) &#8175;
                  <strong>Start Time:</strong> $StartTime <strong>   End time:</strong> $(Get-Date)" ;    
         
         'body'= $ou1_html;  
         'PostContent'="";                       
         }

ConvertTo-Html @params |out-file $OutFile

ii $outfile

any thought

What does $out contain?

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 :slight_smile: 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.

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

}

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.

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