Skip to content

Instantly share code, notes, and snippets.

@matsubo

matsubo/gcpw.ps1 Secret

Last active November 11, 2020 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsubo/97e7d42c7bad1b5f76905c0351f71f87 to your computer and use it in GitHub Desktop.
Save matsubo/97e7d42c7bad1b5f76905c0351f71f87 to your computer and use it in GitHub Desktop.
<# このスクリプトは、https://tools.google.com/dlpage/gcpw/ から Windows 用 Google 認証情報プロバイダを
ダウンロードし、インストールして設定します。
スクリプトを使用するには Windows 管理者権限が必要です。#>
<# ログインを許可するドメインに次のキーを設定します。
例:
$domainsAllowedToLogin = "acme1.com,acme2.com"
#>
$domainsAllowedToLogin = "minedia.com"
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName PresentationFramework
<# 1 つ以上のドメインが設定されているかどうかを確認します #>
if ($domainsAllowedToLogin.Equals('')) {
$msgResult = [System.Windows.MessageBox]::Show('The list of domains cannot be empty! Please edit this script.', 'GCPW', 'OK', 'Error')
exit 5
}
function Is-Admin() {
$admin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match 'S-1-5-32-544')
return $admin
}
<# 現在のユーザーが管理者かどうかを確認し、管理者でない場合は終了します。#>
if (-not (Is-Admin)) {
$result = [System.Windows.MessageBox]::Show('Please run as administrator!', 'GCPW', 'OK', 'Error')
exit 5
}
<# ダウンロードする GCPW ファイルを選択します。32 ビット版と 64 ビット版では名前が異なります #>
$gcpwFileName = 'gcpwstandaloneenterprise.msi'
if ([Environment]::Is64BitOperatingSystem) {
$gcpwFileName = 'gcpwstandaloneenterprise64.msi'
}
<# GCPW インストーラをダウンロードします。#>
$gcpwUrlPrefix = 'https://dl.google.com/credentialprovider/'
$gcpwUri = $gcpwUrlPrefix + $gcpwFileName
Write-Host 'Downloading GCPW from' $gcpwUri
Invoke-WebRequest -Uri $gcpwUri -OutFile $gcpwFileName
<# GCPW インストーラを実行し、インストールが完了するまで待ちます #>
$arguments = "/i `"$gcpwFileName`""
$installProcess = (Start-Process msiexec.exe -ArgumentList $arguments -PassThru -Wait)
<# インストールが成功したかどうかを確認します #>
if ($installProcess.ExitCode -ne 0) {
$result = [System.Windows.MessageBox]::Show('Installation failed!','GCPW', 'OK', 'Error')
exit $installProcess.ExitCode
}
else {
$result = [System.Windows.MessageBox]::Show('Installation completed successfully!', 'GCPW', 'OK', 'Info')
}
<# 許可されたドメインで必要なレジストリキーを設定します #>
$registryPath = 'HKEY_LOCAL_MACHINE\Software\Google\GCPW'
$name = 'domains_allowed_to_login'
[microsoft.win32.registry]::SetValue($registryPath, $name, $domainsAllowedToLogin)
$domains = Get-ItemPropertyValue HKLM:\Software\Google\GCPW -Name $name
if ($domains -eq $domainsAllowedToLogin) {
$msgResult = [System.Windows.MessageBox]::Show('Configuration completed successfully!', 'GCPW', 'OK', 'Info')
}
else {
$msgResult = [System.Windows.MessageBox]::Show('Could not write to registry. Configuration was not completed.', 'GCPW', 'OK', 'Error')
}
<# オプション設定 #>
[microsoft.win32.registry]::SetValue($registryPath, 'validity_period_in_days', 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment