• excellent description, thanks. I get a authorisation error when connting to linux based target. is there anyway to connect ? Microsoft unfortunately removed the iscsi app from Windows 11

  • Hi David
    I was looking for this for longtime. But I have one more questions. I am very new in this scripting world but learning… I am trying to create a script that will install printer package onto remote machine. when I will run the script it will open the dialog box to select the printer package. I got it so far to select now how can I parse that to copy the selected file to the remote machine. I know the copy part but wondering how to use this dialog box part to select in the copy portion. I would appreciate your answer if you can. Thanks a lot in advance.

  • is there any way we can use it with pssession and use invoke command to reach multiple servers?

    like instead of this
    .Get-FileVersionInfoRemotely.ps1 -ComputerName (get-content C:TempComputers.txt) -Path C:Windowssystem32ntoskrnl.exe -OutputFile C:TempOutputFileVer1.csv

    Can we use like this below?

    $Computers = Get-Content “C:TempComputers.txt”

    $Sessions = New-PSSession -ComputerName $Computers
    foreach($line in $Computers)
    {
    Invoke-Command -ComputerName (get-content $line) -FilePath .Get-FileVersionInfoRemotely.ps1 -Path C:Windowssystem32ntoskrnl.exe -OutputFile C:TempOutputFileVer1.csv
    }

    I am unable to run above getting error

    I am not that much good in powershell can someone help so I can reach somany servers using winrm

  • 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.
    Or
    (Get-NetAdapter)[0].InterfaceAlias
    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:
    7
    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:
    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.

  • 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