• Check out the difference between
    [powershell]Get-NetAdapter | Select-Object -ExpandProperty InterfaceAlias[/powershell]
    [powershell]Get-NetAdapter | Select-Object InterfaceAlias[/powershell]

    Do you catch the difference? That’s PowerShell-related, not Get-Netadapter related. 🙂

    You may also use [powershell](Get-NetAdapter).InterfaceAlias[/powershell]


  • Hi Emanuel!

    Every answer I get is like a new window of knowledge! Thank you!

    I’ve actually used something similar to your 2nd suggestion. In fact, here’s my test code:

    Invoke-Command -VMName Win10VMTest004 -ScriptBlock {
    $InterfaceIndex = Get-NetAdapter | Select-Object InterfaceIndex
    $InterfaceAlias = Get-NetAdapter | Select-Object InterfaceAlias
    Write-Output $InterfaceAlias
    If ($InterfaceAlias -eq “Ethernet 2”)
    $InterfaceIndex = $InterfaceIndex4Set
    Write-Output $InterfaceAlias, $InterfaceIndex4Set

    However, using the 1st write-output that I’ve placed to trace where the process flows through, I’ve found out that it doesn’t enter or satisfy the IF statement. It displayed this:

    InterfaceAlias PSComputerName RunspaceId
    ————– ————– ———-
    Ethernet 2 Win10VMTest004 ffd983d1-21bf-42af-b123-bb0ec402dd3f
    Ethernet Win10VMTest004 ffd983d1-21bf-42af-b123-bb0ec402dd3f

    I need to ‘catch’ Ethernet 2. Suspecting that the second value ‘Ethernet’ is overwriting the 1st value ‘Ethernet 2’, I’ve tested a code where the IF tries to catch ‘Ethernet’ only. To no avail.

    You’re right, YouTube videos will surely do a lot of help also.

    Thank you! Your replies are always very helpful and enlightening.

  • This guide has been updated for the latest Windows versions Windows 11 and Windows Server 2022. You’ll learn how to install the Active Directory (AD) module for PowerShell Core 6.0, PowerShell 7 and Windows PowerShell. For Windows PowerShell, the tutorial describes how to install the AD module for Windows 7, Windows 8, Windows 8.1, Windows 10, Windows 11 Windows Server 2008 R2, Windows Server 2012 R2, and Windows Server 2016, Windows Server 2010 and Windows Server 2022. You’ll also learn how to work with the AD module on other systems such as macOS or Linux with the help of PowerShell remoting.Verfiying that RSAT is installed with PowerShell

  • Hi.
    You can do it in several ways:

    or save everything in a variable and then use it in a similar way.
    $Nics = Get-Netadapter


    Get-NetAdapter | Select-Object -ExpandProperty InterfaceIndex

    These approaches are applicable to pretty much all PowerShell commands, not really to this one in particular. If you’re new with PowerShell, getting comfortable with these concepts will be of great help. There are quite a few PowerShell courses on Pluralsight that could be a boost for you at this stage (pretty much anything from Jeff Hicks would be an excellent choice, but start with the “beginner” courses). Pluralsight is not free, but it’s completely worth the investment, and it’s roughly the cost of a Netflix subscription. 🙂
    (I’m not affiliated in any way with them, but it helped me and I learned a lot).
    Alternately, there are tons of free resources on YouTube and elsewhere. The only limit is your time. And your curiosity. 🙂

  • Hi Emanuel!

    This is great help. However, how do I get the value of InterfaceIndex only? If my guess is correct, the code you provided will dump all of what’s contained in Get-NetAdapter.

    Thank you!

  • Hi, Lee Roy (and Anthony).

    You could do something like
    $info = Invoke-Command -ComputerName Dc01,FS03 -ScriptBlock {Get-NetAdapter}.
    to store the info in the variable $info.

    However, for Get-Netadapter you don’t need Invoke-Command. Get-Netadapter can get info from remote systems .
    $info = Get-NetAdapter -CimSession Dc01,FS03

  • Hi Emanuel!

    Invoke-Command is now my new best friend!

    In fact, I’ll also be using it for a code to extract the value of InterfaceIndex (thru Get-Netadapter). But how do I get the value/s of the property/ies (like InterfaceIndex and InterfaceAlias) of Get-Netadapter and use it/them, say move the value/s to a variable/s?

    Thank you!

  • Is there a way to get the value of InterfaceIndex and move it to a variable?

  • In this second post in my series about Hyper-V management with PowerShell I will explain how to create a Hyper-V virtual switch with PowerShell. In my previous post I explained how to install Hyper-V with PowerShell.

  • In this first post of my series about managing Hyper-V with PowerShell I will outline how to install Hyper-V Server and the Hyper-V role with PowerShell.

  • I got this error when run that script. Please help

  • I got this error when run that script. Please help

    Export-Csv : Cannot bind parameter ‘Delimiter’. Cannot convert value “NoTypeInformation” to type “System.Char”. Error: “String must be exactly one
    character long

  • Please help. I got below error when run script

    Export-Csv : Cannot bind parameter ‘Delimiter’. Cannot convert value “Encoding” to type “System.Char”. Error: “String must be exactly one character
    At D:MyselfPSToolsCollectingSystemStability&ProblemOri.ps1:5 char:102
    + … ERPROFILEDocumentsReliabilityStabilityMetrics.csv ‑Encoding ASCII – …
    + ~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand

    Export-Csv : Cannot bind parameter ‘Delimiter’. Cannot convert value “Encoding” to type “System.Char”. Error: “String must be exactly one character
    At D:MyselfPSToolsCollectingSystemStability&ProblemOri.ps1:6 char:84
    + … V $env:USERPROFILEDocumentsReliabilityRecords.csv ‑Encoding ASCII – …
    + ~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand

  • The -h switch of PsExec takes care of elevation problems. By the way, if nothing else works, you could use regular PowerShell remoting command like this:

    Invoke-Command -ComputerName remoteServer -FilePath D:ScriptsyourScript.ps1 -Credential domainadmin
  • But how can one use Psexec to execute a PowerShell script on a Windows server, and inject domain username/password (eg. Create-FailoverCluster that requires permissions to create AD computer object)?

    The user invoking the PowerShell script is NT AUTHORITYSYSTEM (from an Azure DevOps automated pipeline), but need the PS1 file to run with domain credentials. I can get the username and password to the script, but seems that it is not allowed to elevate the creds.

    Any advice?

  • Hi Emanuel!

    This is great! I’ll go ahead and try.

    Thank you so much!

  • In this case, PowerShell Direct is your friend. The VM needs to be on, but otherwise you can run the commands from the host. If the VMs are not in the same domain as the hosts, you can specify different credentials.


  • Hi Emanuel!

    Thank you for replying! Well, my situation is that I need to run your commands ‘outside’ the VM. Sorry for the newbie term (‘coz I’m exactly that – a newbie). Specifically, the Set-DNSClientServerAddress command. This command necessitates me to be ‘inside’ the VM so I can change it’s DNS IP address. I need to do this while I’m ‘outside’ the VM. In fact, I’m adding this line of code to a Powershell syntax that automates VM creation installed with a virtual hard drive (to also automate OS installation) plus setting up virtual network connection with a specific DNS server. The part with the DNS server that I have to specify for the VM is the tricky part for me.

  • Load More
© 4sysops 2006 - 2022


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account