-
Notifications
You must be signed in to change notification settings - Fork 0
/
backgrounds.ps1
72 lines (69 loc) · 3.25 KB
/
backgrounds.ps1
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
# Create variables
$sourcefolder = "{Source Folder Here}" # Set the share and folder where you put the custom backgrounds
$TeamsStarted = "$env:APPDATA\Microsoft\Teams"
$DirectoryBGToCreate = "$env:APPDATA\Microsoft\Teams\Backgrounds"
$Uploadfolder = "$env:APPDATA\Microsoft\Teams\Backgrounds\Uploads"
$Logfile = "$env:LOCALAPPDATA\Logs\BG-copy.log"
$Logfilefolder = "$env:LOCALAPPDATA\Logs"
# Create logfile and function
# Check if %localappdata%\Logs is present, if not create folder and logfile
if (!(Test-Path -LiteralPath $Logfilefolder -PathType container)) {
try {
New-Item -Path $Logfilefolder -ItemType Directory -ErrorAction Stop | Out-Null #-Force
New-Item -Path $Logfilefolder -Name "BG-copy.log" -ItemType File -ErrorAction Stop | Out-Null #-Force
Start-Sleep -s 10
} catch {
Write-Error -Message "Unable to create directory '$Logfilefolder' . Error was: $_" -ErrorAction Stop
}
"Successfully created directory '$Logfilefolder' ."
} else {
"Directory '$Logfilefolder' already exist"
}
# Clear the logfile before starting
Clear-Content $Logfile
# Create the logwrite function
Function LogWrite {
Param ([string]$logstring)
$Stamp = (Get-Date).toString("dd/MM/yyy HH:mm:ss")
$Line = "$Stamp $logstring"
Add-content $Logfile -value $Line
}
# Check if teams is started once before for current user
if ( (Test-Path -LiteralPath $TeamsStarted) ) {
logwrite "Teams started once before by the current user."
} else {
logwrite "Teams has never been started by user"
Exit 1
}
# Check if %appdata%\Microsoft\Teams\Background is present, if not create folder
if (!(Test-Path -LiteralPath $DirectoryBGToCreate -PathType container)) {
try {
New-Item -Path $DirectoryBGToCreate -ItemType Directory -ErrorAction Stop | Out-Null #-Force
} catch {
Write-Error -Message "Unable to create directory '$DirectoryBGToCreate' . Error was: $_" -ErrorAction Stop
}
logwrite "Successfully created directories '$DirectoryBGToCreate' ."
} else {
logwrite "Directory '$DirectoryBGToCreate' already exist"
}
# Check if %appdata%\Microsoft\Teams\Background\Uploads is present, if not create folder
if (!(Test-Path -LiteralPath $Uploadfolder -PathType container)){
try {
New-Item -Path $Uploadfolder -ItemType Directory -ErrorAction Stop | Out-Null #-Force
} catch {
Write-Error -Message "Unable to create directory '$Uploadfolder' . Error was: $_" -ErrorAction Stop
}
logwrite "Successfully created directories '$Uploadfolder' ."
} else {
logwrite "Directory '$Uploadfolder' already exist"
}
Copy-Item -Path L:\Source\Teams_Backgrounds\* -Destination $env:APPDATA\Microsoft\Teams\Backgrounds\Uploads -PassThru
# Stop Teams
Get-Process "Teams" -ErrorAction SilentlyContinue | Stop-Process
#
# Do what you need to here
#
# change to the correct directory
Set-Location ($ENV:USERPROFILE + '\AppData\Local\Microsoft\Teams')
# start Teams
Start-Process -File "$($env:USERProfile)\AppData\Local\Microsoft\Teams\Update.exe" -ArgumentList '--processStart "Teams.exe"'