# Assumes database is Inventory.accdb # Assumes table name is SPInventory # Assumes column names are ComputerName and SPVersion # and that both columns are text (not numeric) values function GetSP($computer) { $wmi = gwmi win32_operatingsystem -computer $computer foreach ($item in $wmi) { $item.servicepackmajorversion } } function SetSP($computer,$spack) { $connstr = "Provider=Microsoft.ACE.OLEDB.12.0;" + ' "Data Source=C:\users\user\documents\inventory.accdb" + ' ";Persist Security Info=False;" # Open Connection $conn = new-object system.data.oledb.oledbconnection $conn.ConnectionString = $connstr $conn.open() # Create query $query = "UPDATE SPInventory SET SPVer = '$spack' " + ' "WHERE ComputerName = '$computer'" # Execute query $cmd = New-Object system.Data.OleDb.OleDbCommand $cmd.connection = $conn $cmd.commandtext = $query $cmd.executenonquery() $conn.close() } [system.refection.assembly]::LoadWithPartialName("System.Data") # Connection String $connstr = "Provider=Microsoft.ACE.OLEDB.12.0;" + ' "Data Source=C:\users\user\documents\inventory.accdb" + ' ";Persist Security Info=False;" # Open Connection $conn = new-object system.data.oledb.oledbconnection $conn.ConnectionString = $connstr $conn.open() # Create query $query = "SELECT ComputerName, SPVersion FROM SPInventory" # Get Records $cmd = New-Object system.Data.OleDb.OleDbCommand $cmd.connection = $conn $cmd.commandtext = $query $reader = $cmd.executereader() # Read rows While ($reader.read()) { $computer = $reader.getvalue(0) $spack = GetSP $computer SetSP $computer $spack } # Close everything $reader.close() $conn.close()