Created
October 23, 2020 03:37
-
-
Save sugimomoto/5afbefb50e8531d504982b1aa312f568 to your computer and use it in GitHub Desktop.
ZoomReplication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ライブラリ読み込み | |
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Data") | |
# DB接続 | |
$connectionString = "DSN=CData API Zoom;" | |
$odbcCon = New-Object System.Data.Odbc.OdbcConnection($connectionString) | |
$odbcCon.Open() | |
# コマンドオブジェクト作成 | |
$odbcCmd = New-Object System.Data.Odbc.OdbcCommand | |
$odbcCmd.Connection = $odbcCon | |
$users = @() | |
$meetings = @() | |
# ユーザーの取得 | |
$odbcCmd.CommandText = "SELECT * FROM Users" # User一覧を取得 | |
$odbcReader = $odbcCmd.ExecuteReader() | |
while ($odbcReader.Read()) { | |
$users += $odbcReader["Id"].ToString() | |
} | |
$odbcReader.Dispose() | |
# ミーティングの取得 | |
foreach($user in $users){ | |
$odbcCmd.CommandText = "SELECT * FROM Meetings WHERE UserId = '" + $user + "' AND StartTime < TODAY()" # 過去のミーティング一覧を取得 | |
$odbcReader = $odbcCmd.ExecuteReader() | |
while ($odbcReader.Read()) { | |
$meetings += $odbcReader["Id"].ToString() | |
} | |
$odbcReader.Dispose() | |
} | |
# Meetingのレプリケーション | |
foreach($meeting in $meetings){ | |
$odbcCmd.CommandText = "CACHE SELECT * FROM Meeting WHERE Id = '" + $meeting + "';" | |
$odbcCmd.ExecuteNonQuery() | |
$odbcReader.Dispose() | |
} | |
# PastMeeting のレプリケーション | |
foreach($meeting in $meetings){ | |
$odbcCmd.CommandText = "CACHE SELECT * FROM PastMeetings WHERE Id = '" + $meeting + "';" | |
$odbcCmd.ExecuteNonQuery() | |
$odbcReader.Dispose() | |
} | |
# コマンドオブジェクト破棄 | |
$odbcCmd.Dispose() | |
# DB切断 | |
$odbcCon.Close() | |
$odbcCon.Dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment