2009-07-23 11 views

risposta

200

Si può semplicemente utilizzare il metodo .NET Framework:

[System.Net.Dns]::GetHostName()

anche

$env:COMPUTERNAME

+0

Funzionante, fantastico! Grazie – George2

+2

Così elegante. I <3 PowerShell. –

+1

Nota: se il nome DNS è più lungo di 15 caratteri, '[System.Net.Dns] :: GetHostName()' (non tronca) è migliore di '$ env: COMPUTERNAME' (troncato) – sonjz

28

forma lunga:

get-content env:computername 

forma breve:

gc env:computername 
+12

supersorto: $ env :NOME DEL COMPUTER –

50

Non dimenticate che tutti i tuoi vecchi programmi di utilità console funzionano bene in PowerShell:

PS> hostname 
KEITH1 
3

Tutte le domande di cui sopra sono corrette, ma se si desidera che il nome host e il dominio provare questo:

[System.Net.DNS]::GetHostByName('').HostName 
Problemi correlati