hot to get network adapters names except microsoft's ones - powershell

Hi I want to get the name of all the network adapters from my computer except the Microsoft ones.
ServiceName : RTL8168
MACAddress : ---------------
AdapterType : Ethernet 802.3
DeviceID : 0
Name : D-Link DGE-528T Gigabit Ethernet Adapter
NetworkAddresses :
Speed : 1000000000
ServiceName : kdnic
MACAddress :
AdapterType :
DeviceID : 1
Name : Microsoft Kernel Debug Network Adapter
NetworkAddresses :
Speed :
ServiceName : e1express
MACAddress : ---------------
AdapterType : Ethernet 802.3
DeviceID : 2
Name : Intel(R) 82562V-2 10/100 Network Connection
NetworkAddresses :
Speed : 9223372036854775807
ServiceName : tunnel
MACAddress :
AdapterType : Tunnel
DeviceID : 3
Name : Microsoft ISATAP Adapter
NetworkAddresses :
Speed : 100000
ServiceName :
MACAddress :
AdapterType :
DeviceID : 4
Name : Microsoft Teredo Tunneling Adapter
NetworkAddresses :
Speed :
This is what I have so far (I don't know the correct regular expression that shows only the adapters that doesn't contain "Microsoft" on its Name object)
get-wmiobject win32_networkadapter | Where-Object {$_.Name -match "^[^M]"}
I want to get this output:
ServiceName : RTL8168
MACAddress : ---------
AdapterType : Ethernet 802.3
DeviceID : 0
Name : D-Link DGE-528T Gigabit Ethernet Adapter
NetworkAddresses :
Speed : 1000000000
ServiceName : e1express
MACAddress : -------------
AdapterType : Ethernet 802.3
DeviceID : 2
Name : Intel(R) 82562V-2 10/100 Network Connection
NetworkAddresses :
Speed : 9223372036854775807
Thank you guys in advance, I know this one is easy :)

In powershell something like
Get-NetAdapter | where-object Name -NotContains Microsoft
upd.: in comments already answered

Related

How Get All Camera Devices ID From PowerShell

I am trying to get all camera devices ID and respective names using PowerShell command line. I tried several commands, but nothing has done what I am aiming. Below my "best" approach:
Get-CimInstance Win32_PnPEntity | where caption -match 'camera'
output
Caption : Remote Desktop Camera Bus
Description : UMBus Enumerator
InstallDate :
Name : Remote Desktop Camera Bus
Status : OK
Availability :
ConfigManagerErrorCode : 0
ConfigManagerUserConfig : False
CreationClassName : Win32_PnPEntity
DeviceID : UMB\UMB\1&841921D&0&RDCAMERA_BUS
ErrorCleared :
ErrorDescription :
LastErrorCode :
PNPDeviceID : UMB\UMB\1&841921D&0&RDCAMERA_BUS
PowerManagementCapabilities :
PowerManagementSupported :
StatusInfo :
SystemCreationClassName : Win32_ComputerSystem
SystemName : DESKTOP
ClassGuid : {4d36e97d-e325-11ce-bfc1-08002be10318}
CompatibleID :
HardwareID : {UMB\UMBUS}
Manufacturer : Microsoft
PNPClass : System
Present : True
Service : umbus
PSComputerName :
I know, for example, that generally the integrated camera has a name "integrated camera" with a ID "0". But this is not what is being shown.
Get-CimInstance Win32_PnPEntity | ? { $_.service -eq "usbvideo" } | Select-Object -Property PNPDeviceID, Name

Get ADUser attributes without Get-ADUser

Is it possible to get current users AD attributes without Get-ADUser?
Am new to powershell. I need to get few attributes like title, email & department for user.
I tried use :
get-wmiobject -Class win32_useraccount -Filter "name='John.Doe'" | select *
PSComputerName : NY-Z343
Status : OK
Caption : BEAZL-INC\john.doe
PasswordExpires : False
__GENUS : 2
__CLASS : Win32_UserAccount
__SUPERCLASS : Win32_Account
__DYNASTY : CIM_ManagedSystemElement
__RELPATH : Win32_UserAccount.Domain="BEAZL-INC",Name="john.doe"
__PROPERTY_COUNT : 16
__DERIVATION : {Win32_Account, CIM_LogicalElement, CIM_ManagedSystemElement}
__SERVER : NY-Z343
__NAMESPACE : rootcimv2
__PATH : \BEAZL-INCrootcimv2:Win32_UserAccount.Domain="BEAZL-INC",Name="john.doe"
AccountType : 512
Description : Dude account for gaming
Disabled : False
Domain : BEAZL-INC
FullName : John Doe
InstallDate :
LocalAccount : False
Lockout : False
Name : john.doe
PasswordChangeable : True
PasswordRequired : False
SID : S-1-5-21-3384058-193304-10174538-501
SIDType : 1
Scope : System.Management.ManagementScope
Path : \\NY-Z343\root\clmv2:Win32_UserAccount.Domain="BEAZL-INC",Name="john.doe"
Options : System.Management.ObjectGetOptions
ClassPath : \\NY-Z34\root\clmv2:Win32_UserAccount
Properties : {AccountType, Caption, Description, Disabled...}
SystemProperties : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}
Qualifiers : {dynamic, Locale, provider, UUID}
Site :
Container :
Yes, you can use [adsisearcher], which is a type accelerator for .NET's DirectorySearcher class. This doesn't require installing anything additional.
Here's an example that will search for a user by the name attribute and return the title, mail, and department attributes:
# This is the search filter
$searcher = [adsisearcher]"(&(objectClass=user)(objectCategory=person)(name=John.Doe))"
# List all the propterties you want to use
$searcher.PropertiesToLoad.AddRange(#("title", "mail", "department"))
# By default, it will search the same domain as the logged in user.
# If you need to search a different domain, uncomment and edit this line.
# $searcher.SearchRoot = [adsi]"LDAP://example.com"
$user = $searcher.FindOne()
$title = $user.Properties["title"][0]

Get Devicename as String from MTP-Device

I try to automatically copy files from MTP-Devices (Smartphones) to my PC. I took several little code snippets from the internet for that and a lot of trial and error (several days), because I have no idea about powershell. But now everything works fine so far. The only problem is, that I have to manually put the name in for a device in my script, every time I took an other device. So I'm searching for a solution to automatically get the name from the actual device and save it in a variable.
I have tried this code:
Get-WmiObject -class win32_pnpentity -computername localhost | where-object {$_.HardwareID -like "*MTP*"} | format-list
As result i get:
__GENUS : 2
__CLASS : Win32_PnPEntity
__SUPERCLASS : CIM_LogicalDevice
__DYNASTY : CIM_ManagedSystemElement
__RELPATH : Win32_PnPEntity.DeviceID="USB\\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_ANDROID\\6&5F679FC&0
&0000"
__PROPERTY_COUNT : 26
__DERIVATION : {CIM_LogicalDevice, CIM_LogicalElement, CIM_ManagedSystemElement}
__SERVER : EXO-SURFACE
__NAMESPACE : root\cimv2
__PATH : \\EXO-SURFACE\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_04E8&PID_6860&MS_COMP_MTP&SAM
SUNG_ANDROID\\6&5F679FC&0&0000"
Availability :
Caption : Galaxy S9+
ClassGuid : {eec5ad98-8080-425f-922a-dabf3de3f69a}
CompatibleID : {USB\MS_COMP_MTP, USB\Class_06&SubClass_01&Prot_01, USB\Class_06&SubClass_01,
USB\Class_06...}
ConfigManagerErrorCode : 0
ConfigManagerUserConfig : False
CreationClassName : Win32_PnPEntity
Description : SM-G965F
DeviceID : USB\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_ANDROID\6&5F679FC&0&0000
ErrorCleared :
ErrorDescription :
HardwareID : {USB\VID_04E8&PID_6860&REV_0400&MS_COMP_MTP&SAMSUNG_Android,
USB\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_Android,
USB\SAMSUNG_MOBILE&MS_COMP_MTP&SAMSUNG_Android, USB\SAMSUNG_MOBILE&MI_00...}
InstallDate :
LastErrorCode :
Manufacturer : Samsung Electronics Co., Ltd.
Name : Galaxy S9+
PNPClass : WPD
PNPDeviceID : USB\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_ANDROID\6&5F679FC&0&0000
PowerManagementCapabilities :
PowerManagementSupported :
Present : True
Service : WUDFWpdMtp
Status : OK
StatusInfo :
SystemCreationClassName : Win32_ComputerSystem
SystemName : EXO-SURFACE
PSComputerName : EXO-SURFACE
This looks very fine, because for the Name it's recognized as "Galaxy S9+" like it should. So do anyone here know, how to extract this Device Name into an variable? I would be very thankful, because I am a real noob in powershell and it's a project to help my parents, who have their problems with technology.

Receiving invalid data via WMI

I've had a script running for the better half of a year now that checks for disk space, should it be low it sends out an email been working just fine.
Today I received an alert saying that that Disk space was at 0gb.. I logged into the server and had about 30gbs available.
Part of code that checks the space.
[decimal]$thresholdspace = 5
$tableFragment= Get-WMIObject -ComputerName $computer Win32_LogicalDisk `
| select __SERVER, DriveType, VolumeName, Name, #{n='Size (Gb)' ;e={"{0:n2}" -f ($_.size/1gb)}},#{n='FreeSpace (Gb)';e={"{0:n2}" -f ($_.freespace/1gb)}}, #{n='PercentFree';e={"{0:n2}" -f ($_.freespace/$_.size*100)}} `
| Where-Object {$_.DriveType -eq 3 -and [decimal]$_.PercentFree -lt [decimal]$thresholdspace}
So I opened up an ISE session and did the following.
$computer = 'Server_01'
Get-WMIObject -ComputerName $computer Win32_LogicalDisk | select __SERVER, DriveType, VolumeName, Name,FreeSpace
and it responded with:
__SERVER : Server_01
DriveType : 2
VolumeName :
Name : A:
FreeSpace :
__SERVER : Server_01
DriveType : 3
VolumeName :
Name : C:
FreeSpace : 31372767232
__SERVER : Server_01
DriveType : 5
VolumeName :
Name : E:
FreeSpace :
So I then ran the part of my code that is getting space and it returned with the following:
__SERVER : Server_01
DriveType : 3
VolumeName :
Name : C:
Size (Gb) : 0.00
FreeSpace (Gb) : 0.00
PercentFree :
So I ran the simple WMI query and it responded with no data..
__SERVER : Server_01
DriveType : 2
VolumeName :
Name : A:
FreeSpace :
__SERVER : Server_01
DriveType : 3
VolumeName :
Name : C:
FreeSpace :
__SERVER : Server_01
DriveType : 5
VolumeName :
Name : E:
FreeSpace :
Any idea as to why I'm getting invalid or what appears to be incomplete data? I've never seen anything like this, and have not ran into this issue at all before. Nothing has changed on either server it is running from.

Powershell, get ip4v address of VM

I'm new to powershell and I"m trying to get just the IPv4 address of a vm and save it as a string.
I can get all network attributes like so:
PS C:\Windows\system32> get-vm | select -ExpandProperty networkadapters | select vmname, macaddress, switchname, ipaddres
sses
VMName MacAddress SwitchName IPAddresses
------ ---------- ---------- -----------
foobar vSwitch {192.0.2.1, fe80::84a...
I can get both the v4 and the v6 ip address
PS C:\Windows\system32> $IP = ( GEt-VM -ComputerName $HVCOMPUTERNAME -VMName $HVNAME | Get-VMNetworkAdapter).IpAddresses
PS C:\Windows\system32> $IP
192.0.2.1
fe80::d47e:
----------
How can I get just the v4 address as a string?
Update
It looks like there is no object property that just includes the v4 address
PS C:\Windows\system32> GEt-VM -ComputerName $HVCOMPUTERNAME -VMName $HVNAME | Get-VMNetworkAdapter | Format-List -Property *
IovWeight : 0
IovQueuePairsRequested : 1
IovQueuePairsAssigned : 0
IovInterruptModeration : Default
IovUsage : 0
ClusterMonitored : True
VirtualFunction :
IsLegacy : False
IsManagementOs : False
IsExternalAdapter : False
Id : Microsoft:xxxxxxxxxxx
AdapterId : xxxxxxxxxxx
DynamicMacAddressEnabled : True
MacAddress : 00155D5B9B14
MacAddressSpoofing : Off
SwitchId : xxxxxxxxxxx
Connected : True
PoolName :
SwitchName : vSwitch
AclList : {}
ExtendedAclList : {}
IsolationSetting : Microsoft.HyperV.PowerShell.VMNetworkAdapterIsolationSetting
CurrentIsolationMode : Vlan
RoutingDomainList : {}
DhcpGuard : Off
RouterGuard : Off
PortMirroringMode : None
IeeePriorityTag : Off
VirtualSubnetId : 0
DynamicIPAddressLimit : 0
StormLimit : 0
AllowTeaming : Off
VMQWeight : 100
IPsecOffloadMaxSA : 512
VmqUsage : 0
IPsecOffloadSAUsage : 0
VFDataPathActive : False
VMQueue :
MandatoryFeatureId : {}
MandatoryFeatureName : {}
VlanSetting : Microsoft.HyperV.PowerShell.VMNetworkAdapterVlanSetting
BandwidthSetting :
BandwidthPercentage : 0
TestReplicaPoolName :
TestReplicaSwitchName :
StatusDescription : {OK}
Status : {Ok}
IPAddresses : {192.0.2.1, fe80::xxxxxxxxxxx}
ComputerName : xxxxxxxxxxx
Name : Network Adapter
IsDeleted : False
VMId : xxxxxxxxxxx
VMName : foobar
VMSnapshotId : 00000000-0000-0000-0000-000000000000
VMSnapshotName :
Key :
You can just filter out any IP that has ":" in it, as such:
$IP | ?{$_ -notmatch ':'}
Assuming there is only 1 V4 address, and that the v4 address is the first output, do:
$IP = ( GEt-VM -ComputerName $HVCOMPUTERNAME -VMName $HVNAME | Get-VMNetworkAdapter).IpAddresses | Select-String -List 1
IPAddresses looks like an array or list and you only want the first one so try:
$IP = ( GEt-VM -ComputerName $HVCOMPUTERNAME -VMName $HVNAME | Get-VMNetworkAdapter).IpAddresses[0]