This repros only on container for ubuntu. It works as expected on VMs and containers of other Linux distros
PS /> docker run -it --rm mcr.microsoft.com/powershell:latest
PowerShell 6.2.0
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /> $result = Write-Information "Test Message" *>&1
PS /> $result.Computer
PS /> [Environment]::MachineName
35dc3ee9a157
PS /> cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
PS />
PS /> $result.Computer
35dc3ee9a157
$result.Computer is an empty string
PS /> $PSVersionTable
Name Value
---- -----
PSVersion 6.2.0
PSEdition Core
GitCommitId 6.2.0
OS Linux 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
We call GetFullyQualifiedName() from libpsl-native to get computer name. So a root of the issue is there.
Perhaps if GetFullyQualifiedName() is empty or null, we can fallback to [Environment]::MachineName?
Or use [Environment]::MachineName directly and remove pinvoke?
I see on Windows we use System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties - the API is ported and we could test it and use for all platforms.
We should probably see if we can get rid of libpsl-native altogether as .NET Core keeps adding more APIs
I'd expect the issue on container for ubuntu is not PowerShell issue and should be fixed on container for ubuntu.
I reviewed API that we use on Unix-es - we use the same GetHostName() (and CoreFX) to get host name but getaddrinfo() to get domain name - CoreFX uses GetDomainName()
I think we should follow CoreFX and remove P/Invokes in our code.
@adityapatwardhan Can we close the issue?
Most helpful comment
I'd expect the issue on container for ubuntu is not PowerShell issue and should be fixed on container for ubuntu.
I reviewed API that we use on Unix-es - we use the same GetHostName() (and CoreFX) to get host name but getaddrinfo() to get domain name - CoreFX uses GetDomainName()
I think we should follow CoreFX and remove P/Invokes in our code.