John Myers
asked on
Merge WMI scripts into one
I have three scripts that I run in PowerShell to get some information I need from remote workstations. I would like this to be accomplished with just one script instead of three. What I need to get from the remote stations is:
Hostname
IP Address
MAC Address
Operating System
Determine if the workstation is a 32-bit or 64-bit
Serial Number or Service Tag Number
I need to be able run these scripts using a list of either Hostnames or IP Addresses in a text file or csv file. The reults also have to be exported to a CSV file.
Here are the scripts I use. Not pretty, but they work.
Any help would be much appreciated.
Hostname
IP Address
MAC Address
Operating System
Determine if the workstation is a 32-bit or 64-bit
Serial Number or Service Tag Number
I need to be able run these scripts using a list of either Hostnames or IP Addresses in a text file or csv file. The reults also have to be exported to a CSV file.
Here are the scripts I use. Not pretty, but they work.
Get-Content C:\Users\username\Desktop\IPs.txt |
Where-Object { Test-Connection $_ -Count 2 -Quiet } |
ForEach-Object {
$IPAddress = $_
Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE' -Computer $IPAddress |
Where-Object { $_.IPAddress -contains $IPAddress } |
Select-Object @{n='IPAddress';e={ $IPAddress }}, MACAddress, DNSHostName
} | Export-Csv C:\Users\username\Desktop\MACAddressReport.csv -NoTypeInformation
$computerlist = Get-Content C:\Users\username\Desktop\IPs.txt
foreach ($computer in $computerlist) {
if((Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{
Get-WMIObject Win32_OperatingSystem -ComputerName $computer |
select-object CSName, Caption | export-csv -Path C:\Users\username\Desktop\MACAddressReport-2.csv -NoTypeInformation -Append
}
}
get-content C:\Users\username\Desktop\HostNames.txt |
select-object `
@{n = 'IP'; e = { [Net.Dns]::GetHostEntry($_).AddressList } },
@{n= 'Name'; e = { $_ } } |
Export-Csv C:\Users\username\Desktop\IPAddressReport.csv -NoTypeInformation
Any help would be much appreciated.
ASKER
Sorry I have been out of the country for a while and not able to work on this.
This script worked great, but was wondering how I could add in the TPM version for each machine. I have messed around with it a bit but cannot get it working.
Any ideas?
Thanks.
This script worked great, but was wondering how I could add in the TPM version for each machine. I have messed around with it a bit but cannot get it working.
Any ideas?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank. I owe you.
Solution provided.
Open in new window