• Is there really still no way to automate the login process? I know with Connect-MicrosoftTeams I can very easily pass credentials too it and automate a script. This module would be perfect if I could automate the login process.

  • The PowerShell module psansible.Inventory allows you to simplify the dynamic creation of your Ansible inventory with the help of an Ansible inventory script. You can retrieve data from your preferred sources, structure the data, and create a standardized Ansible inventory.

  • Well, I also introduced you to filtering. And I’d definitely use Where-Object instead of more convoluted syntax and arrays for that purpose.
    Those are great tools and just as essential for other purposed, but not for this. I mentioned them here just to show there are more ways to accomplish something. And I also mentioned there are more ways, and that you should use the most suitable one for each case. 🙂

  • I meant ‘forcing the codes’. Sorry for the typo.

  • I meant ‘forcing the codes…’. Sorry for the typo.

  • Hi Emanuel!

    While happily looking at what I’ve been learning, there’s this realization (and warning) that I’m forching the codes to just ‘stop’ at the 1st record/occurence of ‘Ethernet 2’. What if there’s more? What if the value ‘Ethernet 2’ appears on the 2nd, 3rd, so on…? How will I be able to capture it if it’s not on the 1st record? Meaning, how will I be able to capture ‘Ethernet 2’ in InterfaceAlias when/if I don’t know when it will appear?

    You’ve introduced me to string formatting in your latest reply. Thank you!

  • Hi Alex, I’m telling you that I also have the same error as Luciano, but in my case, according to your comment, I don’t use a signature certificate on my server. ?

  • Hi Wolfgang
    When i try to personalize things, it is asking for product key.

  • In my last article, we created a new VM for Kali Linux, mounted the ISO file to its virtual DVD drive, and changed the boot order so that the VM could boot from the virtual DVD drive. Here, I will show how to start and stop a Hyper-V with PowerShell. You’ll also learn how to disable secure boot with PowerShell.Stop a Hyper V VM with PowerShell

  • Good, finally! :))
    You could have also done
    Get-NetAdapter | where InterfaceAlias -like “Ethernet 2”
    or whatever the NIC Alias was.
    This one is less nice and a bit unpredictable, but it does the same thing.

    There are many ways to achieve something. In the long run, I’d suggest you pick an option that’s reasonably fast and easy to understand for a colleague that’s looking at a script (or you in 6 months, like Mr. Jeff Hicks always says).

  • Hi Emanuel!

    I finally got it!

    I just had to use Select-Object’s limiter command!

    PS C:Windowssystem32> Invoke-Command -VMName Win10VMTest004 -ScriptBlock {
    $InterfaceAlias2 = Get-NetAdapter | Select-Object -First 1 -ExpandProperty InterfaceAlias
    $InterfaceIndex2 = Get-NetAdapter | Select-Object -First 1 -ExpandProperty InterfaceIndex
    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:
    Ethernet 2

    This solution I got just from browsing backwards to the basics!

    Thank you!!!

  • Hi Emanuel!

    You’re right. 🙂

    These codes are meant to simulate if I’ll be able to get the value of InterfaceIndex once I encounter a value of ‘Ethernet 2’ in InterfaceAlias. I’ve made $InterfaceIndex4Set just so I can ‘see’ what’s inside it, after the movement of whatever is inside of InterfaceIndex. However, the obvious obstacle for me is that InterfaceIndex keeps on giving out 2 values, which is ‘7’ and ‘4’. I only need the 1st value of ‘7’ to appear once the IF statement gets satisfied with an InterfaceAlias value of ‘Ethernet 2’.

    What I want to do is to get all InterfaceAlias ‘Ethernet 2’ (and nothing else) and then use it’s corresponding InterfaceIndex, which should also have one value only. But I always get 2 values.

    Thank you!

  • Well, if you have more than one NIC, then you have an array. To be honest, I’m not very sure about what you’re doing (like what is $InterfaceIndex4Set).

    I think before you get into deeper stuff it would help you greatly to get more comfortable with the basic workings of PowerShell. Otherwise you’d try to drive a Formula 1 car after you just got your driver’s license.

    Until then, even if you get something right (or it would seem to be right), then the result of your script might not be what it seems, and it could come back to haunt you. Usually that happens right before you plan to go on vacation, or immediately after. 🙂

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

    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.

  • 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