Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Simple powershell help

$
0
0

Objective: I want to pull basic information used for inventoring new workstations. These include IP settings, User accounts (Passwords would be nice), OS info, HDD info.

I have made this code from https://www.youtube.com/watch?v=-Ya1dQ1Igkc in an attempt to learn powershell. 

My issue:  When i run the script, the get-wmiobject Win32_NtworkAdapterConfiguration returns multiple values in an array, because of my personal connection types. 

Resolution: I would like to select only those NIC that are to be used, In most cases there is only one NIC and this would not be an issue, but if i were to run this on a workstation that is using multiple connections i would not want to return the incorrect IP address of the server. Also this is returning $null for network connections that do not use DHCP or have an IP address. Maybe have the command filter to only have Network connections displayed that have an IP address.

Powershell
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<# This is to gather NVR info#>#Need to compare the NetworkAdapter.MACAddress to th NetworkAdapterConfiguration.Macaddress to match them up.$os=Get-WmiObject-Classwin32_OperatingSystem|SelectCSName,Name,ServicePackMajorVersion$user=Get-WmiObjectWin32_UserAccount-PropertyName-filterLocalAccount=TRUE|Select-PropertyName$ip=Get-WmiObjectwin32_NetworkAdapter|selectNetConnectionID,NetConnectionStatus,PhysicalAdapter,MACAddress|Where-Object-PropertyPhysicalAdapter-eq'TRUE'|Where-Object-PropertyNetConnectionStatus-eq'2'$ipsettings=Get-WmiObjectwin32_NetworkAdapterConfiguration|selectMACAddress,IPSubnet,IPAddress,DHCPEnabled,DHCPServer,DNSServerSearchOrder,DefaultIPGateway|Where-Object-PropertyIPAddress$hdd=Get-WmiObjectwin32_diskDrive|selectModel,SerialNumber,InterfaceType,Size$prop=@{'ComputerName'=$os.CSName;'OS'=$os.Name;'SPVersion'=$os.ServicePackMajorVersion;'Accounts'=$user.Name;'ConnName'=$ip.NetConnectionID;'ConnMAC'=$ipsettings.MACAddress;'ConnIP'=$ipsettings.IPAddress;'ConnSUB'=$ipsettings.IPSubnet;'ConnDHCPenabled'=$ipsettings.DHCPEnabled;'ConnDHCPServer'=$ipsettings.DHCPServer;'ConnDNS'=$ipsettings.DNSServerSearchOrder;'ConnGW'=$ipsettings.DefaultIPGateway;'HDModel'=$hdd.Model;'HDSerial'=$hdd.SerialNumber;'HDType'=$hdd.InterfaceType;'HDSize'=$hdd.Size;}$obj=New-Object-TypeNamePSObject-Property$propWrite-Output$obj

Viewing all articles
Browse latest Browse all 15370

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>