• HI Emanuel!

    Thank you!!!

    With your expert guidance, I was able to come up with this:

    PS C:Windowssystem32> Invoke-Command -VMName Win10VMTest004 -ScriptBlock {
    $InterfaceIndex2 = Get-NetAdapter | Select-Object -ExpandProperty InterfaceIndex
    $InterfaceAlias2 = Get-NetAdapter | Select-Object -ExpandProperty InterfaceAlias
    If ($InterfaceAlias2 -eq “Ethernet 2”)
    {
    $InterfaceIndex4Set = $InterfaceIndex2
    Write-Output $InterfaceIndex4Set, $InterfaceAlias2
    }}
    cmdlet Invoke-Command at command pipeline position 1
    Supply values for the following parameters:
    7
    4
    Ethernet 2
    Ethernet

    PS C:Windowssystem32>

    What I need is to ‘do something’ once I catch InterfaceAlias value of Ethernet 2, and it’s basically using the InterfaceIndex value of ‘7’ somewhere down the road.

    So I have very obvious questions in here. Am I dealing with an array when I access the contents of Get-NetAdapter? How do I ‘capture’ the same ‘row’ of data once I get the ‘Ethernet 2’ value of InterfaceAlias? Sorry about my ignorance. I did COBOL programming and as you can see, my knowledge is pretty Jurassic at best. 😉

    Thank you again!

  • Thank you for writing this article.
    I wrote all my own Powershell code to install VMs, but on the free Hypervisor-only platform. IMO, it is pointless to host VMs on a GUI based server. The command line based server has far less bloat and better security.

  • In this new post of my Hyper-V management series, I will explain how create a Hyper-VM with PowerShell.Add virtual DVD drive to VM and Mount the ISO File using PowerShell

  • If you’re creating complex PowerShell scripts like this, you should already be aware that setting the AllowTelemetry key in the registry, will have the same effect as using the Local Group Policy Editor to set one on of the 4 allowed levels of Data Reporting. You should also be aware that setting it to Zero is only possible on Windows Enterprise and if you choose to do it anyway…. for example, if you set this key to 0 on a Windows Pro copy…. the system will revert to the level of Diagnostic Data that Microsoft sees fit, and this effect will be invisible. You can verify what I’m telling you by simply visiting the relevant Group Policy, setting it to 4 then refresh Regedit (press F5) and watch as the AllowTelemetry key changes to 4. If you’re not on Enterprise then then 1 is the lowest setting you can use.

    Basically, if you don’t know what you’re doing by poking around in the registry, you may very well be enabling more Telemetry while you think you’re turning it off.

    Key: HKLMSOFTWAREPoliciesMicrosoftWindowsDataCollection”AllowTelemetry”

    Local Group Policy: Computer ConfigurationAdministrative TemplatesWindows ComponentsData Collection and Preview BuildsAllow Telemetry (it tells you that you can only set 0 if you’re running Enterprise.)

    *I’d never recommend that anybody run a script that automatically makes a bunch of changes to their Windows in the hopes of tuning it for privacy reasons. The best thing to do is do the research yourself and understand what it is that you’ll be changing.

  • A comment on the previous post about deploying Chrome extensions posed the question of whether PowerShell could be used to remove Chrome extensions.

  • thanks for sharing!
    i am looking to make a script to do a hot clone(booteable) of disk….its posible to achive that on windows?
    Lets imagine:

    i have a 256 SSD disk with the default partitions that windows create….and a second HDD partition (lets say…500gb)

    so idea will be create the same parttion structure in HDD and a extra partition to hold the image of the partitions of SSD…

    launch in powershell the image of the parttions and hold in the extra partitions of HDD and then recover each image in the correspondent copied partitions of HDD…

    have sense?

  • Hi,

    Is there anyway to many different ad domain user on different client machines?
    in one step?

    Regards

  • I guess something has changed in PowerShell in the past three years, because despite following this guide to the letter it doesn’t work as described. Not sure why.

  • That wast my mistake. The methods just also apply to the latest PowerShell versions. We changed the wording.Thanks for the hint!

  • You said you would discuss changes in version 7 and 7.2, but I didn’t find that in the article.

  • Sponsor posted an update in the group Group logo of PowerShellPowerShell 1 week, 1 day ago

    Webinar: Simplify your VMware management with PowerShell!
    Creating new VMs, managing snapshots and changing VM configurations are just a few examples of recurring to-dos where PowerShell can help to simplify VMware administration.
    In this webinar, we will show you how to automate and delegate these tasks to helpdesk teams and even end users. This webinar is aimed at administrators, IT and DevOps professionals, PowerShell developers and IT managers.
    Register for free
  • It is important for an administrator to know what Windows PowerShell and PowerShell edition and version are installed on a system, especially due to script compatibility. This article covers all the ways to check the PowerShell version on Windows, Linux, and MacOS and offers tips and tricks. I will also discuss the changes in PowerShell 7 and PowerShell 7.2.Getting the PowerShell version in MacOS

  • Check out the difference between
    [powershell]Get-NetAdapter | Select-Object -ExpandProperty InterfaceAlias[/powershell]
    and
    [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]

    Cheers

  • 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:

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

    or

    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!

  • Load More
© 4sysops 2006 - 2022

CONTACT US

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

Sending

Log in with your credentials

or    

Forgot your details?

Create Account