Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Get-Inventory {
- $strFilter = "computer"
- $objDomain = New-Object System.DirectoryServices.DirectoryEntry
- $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
- $objSearcher.SearchRoot = "LDAP://OU=X,DC=Y,DC=Z" //Update that line to mauch that desired OU CN
- $objSearcher.SearchScope = "Subtree"
- $objSearcher.PageSize = 1000
- $objSearcher.PropertiesToLoad.Add("Name") | Out-Null
- $objSearcher.Filter = "(objectCategory=$strFilter)"
- $colResults = $objSearcher.FindAll()
- $global:computer_array = @()
- foreach ($objResult in $colResults) {
- If (Test-Connection -ComputerName $objResult.Properties.name -Quiet -Count 1)
- {
- Try
- {
- $CS = gwmi win32_computersystem -ComputerName $objResult.Properties.name |
- select name,model
- if ($Error[0].Exception -match "HRESULT: 0x800706BA")
- {
- $Error.Clear()
- continue
- }
- $OS = gwmi win32_operatingsystem -ComputerName $objResult.Properties.name |
- select caption,version,osarchitecture,serialnumber
- if ($Error[0].Exception -match "HRESULT: 0x800706BA")
- {
- $Error.Clear()
- continue
- }
- $obj = New-Object PSObject -Property @{
- Name=$CS.name
- Model=$CS.Model
- OS=$OS.caption
- Architecture = $OS.osArchitecture
- SerialNumber = $OS.SerialNumber
- Version = $OS.version
- }
- $global:computer_array += $obj
- }
- catch [Exception]
- {
- Write-Host "Error $objResult.Properties.name"
- }
- }
- Else { "Unable to contact $strComputerName" }
- }
- Write-Output $computer_array
- }#End Function
- Function Import-ListItems {
- Param(
- $site = "http://intranet", //update to list URL
- $spweb = (Get-SPWeb -Identity $site),
- $List = $spweb.lists["Inventory"]
- )
- Foreach($row in $computer_array) {
- $item = $List.items.add()
- $item["Title"] = $row.Name
- $item["Model"] = $row.Model
- $item["Architecture"]= $row.Architecture
- $item["Serial Number"] = $row.SerialNumber
- $item["OS Version"] = $row.version
- $item.update()
- }
- }#End Function
- Get-Inventory $computer_array
- Import-ListItems -site "http://intranet" //update to list URL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement