Powershell: Computer field in InformationRecord is incorrect on Ubuntu 18.04 container

Created on 3 May 2019  路  7Comments  路  Source: PowerShell/PowerShell

This repros only on container for ubuntu. It works as expected on VMs and containers of other Linux distros

Steps to reproduce

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 />

Expected behavior

PS /> $result.Computer
35dc3ee9a157

Actual behavior

$result.Computer is an empty string

Environment data

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

Issue-Bug Resolution-Fixed WG-Engine

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.

All 7 comments

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?

Was this page helpful?
0 / 5 - 0 ratings