Author Posts

December 12, 2017 at 7:51 pm

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

December 12, 2017 at 7:52 pm

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.

December 12, 2017 at 8:26 pm

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

December 12, 2017 at 8:28 pm

What does $out contain?

December 12, 2017 at 8:33 pm

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.

December 12, 2017 at 8:34 pm

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


December 12, 2017 at 8:36 pm

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.

December 13, 2017 at 1:31 am

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