Getting essential computer info for network admins

491 views Asked by At

I will be answering my own question in this thread but please feel free to give me constructing criticism on what I can do better with this script. I recently had to install VNC on mass across a lot of computers on a domain and needed some info about their PC, for example:

  1. Host name
  2. Username
  3. MAC Address
  4. IPv4 Address
  5. Domain name

Once all this info is gathered it is compiled into a text file and uploaded to a FTP server, to save files from being conflicted with the same name I set each file to be named the name of the user.

This is the first ever script and first experience I have had with powershell so please tell me if there is anything I can improve.

1

There are 1 answers

1
Phasmatis On
function Get-MACAddress {
    ipconfig /all | findstr "Physical" | Where-Object {$_.length -lt 58}
}
function Get-IPAddress {
    ipconfig | findstr "IPv4 Address"
}
function Get-HostName {
   get-content env:computername
}
function Get-UserName{
     get-content env:UserName
}
function Get-DomainName{
get-content env:USERDOMAIN
}
function CreateCSVdocument {
    Get-MACAddress | New-Item C:\Users\$($env:username)\Documents\$($env:username).txt -type file     -force 
    Add-Content C:\Users\$($env:username)\Documents\$($env:username).txt " "

Get-IPAddress | Add-Content C:\Users\$($env:username)\Documents\$($env:username).txt
Add-Content C:\Users\$($env:username)\Documents\$($env:username).txt " "

Add-Content C:\Users\$($env:username)\Documents\$($env:username).txt "Hostname:"
Get-Hostname | Add-Content C:\Users\$($env:username)\Documents\$($env:username).txt
Add-Content C:\Users\$($env:username)\Documents\$($env:username).txt " "

Add-Content C:\Users\$($env:username)\Documents\$($env:username).txt "User:"
Get-UserName | Add-Content C:\Users\$($env:username)\Documents\$($env:username).txt
Add-Content C:\Users\$($env:username)\Documents\$($env:username).txt " "

Add-Content C:\Users\$($env:username)\Documents\$($env:username).txt "Domain:"
Get-DomainName | Add-Content C:\Users\$($env:username)\Documents\$($env:username).txt
}
function FTPUpload {
$Dir="C:\Users\$($env:username)\Documents\$($env:username).txt"    

#ftp server 
$ftp = "ftpserver" 
$user = "username" 
$pass = "password"  

$webclient = New-Object System.Net.WebClient 

$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  

#list every sql server trace file 
foreach($item in (dir $Dir "$($env:username).txt")){ 
    "Uploading $item..." 
    $uri = New-Object System.Uri($ftp+$item.Name) 
    $webclient.UploadFile($uri, $item.FullName) 
} 

}
Get-DomainName
Get-IPAddress
Get-MACAddress
Get-HostName
Get-UserName
CreateCSVdocument
FTPUpload