Skip to content

Commit ade4831

Browse files
daxian-dbwlzybkr
authored andcommitted
Remove dependency on the Utility module (#814)
1 parent d7da9d3 commit ade4831

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

PSReadLine/ReadLine.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Globalization;
1010
using System.Linq;
1111
using System.Management.Automation;
12+
using System.Management.Automation.Host;
1213
using System.Management.Automation.Language;
1314
using System.Management.Automation.Runspaces;
1415
using System.Reflection;
@@ -625,13 +626,9 @@ private PSConsoleReadLine()
625626
{
626627
try
627628
{
628-
ps.AddCommand("Get-Variable").AddParameter("Name", "host").AddParameter("ValueOnly");
629-
var results = ps.Invoke();
630-
dynamic host = results.Count == 1 ? results[0] : null;
631-
if (host != null)
632-
{
633-
hostName = host.Name as string;
634-
}
629+
var results = ps.AddScript("$Host").Invoke<PSHost>();
630+
PSHost host = results.Count == 1 ? results[0] : null;
631+
hostName = host?.Name;
635632
}
636633
catch
637634
{

0 commit comments

Comments
 (0)