Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Custom parameter help

$
0
0

Hi All,

Another chapter completed from Learn Powershell in a month of lunches (whoohoo!). After doing the lab I said well this script is pretty handy, but I would like to make a few changes to suite my needs. The script should be getting the physical adapters, but for some reason my VMware, and cisco anyconnect adapters are showing up in the list. Not the worst but I would like to filter by device id if possible, and only select say 1,2. Essentially the below works to filter by 1 device id, but I cannot specify * or 1,2,5 etc. Any guidance is greatly appreciated. I would like the default to show all the physical adapters, and have the freedom to filter as needed.

[CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "Please enter a valid computer name to query.")] [Alias('hostname')] [string]$computername = 'localhost', [int[]] $deviceid = 1 ) Get-WmiObject -Class Win32_NetworkAdapter -ComputerName $computername -Filter "deviceid=$deviceid" | Where-Object -Property PhysicalAdapter -eq $true | Format-Table -Property Name, DeviceID, MACAddress, AdapterType, @{Name='Speed (MB)'; Expression = {$_.Speed / 1MB -as [int]}} 

submitted by /u/grrrrshell
[link] [comments]

The post Custom parameter help appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images