-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-GoogleDrive.ps1
More file actions
103 lines (85 loc) · 3.64 KB
/
Install-GoogleDrive.ps1
File metadata and controls
103 lines (85 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<#
.SYNOPSIS
Install Google Drive for Desktop and configure mount point
.DESCRIPTION
Downloads and installs Google Drive for Desktop, configures mount as G:, and creates startup shortcut.
.EXAMPLE
.\Install-GoogleDrive.ps1
.NOTES
Requires Administrator privileges
Logs to C:\Logs\GoogleDrive_Install_YYYYMMDD_HHMMSS.log
.INTUNE WIN32 APP DEPLOYMENT
Install command: powershell.exe -ExecutionPolicy Bypass -NoProfile -File "Install-GoogleDrive.ps1"
Install behavior: System context
Detection: File exists %ProgramFiles%\Google\Drive File Stream\GoogleDriveFS.exe
Return codes: 0=success, 1=failure
#>
#Requires -RunAsAdministrator
# Logging setup
$LogDir = "C:\Logs"
if (-not (Test-Path $LogDir)) {
New-Item -Path $LogDir -ItemType Directory -Force | Out-Null
}
$Timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$LogFile = "$LogDir\GoogleDrive_Install_$Timestamp.log"
function Write-Log {
param(
[string]$Message,
[ValidateSet('INFO','WARNING','ERROR')]
[string]$Level = 'INFO'
)
$LogMessage = "{0} [{1}] {2}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Level, $Message
Add-Content -Path $LogFile -Value $LogMessage
switch ($Level) {
'ERROR' { Write-Host $Message -ForegroundColor Red }
'WARNING' { Write-Host $Message -ForegroundColor Yellow }
default { Write-Host $Message }
}
}
Write-Log "Starting Google Drive for Desktop installation"
# Check if already installed
$GoogleDriveExe = "$env:ProgramFiles\Google\Drive File Stream\GoogleDriveFS.exe"
if (Test-Path $GoogleDriveExe) {
$version = (Get-Item $GoogleDriveExe).VersionInfo.FileVersion
Write-Log "Google Drive already installed (version: $version)" -Level WARNING
Write-Log "To reinstall, uninstall first via Windows Settings"
exit 0
}
$InstallerPath = "$env:TEMP\GoogleDriveSetup.exe"
$DownloadUrl = "https://dl.google.com/drive-file-stream/GoogleDriveSetup.exe"
try {
Write-Log "Downloading Google Drive installer from $DownloadUrl"
Invoke-WebRequest -Uri $DownloadUrl -OutFile $InstallerPath -ErrorAction Stop
Write-Log "Download completed: $InstallerPath"
Write-Log "Starting silent installation"
$Process = Start-Process -FilePath $InstallerPath -ArgumentList "/silent" -Wait -PassThru -ErrorAction Stop
if ($Process.ExitCode -ne 0) {
Write-Log "Installation failed with exit code: $($Process.ExitCode)" -Level ERROR
exit 1
}
Write-Log "Installation completed successfully"
Remove-Item -Path $InstallerPath -Force -ErrorAction SilentlyContinue
Write-Log "Configuring mount point as G:"
$RegPath = "HKCU:\Software\Google\DriveFS"
New-Item -Path $RegPath -Force -ErrorAction Stop | Out-Null
Set-ItemProperty -Path $RegPath -Name "DefaultMountPoint" -Value "G:\" -ErrorAction Stop
Write-Log "Mount point configured"
$DriveExe = "$env:ProgramFiles\Google\Drive File Stream\GoogleDriveFS.exe"
if (Test-Path $DriveExe) {
Write-Log "Creating startup shortcut"
$StartupPath = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\GoogleDrive.lnk"
$Shell = New-Object -ComObject WScript.Shell
$Shortcut = $Shell.CreateShortcut($StartupPath)
$Shortcut.TargetPath = $DriveExe
$Shortcut.Save()
Write-Log "Startup shortcut created"
} else {
Write-Log "GoogleDriveFS.exe not found at expected path, skipping startup shortcut" -Level WARNING
}
Write-Log "Google Drive for Desktop installation and configuration completed successfully"
exit 0
}
catch {
Write-Log "Failed to install or configure Google Drive: $_" -Level ERROR
exit 1
}