Sign in to join the PowerShell Group
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.csvCan 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.
Stéphane van Gulick wrote a new post,
Create an Ansible inventory file with psansible.inventory and an Ansible inventory script in PowerShell 23 hours, 40 minutes ago
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.
Stephen joined the group
PowerShell 2 days, 20 hours ago
Emanuel Halapciuc commented on
Change remote IP address and DNS entry with a PowerShell script 3 days, 3 hours ago
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. 🙂Lee Roy Anthony commented on
Change remote IP address and DNS entry with a PowerShell script 3 days, 4 hours ago
I meant ‘forcing the codes’. Sorry for the typo.
Lee Roy Anthony commented on
Change remote IP address and DNS entry with a PowerShell script 3 days, 4 hours ago
I meant ‘forcing the codes…’. Sorry for the typo.
Lee Roy Anthony commented on
Change remote IP address and DNS entry with a PowerShell script 3 days, 4 hours ago
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!
Fox system commented on
WSUS reporting with PowerShell 5 days, 19 hours ago
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. ?
Raza commented on
Create a customized Windows 10 image using PowerShell and Hyper-V 6 days, 1 hour ago
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.
Emanuel Halapciuc commented on
Change remote IP address and DNS entry with a PowerShell script 6 days, 5 hours ago
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).
Lee Roy Anthony commented on
Change remote IP address and DNS entry with a PowerShell script 6 days, 5 hours ago
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 2This solution I got just from browsing backwards to the basics!
Thank you!!!
Lee Roy Anthony commented on
Change remote IP address and DNS entry with a PowerShell script 6 days, 10 hours ago
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!
Emanuel Halapciuc commented on
Change remote IP address and DNS entry with a PowerShell script 1 week ago
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. 🙂
Lee Roy Anthony commented on
Change remote IP address and DNS entry with a PowerShell script 1 week, 1 day ago
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
EthernetPS 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.Michael Pietroforte edited the doc How to create a Hyper-V VM with PowerShell in the group
PowerShell 1 week, 2 days ago
In this new post of my Hyper-V management series, I will explain how create a Hyper-VM with PowerShell.
- Load More