Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##lists Computers on network
- echo "Computer Names" >> Computers.txt
- $objDomain = New-Object System.DirectoryServices.DirectoryEntry
- IF($objDomain.exist)
- {$strCategory = "computer"
- $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
- $objSearcher.SearchRoot = $objDomain
- $objSearcher.Filter = ("(objectCategory=$strCategory)")
- $colProplist = "name"
- foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
- $colResults = $objSearcher.FindAll()
- foreach ($objResult in $colResults)
- {$objResult.Properties.name[0] >> Computers.txt ;Clear-Host} }
- else {
- Get-WmiObject Win32_ComputerSystem | Foreach-Object {$compname =$_.Name}
- $compname >> Computers.txt }
- #gets info from computers on network
- $computers = Get-Content .\computers.txt
- foreach ($comp in $computers)
- {
- $cimsession = New-CimSession -ComputerName $comp -ErrorAction SilentlyContinue
- $computerSystem = Get-CimInstance CIM_ComputerSystem -CimSession $cimsession
- $computerBIOS = Get-CimInstance CIM_BIOSElement -CimSession $cimsession
- $computerOS = Get-CimInstance CIM_OperatingSystem -CimSession $cimsession
- $computerCPU = Get-CimInstance CIM_Processor -CimSession $cimsession
- $computerHDD = Get-CimInstance -ClassName win32_logicaldisk -CimSession $cimsession | Where {$_.drivetype -eq "3" -and $_.deviceid -like "C:" } | Select-Object @{l="Freespace";e={[math]::round($_.freespace/1GB)}}
- $outputFile = ".\{0}-{1:yyyyMMddHHmm}.csv" -f $env:COMPUTERNAME,(Get-Date)
- $inventory = New-Object psobject -property @{
- Name=$computersystem.name;
- Manufacturer=$computersystem.manufacturer;
- SerialNumber = $computerbios.serialnumber;
- Processor=$computerCPU.name;
- OS=$computerOS.caption;
- InstallDate=$computeros.InstallDate;
- FreeSpace=$computerHDD
- }
- }
- $inventory | export-csv $outputFile -Append -NoTypeInformation
- #attaches and sends network information
- function sendMail
- {
- #SMTP server name
- $From = ""
- $To = ""
- $Cc =
- $Subject = " $env:COMPUTERNAME"
- $Body = $body
- $Attachment = ".\inventory.cvs"
- $SMTPServer = "smtp.gmail.com"
- $SMTPPort = "587"
- $username = ""
- $password = ""
- $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
- $Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword
- #Sending email
- Send-MailMessage -From $From -To $To -Subject $Subject -SmtpServer $SMTPServer -Port 587 -UseSsl -Credential $Credentials -Attachment $Attachment
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement