PnP
PnP

Reputation: 3185

Powershell with HTML Formatting

So I am creating a basic HTML report for a System Server Audit, some extracts which are relevant:

$system = Get-WmiObject -ComputerName $cmpSys Win32_ComputerSystem 

$body = $null
$body += @"
<font color="red">Hostname: </font>$cmpSys
<br>
<font color="red">Domain: </font>($system.Domain)
<br>
"@

Now, Hostname: $cmpSys - correctly produces Hostname in red and the hostname in black

However, I am calling $system.Domain in the format later on, which produces in my report:

Domain: (\\W7WKS01\root\cimv2:Win32_ComputerSystem.Name="W7WKS01".Domain) 

But it should just display W7WKS01

Any ideas?

Upvotes: 0

Views: 110

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200483

You need $($system.Domain), not just ($system.Domain). Without the leading $ the parentheses are just literal parentheses inside a string, and $system.Domain is expanded to the default attribute of $system (__PATH) followed by a literal ".Domain".

Upvotes: 1

Related Questions