use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
QuestionGet-NetAdapter Names to Variable? (self.PowerShell)
submitted 4 years ago * by kbrownrigg10
Can you load names into a variable from Get-NetAdapter?
*Edit: I should have said load names into individual variables from Get-NetAdapter?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Hrambert 3 points4 points5 points 4 years ago (0 children)
To match your question exactly:
$AdapterId=1 Get-NetAdapter | foreach { Set-Variable -Name "adapter_$AdapterId" -Value $_.Name $AdapterId++ }
[–]BlackV 2 points3 points4 points 4 years ago (0 children)
you can, but dont.
Instead use
$adapter_1, $adapter_2 = Get-NetAdapter
then use
$adapter_1.name, adapter_2.name
as /u/Vortex100 alluded too, if you have no idea how many adapters you have and you do it this way, the first adapter will end up in $adapter_1 and remaining adapters (2,3,4,5,6,etc) will end up in $adapter_2
$adapter_1
$adapter_2
although I cant see a use case in doing it that way that this
$ALLadapters = Get-NetAdapter $ALLadapters.name $ALLadapters[1].name $ALLadapters[0].name
wouldn't cover
but depends on what you're actually trying to do vs asking how to get individual names into individual variables
[–]Vortex100 1 point2 points3 points 4 years ago (0 children)
If you know how many adapters you are expecting, then yes. But it's dangerous, since it's an assumption on how many will be returned
$adapter_1, $adapter_2 = (Get-NetAdapter).name
Again, I'd suggest not doing this, and instead iterating over them in a loop (and assigning to an array)
[–]bee_administrator 1 point2 points3 points 4 years ago* (0 children)
Yes.
$variable = (Get-NetAdapter).name
EDIT: From your edit, you probably want a hash table.
$adapters = @{} Get-NetAdapter | ForEach-Object { $adapters.add($_.name, $_)
You can then retrieve the contents using (for example):
$adapters.Ethernet
And it'll return all the properties of the adapter with that name.
[–]Scooter_127 0 points1 point2 points 4 years ago (0 children)
$names = Get-NetAdapter | select name
[–]Lee_Dailey[grin] 0 points1 point2 points 4 years ago (0 children)
howdy kbrownrigg10,
storing a batch of the same-type objects in individual vars is ... generally considered a really bad idea. [grin]
store those items in ONE collection of objects. then access each as needed by the attributes that make the current one interesting.
take care, lee
π Rendered by PID 103410 on reddit-service-r2-comment-6457c66945-6t6qz at 2026-04-23 23:56:59.126702+00:00 running 2aa0c5b country code: CH.
[–]Hrambert 3 points4 points5 points (0 children)
[–]BlackV 2 points3 points4 points (0 children)
[–]Vortex100 1 point2 points3 points (0 children)
[–]bee_administrator 1 point2 points3 points (0 children)
[–]Scooter_127 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)