Jump to content

rekabbelac

Members
  • Content count

    1
  • Joined

  • Last visited

  1. I threw together a Powershell script that queries and modifies the SQL database to do this. I'm pretty sure it could be done completely as a SQL query, but my SQL ability is pretty limited. $sqlserver = 'localhost' $database = 'pcmonitor' $computeridentifiers = @(Invoke-Sqlcmd -ServerInstance $sqlserver -Database $database -Query "SELECT [identifier] FROM [pcmonitor].[dbo].[Computers] WHERE [accountId] =1 AND [active] =1;") | select-object -expand identifier $useridentifiers = @(Invoke-Sqlcmd -ServerInstance $sqlserver -Database $database -Query "SELECT [id] FROM [pcmonitor].[dbo].[Accounts] WHERE [id] != 1 AND [active] =1;") | select-object -expand id foreach ($useridentifier in $useridentifiers) { foreach ($computeridentifier in $computeridentifiers) { $computeridentifier Invoke-Sqlcmd -ServerInstance $sqlserver -Database $database -Query "IF NOT EXISTS (SELECT * FROM [pcmonitor].[dbo].[AssociatedAccounts] WHERE associatedAccountId = '$useridentifier' AND computerIdentifier like '$computeridentifier') INSERT INTO [pcmonitor].[dbo].[AssociatedAccounts] (primaryAccountId,computerIdentifier,associatedAccountId,readOnly,sendNotifications,version,active) VALUES (1,'$computeridentifier','$useridentifier',0,1,1,1)" } }
×