Script to send email on Bitlocker status

Here is my code below (error below that). It is having issues with the “$Body = hostname” line. The format of the hostname output doesn’t seem to be compatible with the email code, any suggestions?

$BLinfo = Get-Bitlockervolume
$ToAddress = ‘’
$Subject = ‘PCs with Bitlocker Disabled’
#$Body = Out-String -InputObject (hostname)
$Body = hostname

if($blinfo.ProtectionStatus -eq ‘Off’) {
Import-Module $env:SyncroModule -WarningAction SilentlyContinue
Send-Email -To $ToAddress -Subject $Subject -Body $Body

error> System.InvalidOperationException: A circular reference was detected while serializing an object of type ‘System.Management.Automation.PSParameterizedProperty’.
error> Stack:
error> at ConvertTo-Json20, C:\ProgramData\Syncro\bin\module.psm1: line 314
error> at Call-Api, C:\ProgramData\Syncro\bin\module.psm1: line 266
error> at Call-SyncroApi, C:\ProgramData\Syncro\bin\module.psm1: line 249
error> at Send-Email, C:\ProgramData\Syncro\bin\module.psm1: line 138
error> at , C:\ProgramData\Syncro\bin\8b51ec11-f4e0-4dbe-89c4-7270375e9734.ps1: line 12
error> at , : line 1
error> at , : line 1
error> Call-SyncroApi: failure

Don’t use hostname for the variable. It’s can’t “expand” it when doing it that way, hence the error.

I would just get rid of $Body and instead do:

Send-Email -To $ToAddress -Subject $Subject -Body $env:computername

or if you want to keep the $Body, do $Body = $env:computername

put quotes around $Body
Send-Email -To $ToAddress -Subject $Subject -Body ‘$Body’

Not single quotes though, since that won’t expand it.

I actually tested it with single quotes. No expanding. Hostname is a command with basic output not a variable.

Hmm interesting. Testing locally it doesn’t output it for me when I do it. Learn something new everyday I guess.

I dunno what magic you have, but it def doesn’t work for me lol. Using the $env:computername does however.

OH! LOL, yes. I didn’t check the output in the email, just that it didn’t error. Yea, would need to be double quotes, wasn’t thinking.

Phew, man you really had me doubting everything I thought I knew about single and double quotes in PowerShell scripting lol.