Sunday, 23 September 2012

EchoArgs.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script contains a function, EchoArgs, that returns a list of 
  4.     the arguments passed and their type. It is used to demonstrate 
  5.     the use of the --% operator when calling a function or cmdlet, a new 
  6.     feature in PowerShell v3. 
  7. .DESCRIPTION 
  8.     The EchoArgs function takes the arguments passed, via $args, and
  9.     displays each argument and its type. Then, this function is called
  10.     first with a normal calling sequence and then using --%. 
  11. .NOTES 
  12.     File Name  : EchoArgs.ps1 
  13.     Author     : Thomas Lee - tfl@psp.co.uk 
  14.     Requires   : PowerShell Version 2.0 
  15. .LINK 
  16.     This script posted to: 
  17.         http://www.pshscripts.blogspot.com 
  18.     MSDN sample posted to: 
  19.          http://msdn.microsoft.com/en-us/library. 
  20. .EXAMPLE 
  21.     Psh[Cookham8:C:\foo]>E:\PowerShellScriptLib\SERVER2012FEATURES\EchoArgs.ps1 
  22.     Calling Echoargs with 'fasdf $(LS) 2334 {asdf}' 
  23.     Argument [0]: [fasdf] Type:System.String 
  24.     Argument [1]: [System.Object[]] Type:System.Object[] 
  25.     Argument [2]: [2334] Type:System.Int32 
  26.     Argument [3]: [asdf] Type:System.Management.Automation.ScriptBlock 
  27.  
  28.     Calling Echoargs with '--%  asdf; {asfd}-a asdf' 
  29.     Argument [0]: [--%] Type:System.String 
  30.     Argument [1]: [asdf; $(ls) {asfd} - a asdf] Type:System.String        
  31. #> 
  32.  
  33. # EchoArgs function 
  34. Function EchoArgs { 
  35. #Loop through and display each argument passed 
  36.   For ($i = 0; $i -ilt $Args.count; $i ++) { 
  37.   "Argument [{0}]: [{1}] Type:{2}" -f $I, $args[$i],$($args[$i].GetType().FullName) 
  38. } 
  39. } 
  40.  
  41. # Test it 
  42. "Calling Echoargs with 'fasdf `$(LS) 2334 {asdf}'" 
  43. Echoargs  fasdf $(ls) 2334 {asdf} 
  44. "";"Calling Echoargs with '--%  asdf; {asfd}-a asdf'" 
  45. Echoargs  --%  asdf; $(ls) {asfd} - a asdf 

Tuesday, 18 September 2012

Disable-Gui.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script defines a function, Disable-Gui which 
  4.     disables the GUI on Windows Server 2012 Server Core 
  5. .DESCRIPTION 
  6.     The Disable-GUI function enables the GUI in Server 2012 
  7.     Server Core by Removing two windows features. The 
  8.     script add a Shell setting to ensure that when 
  9.     Server 2012 restarts, it starts with PowerShell.  
  10. .NOTES 
  11.     File Name  : Disable-GUI.ps1 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell Version 3.0 and Windows Server 2012. 
  14. .LINK 
  15.     This script posted to: 
  16.         http://www.pshscripts.blogspot.com 
  17. .EXAMPLE 
  18.     Psh> Disable-GUI -Verbose 
  19.     Removing Windows Feature: Server-GUI-Shell, Server-Gui-Mgmt-Infra 
  20.     Setting Shell Registry setting to PowerShell 
  21.     Restarting the computer - please be patient 
  22.     < after reboot, full GUI is added > 
  23. #> 
  24.  
  25. Function Disable-GUI { 
  26.  
  27. # No parameters - but maybe later 
  28. # Turn on CmdletBinding to enable -Verbose 
  29.  
  30. [Cmdletbinding()] 
  31. Param() 
  32.  
  33. # Remove features from main Server core and downgrade GUI to Server Core 
  34. Write-Verbose "Removing Windows Feature: Server-GUI-Shell, Server-Gui-Mgmt-Infra" 
  35. Uninstall-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra 
  36.  
  37. # Add in PowerShell as the shell 
  38. Write-Verbose "Setting Shell Registry setting to PowerShell" 
  39. $RegPath = "Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon"  
  40. Set-ItemProperty -Path $RegPath -Name Shell -Value 'PowerShell.exe -noExit -Command "$psversiontable"'  -Force 
  41.  
  42. # Now restart the system 
  43. Write-Verbose "Restarting the computer - please be patient" 
  44. Restart-Computer 
  45. } 

Enable-GUI.ps1

  1. <#
  2. .SYNOPSIS
  3. This script defines a function, Enable-Gui which
  4. enables the GUI on Windows Server 2012 Server Core
  5. .DESCRIPTION
  6. The Enable-GUI function enables the Gui in Server 2012
  7. Server Core by adding in two windows features. The
  8. script removes any Shell setting to ensure that when
  9. Server 2012 restarts, it starts with the full Desktop.
  10. .NOTES
  11. File Name : Enable-GUI.ps1
  12. Author : Thomas Lee - tfl@psp.co.uk
  13. Requires : PowerShell Version 3.0 and Windows Server 2012.
  14. .LINK
  15. This script posted to:
  16. http://www.pshscripts.blogspot.com
  17. .EXAMPLE
  18. Psh> Enable-GUI -Verbose
  19. Installing Windows Feature: Server-GUI-Shell, Server-Gui-Mgmt-Infra
  20. Removing Shell Registry Setting
  21. Finished installation, now rebooting
  22. < after reboot, full GUI is added >
  23. #>
  24. Function Enable-GUI {
  25. # No parameters - but maybe later
  26. # Turn on CmdletBinding to enable -Verbose
  27. [Cmdletbinding()]
  28. Param()
  29. # Install the GUI
  30. Write-Verbose "Installing Windows Feature: Server-GUI-Shell, Server-Gui-Mgmt-Infra"
  31. Install-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra -Source d:\sources\sxs
  32. # Remove the Setting For Shell to force back to CMD.EXE
  33. Write-Verbose 'Removing Shell Registry Setting'
  34. $RegPath = "Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon"
  35. Remove-ItemProperty -Confirm -Path $RegPath -Name Shell -ErrorAction SilentlyContinue
  36. # And reboot the system
  37. Write-Verbose "Finished installation, now rebooting"
  38. Restart-Computer
  39. }

Sunday, 16 September 2012

Set-HyperVHostDefault.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script demonstrates setting default values for Local Hyper-V host. 
  4. .DESCRIPTION 
  5.     This script imports the Hyper-V module then uses it 
  6.     to set certain default values for this hyper-V Host 
  7. .NOTES 
  8.     File Name  : Set-HyperVHostDefault.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 3.0 and Windows 8/Server 2012 
  11. .LINK 
  12.     This script posted to: 
  13.         http://www.pshscripts.blogspot.com 
  14. .EXAMPLE 
  15.    Left as an exercise for the reader 
  16.     
  17. #> 
  18.  
  19.  
  20. # Import Hyper-V Module 
  21. Import-Module Hyper-V 
  22.  
  23. Write-Verbose "$((gcm -module hyper-v).Count) cmdlets imported in Hyper-V Module" 
  24.  
  25. # Create $parm hash table! 
  26. $parm = @{} 
  27.  
  28. # Specify the Computername 
  29. $parm += @{ComputerName = "Win8.Cookham.Net"} 
  30.  
  31. # Specify the Hard Disk Path 
  32. $parm += @{VirtualMachinePath = "E:\hyperv"} 
  33.  
  34. # Specify the VHD Disk Path 
  35. $parm += @{VirtualHardDiskPath = "E:\hyperv"} 
  36.  
  37. # Set the VM host accordingly 
  38. Write-Verbose "Setting parameters as follows:";$parm 
  39. Set-VmHost @parm 
  40.  
  41. # And Display Details 
  42.  
  43. Get-VMHost 
  44.  
  45. # End Set-HyperVHostDefaults 

New-InternalSwitch.ps1

  1. <#
  2. .SYNOPSIS
  3.     This script demonstrates creating a Hyper-V Switch
  4. .DESCRIPTION
  5.     This script imports the Hyper-V module then uses it
  6.     to create an Internal Switch for use in future provisioning.
  7. .NOTES
  8.     File Name : New-InternalSwitch.ps1
  9.     Author : Thomas Lee - tfl@psp.co.uk
  10.     Requires : PowerShell Version 3.0 and Windows 8/Server 2012
  11. .LINK
  12.     This script posted to:
  13.     http://www.pshscripts.blogspot.com
  14. .EXAMPLE
  15.     C:\foo\> .New-InternalSwitch.ps1
  16.     VERBOSE: New-InternalSwitch will create a new virtual network.
  17.     Name      SwitchType NetAdapterInterfaceDescription
  18.     ----      ---------- ------------------------------
  19.     Internal  Internal
  20. #>
  21. # Import Hyper-V Module
  22. Import-Module Hyper-V
  23. Try {New-VMSwitch -Name Internal -SwitchType Internal -ComputerName LocalHost -Verbose}
  24. Catch { "Failed to create switch"; $error[0] }
  25. # End New-InternalSwitch.ps1

Tuesday, 7 August 2012

Show-Formatting1.ps1

  1. <#
  2. .SYNOPSIS
  3. MSDN Sample Recoded in PowerShell demonstrating formatting
  4. .DESCRIPTION
  5. This sample recodes an MSDN Sample into PowerShell that
  6. shows some of the options of formatting using ToString() and
  7. various .NET formatting strings
  8. .NOTES
  9. File Name : Show-Formatting1.ps1
  10. Author : Thomas Lee - tfl@psp.co.uk
  11. Requires : PowerShell Version 2.0
  12. .LINK
  13. This script posted to:
  14. http://www.pshscripts.blogspot.com
  15. MSDN sample posted to:
  16. http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
  17. .EXAMPLE
  18. Psh> .\Show-Formatting1.ps1\
  19. 00123
  20. 1.20
  21. 01.20
  22. 01,20
  23. 0.6
  24. 1,234,567,890
  25. 1.234.567.890
  26. 1,234,567,890.1
  27. 1,234.57
  28. #>
  29. ## Start script
  30. [double] $value = 123;
  31. $value.ToString("00000")
  32. # Displays 00123
  33. $value = 1.2;
  34. $value.ToString("0.00", [System.Globalization.CultureInfo]::InvariantCulture)
  35. # Displays 1.20
  36. $value.ToString("00.00",[System.Globalization.CultureInfo]::InvariantCulture)
  37. # Displays 01.20
  38. $value.ToString("00.00",
  39. [System.Globalization.CultureInfo]::CreateSpecificCulture("da-DK"))
  40. # Displays 01,20
  41. $value = .56
  42. $value.ToString("0.0", [System.Globalization.CultureInfo]::InvariantCulture)
  43. # Displays 0.6
  44. $value = 1234567890
  45. $value.ToString("0,0", [System.Globalization.CultureInfo]::InvariantCulture)
  46. # Displays 1,234,567,890
  47. $value.ToString("0,0",
  48. [System.Globalization.CultureInfo]::CreateSpecificCulture("el-GR"))
  49. # Displays 1.234.567.890
  50. $value = 1234567890.123456;
  51. $value.ToString("0,0.0", [System.Globalization.CultureInfo]::InvariantCulture)
  52. # Displays 1,234,567,890.1
  53. $value = 1234.567890;
  54. $value.ToString("0,0.00", [System.Globalization.CultureInfo]::InvariantCulture)
  55. # Displays 1,234.57

Thursday, 5 July 2012

Manage-ServerCoreGui.ps1

  1. <# 
  2. .Synopsis 
  3.    This file contains two simple functions to manage the GUI
  4.    in Server Core Windows Server 2012. 
  5. .DESCRIPTION 
  6.    There are two functions: Enable-ServerCoreGui that enables
  7.    the GUI in a server core installation. Diable-ServerCoreGuI
  8.    disables the GUI and returns the installation to
  9.    traditional Server Core. 
  10.  
  11.    Enable-ServerCoreGui also checks to see if some or all
  12.    parts are already installed andwarns accordingly. 
  13. .EXAMPLE 
  14.    c:\foo> Enable-ServerCoreGui 
  15.     
  16.    This enables the GUI and reboots the Server into FUll GUI mode. 
  17.  
  18. .EXAMPLE 
  19.    c:\foo> Disable-ServerCoreGui 
  20.     
  21.    This disables the GUI and reboots the Server back to Server Core mode. 
  22. #> 
  23.  
  24.  
  25. Function Enable-ServerCoreGui { 
  26.  
  27. #    Import the module 
  28. Import-Module -Name DISM -ErrorAction Stop 
  29.  
  30. # is it already enabled?? 
  31. if ((Get-WindowsOptionalfeature -online -Feature ServerCore-FullServer).state -eq 'Enabled'){ 
  32.   "Servercore-FullServer is already enabled" 
  33. } 
  34.  
  35. if ((Get-WindowsOptionalfeature -online -Feature Server-GUI-Shell).state -eq 'Enabled'){ 
  36.   "Server-GUI Shell is already enabled" 
  37. } 
  38.  
  39. if ((Get-WindowsOptionalfeature -online -Feature Server-Gui-Mgmt).state -eq 'Enabled'){ 
  40.   "Server-Gui-Mgmt is already enabled" 
  41. } 
  42.  
  43. # Enable the features needed to add the GUI 
  44. Enable-WindowsOptionalFeature –Online -NoRestart ` 
  45.       -Featurename ServerCore-FullServer, Server-Gui-Shell,Server-Gui-Mgmt 
  46.  
  47. # So Restart the computer 
  48. Restart-computer 
  49. } 
  50.  
  51. Function Disable-ServerCoreGui { 
  52.  
  53. #    Import the module 
  54. Import-Module -Name DISM -ErrorAction Stop 
  55.  
  56. # Disable all the features needed to add the GUI 
  57. # if any are already disabled, oh well - they're still disabled. 
  58. Disable-WindowsOptionalFeature –Online -NoRestart ` 
  59.       -Featurename ServerCore-FullServer, Server-Gui-Shell,Server-Gui-Mgmt 
  60.  
  61. # Finally Restart the computer 
  62. Restart-computer 
  63. } 

Monday, 30 April 2012

Show-DnsConfiguration.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script shows the DNS Configuration  of NICs  
  4.     in your system 
  5. .DESCRIPTION 
  6.     This script is a re-write of an MSDN Sample  
  7.     using PowerShell./ The script gets all network 
  8.     active network interfaces then prints out that 
  9.     interfaces' DNS Properties. 
  10. .NOTES 
  11.     File Name  : Show-DnsConfiguration.ps1 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell Version 2.0 
  14. .LINK 
  15.     This script posted to: 
  16.         http://www.pshscripts.blogspot.com 
  17.     MSDN sample posted to: 
  18.          http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces.aspx    
  19. .EXAMPLE 
  20.     Psh[C:\foo]> .\Show-DnsConfiguration.ps1 
  21.     Broadcom NetXtreme 57xx Gigabit Controller 
  22.       DNS suffix .............................. : cookham.net 
  23.       DNS enabled ............................. : False 
  24.       Dynamically configured DNS .............. : True 
  25.  
  26.     ... more interfaces snipped for brevity!     
  27. #> 
  28.  
  29. # Get the adapters than iterate over the collection and display DNS configuration 
  30. $adapters = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() 
  31. ForEach ($adapter in $adapters)   { 
  32.   $properties = $adapter.GetIPProperties() 
  33.   $adapter.Description 
  34.   "  DNS suffix .............................. : {0}" -f $properties.DnsSuffix 
  35.   "  DNS enabled ............................. : {0}" -f $properties.IsDnsEnabled 
  36.   "  Dynamically configured DNS .............. : {0}" -f $properties.IsDynamicDnsEnabled 
  37. } 

Show-NetworkInterfaces2.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script, shows details about the Network Interfaces 
  4.     on a system. This is a re-write of an MSDN script into 
  5.     PowerShell 
  6. .DESCRIPTION 
  7.     This script Uses several .NET classes to get the details 
  8.     of the interfaces on the system, then displays these details. 
  9.     Note in the MSDN Script, there were calls to other MSDN Samples.  
  10.     To make things simple, I have removed these calls.  
  11. .NOTES 
  12.     File Name  : Show-NetworkInterfaces2.ps1 
  13.     Author     : Thomas Lee - tfl@psp.co.uk 
  14.     Requires   : PowerShell Version 2.0 
  15. .LINK 
  16.     This script posted to: 
  17.         http://www.pshscripts.blogspot.com 
  18.     MSDN sample posted to: 
  19.          http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.aspx    
  20. .EXAMPLE 
  21.  
  22.     Psh[C:\foo]> .\Show-NetworkInterfaces2.ps1 
  23.     Interface information for Cookham8.cookham.net 
  24.       Number of interfaces .................... : 2 
  25.  
  26.     Broadcom NetXtreme 57xx Gigabit Controller 
  27.     ========================================== 
  28.       Interface type .......................... : Ethernet 
  29.       Physical Address ........................ : 001E4F955CC4 
  30.       Operational status ...................... : Up 
  31.       IP version .............................. : IPv4, IPv6 
  32.       DNS suffix .............................. : cookham.net 
  33.       MTU...................................... : 1500 
  34.       WINS Servers ............................ : 
  35.       10.10.1.101 
  36.       DNS enabled ............................. : False 
  37.       Dynamically configured DNS .............. : True 
  38.       Receive Only ............................ : False 
  39.       Multicast ............................... : True 
  40.  
  41.     Microsoft ISATAP Adapter 
  42.     ======================== 
  43.       Interface type .......................... : Tunnel 
  44.       Physical Address ........................ : 00000000000000E0 
  45.       Operational status ...................... : Down 
  46.       IP version .............................. : IPv4, IPv6 
  47.       DNS suffix .............................. : cookham.net 
  48.       MTU...................................... :  
  49.       DNS enabled ............................. : False 
  50.       Dynamically configured DNS .............. : True 
  51.       Receive Only ............................ : False 
  52.       Multicast ............................... : False 
  53.        
  54. #> 
  55.  
  56. # First, get network properties of, and the nics in, this system 
  57. $computerProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties() 
  58. $nics =               [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() 
  59.  
  60. "Interface information for {0}.{1}" -f $computerProperties.HostName, $computerProperties.DomainName 
  61.  
  62. # Do we have nics?? 
  63. If (!$nics -or $nics.Length -lt 1) 
  64.     { 
  65.         "  No network interfaces found." 
  66.         return 
  67.     } 
  68.  
  69. # Show interface details 
  70. "  Number of interfaces .................... : {0}" -f $nics.Length 
  71. ForEach ($adapter in $nics) 
  72.     { 
  73.         $properties = $adapter.GetIPProperties() 
  74.         "" 
  75.         $adapter.Description 
  76.         "=" * $adapter.Description.Length 
  77.         "  Interface type .......................... : {0}" -f $adapter.NetworkInterfaceType 
  78.         "  Physical Address ........................ : {0}" -f $adapter.GetPhysicalAddress().ToString() 
  79.         "  Operational status ...................... : {0}" -f $adapter.OperationalStatus 
  80.     # Create a display string for the supported IP versions. 
  81.        $versions ="" 
  82.         if ($adapter.Supports([System.Net.NetworkInformation.NetworkInterfaceComponent]::IPV4 )) 
  83.         { 
  84.              $versions = "IPv4" 
  85.          } 
  86.         if ($adapter.Supports([System.Net.NetworkInformation.NetworkInterfaceComponent]::IPv6)) 
  87.         { 
  88.             if ($versions.Length -gt 0) 
  89.             { 
  90.                $versions += ", "; 
  91.              } 
  92.             $versions += "IPv6"; 
  93.         } 
  94.         "  IP version .............................. : {0}" -f $versions 
  95.  
  96. # The remaining information is not useful for loopback adapters. 
  97.  if ($adapter.NetworkInterfaceType -eq [System.Net.NetworkInformation.NetworkInterfaceType]::Loopback) 
  98.         { 
  99.             continue 
  100.         } 
  101.  "  DNS suffix .............................. : {0}" -f $properties.DnsSuffix 
  102.         if ($adapter.Supports([System.Net.NetworkInformation.NetworkInterfaceComponent]::IPv4)) 
  103.         { 
  104.             $ipv4 = $properties.GetIPv4Properties() 
  105.             "  MTU...................................... : {0}" -f $ipv4.Mtu 
  106.             if ($ipv4.UsesWins) 
  107.             { 
  108.  
  109.                 $winsServers = $properties.WinsServersAddresses 
  110.                 if ($winsServers.Count -gt 0) 
  111.                 { 
  112.                     "  WINS Servers ............................ :"; 
  113.                     foreach ($Winserver in $winsServers) { 
  114.                     "  {0}" -f $Winserver.IpAddressToString 
  115.                     } 
  116.                 } 
  117.             } 
  118.         } 
  119.  
  120.         "  DNS enabled ............................. : {0}" -f $properties.IsDnsEnabled 
  121.         "  Dynamically configured DNS .............. : {0}" -f $properties.IsDynamicDnsEnabled 
  122.         "  Receive Only ............................ : {0}" -f $adapter.IsReceiveOnly 
  123.         "  Multicast ............................... : {0}" -f $adapter.SupportsMulticast 
  124. }  # End Foreach 

Sunday, 29 April 2012

Show-NetworkInterfaces1.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays the NICs in a system and their physical
  4.     address. 
  5. .DESCRIPTION 
  6.     This script is a MSDN Sample recoded in PowerShell. The script
  7.     first gets all the interfaces on the system, then loops through
  8.     them displaying more information about them to the console.
  9.     Note the use of Console.Write in the loop at the end. Not quite
  10.     sure a better PowerShell equivalent other than creating a
  11.     string with all the bytes, then displaying that string. 
  12. .NOTES 
  13.     File Name  : Show-NetworkInterfaces1.ps1 
  14.     Author     : Thomas Lee - tfl@psp.co.uk 
  15.     Requires   : PowerShell Version 2.0 
  16. .LINK 
  17.     This script posted to: 
  18.         http://www.pshscripts.blogspot.com 
  19.     MSDN sample posted to: 
  20.         http://msdn.microsoft.com/en-us/library/system.net.networkinformation.physicaladdress.aspx    
  21. .EXAMPLE 
  22.     PSH[c:\foo]> .\Show-Networkinterfaces1.ps1 
  23. Interface information for Cookham8.cookham.net      
  24.   Number of interfaces .................... : 2 
  25. Broadcom NetXtreme 57xx Gigabit Controller 
  26. ========================================== 
  27.   Interface type .......................... : Ethernet 
  28.   Physical address ........................ : 00-1E-4F-95-5C-C4  
  29.  
  30. Microsoft ISATAP Adapter 
  31. ======================== 
  32.   Interface type .......................... : Tunnel 
  33.   Physical address ........................ : 00-00-00-00-00-00-00-E0  
  34.      
  35. #> 
  36.      
  37. # Get computer IP global properties 
  38. $ComputerProperties = [System.Net.NetworkInformation.IpGlobalProperties]::GetIPGlobalProperties() 
  39.  
  40. # Get the nics in this system 
  41. $nics = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() 
  42.  
  43. # Show information header 
  44. "Interface information for {0}.{1}     " -f $ComputerProperties.HostName, $ComputerProperties.DomainName 
  45.   
  46. # Iterate through the NIcs ans outout per nic info 
  47. # First, check if interfaces are found 
  48.  if (!$nics -OR $nics.Length -LT 1) 
  49.     { 
  50.         "  No network interfaces found." 
  51.         return 
  52.     } 
  53.  
  54. # Here print out number of interfaces and interface details 
  55. [System.Console]::WriteLine("  Number of interfaces .................... : {0}" -f $nics.Length) 
  56. Foreach ($adapter in $nics) 
  57.     { 
  58.         $properties = $adapter.GetIPProperties();    
  59.         " ";"" 
  60.         "{0}" -F $adapter.Description 
  61.         "=" * $adapter.Description.Length 
  62.         "  Interface type .......................... : {0}" -F $adapter.NetworkInterfaceType 
  63.         [System.Console]::Write("  Physical address ........................ : ") 
  64.         $address = $adapter.GetPhysicalAddress(); 
  65.         $bytes = $address.GetAddressBytes() 
  66.         for($i = 0; $i -lt $bytes.Length; $i++) 
  67.         { 
  68.             # Display the physical address in hexadecimal. 
  69.             [system.Console]::Write("{0}" -f $bytes[$i].ToString("X2")) 
  70.             # Insert a hyphen after each byte, unless we are at the end of the  
  71.             # address. 
  72.             if ($i -NE $bytes.Length -1) 
  73.             { 
  74.                  [System.Console]::Write("-") 
  75.             } 
  76.         } 
  77.         [System.Console]::WriteLine() 
  78.     }