From cb554f576758b915252a2a5b853aea9ac443b6dc Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Thu, 29 Dec 2022 15:40:21 +0100 Subject: [PATCH] Add try/catch for containers without the hostname command (#8710) fixes #8701 --- dbatools.psm1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dbatools.psm1 b/dbatools.psm1 index e45cbc3aa7..f853fb9751 100644 --- a/dbatools.psm1 +++ b/dbatools.psm1 @@ -94,7 +94,11 @@ if (($PSVersionTable.PSVersion.Major -lt 6) -or ($PSVersionTable.Platform -and $ # this doesn't exist by default # https://github.com/PowerShell/PowerShell/issues/1262 - $env:COMPUTERNAME = hostname + try { + $env:COMPUTERNAME = hostname + } catch { + $env:COMPUTERNAME = "unknown" + } } Write-ImportTime -Text "Setting some OS variables"