-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_profile_filechange.ps1
More file actions
72 lines (60 loc) · 2.61 KB
/
user_profile_filechange.ps1
File metadata and controls
72 lines (60 loc) · 2.61 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
<#
.SYNOPSIS
Updates the `file.config` file located in the `AppData\Roaming` directory for all real user profiles on a Windows machine.
.DESCRIPTION
This script is designed to be executed as SYSTEM and iterates through all user profiles on the system, excluding default, public, and other non-real profiles.
It identifies the `file.config` file for each profile, applies predefined modifications, and logs all operations, including errors and skipped profiles.
.NOTES
Version: 1.0
- Ensure the script is executed in a 64-bit PowerShell environment for compatibility.
- Deploy via Intune as SYSTEM to ensure access to all user profiles.
#>
# Define the path to the configuration file relative to each user profile
$ConfigFile = 'AppData\Roaming\file.config'
# Logging setup
$LogFolder = 'C:\ProgramData\IntuneScripts'
$LogPath = Join-Path $LogFolder 'FileConfigUpdate.log'
if (-not (Test-Path $LogFolder)) { New-Item -ItemType Directory -Path $LogFolder -Force | Out-Null }
Start-Transcript -Path $LogPath -Append -Force
# Grab real profile paths
$excluded = @('Public', 'Default', 'DefaultUser0', 'All Users')
$profiles = Get-ChildItem 'C:\Users' -Directory |
Where-Object { $excluded -notcontains $_.Name } |
Select-Object -ExpandProperty FullName
Write-Host "Discovered profiles: $($profiles -join ', ')"
# Generate $cfg paths for all profiles
$cfgPaths = @{ }
foreach ($userProfile in $profiles) {
$cfg = Join-Path $userProfile $ConfigFile
$cfgPaths[$userProfile] = $cfg
}
Write-Host "Generated config paths: $($cfgPaths.Values -join ', ')"
# Define your file-modification logic
function Update-ConfigFile {
param([string]$ConfigPath)
try {
$content = Get-Content -Path $ConfigPath -Raw
##################################
# Modify the new content as needed
##################################
# Example: Change 'Something=false' to 'Something=true'
$newContent = $content -replace 'Something=false', 'Something=true'
if ($newContent -ne $content) {
Write-Host "Updating $ConfigPath"
$newContent | Set-Content -Path $ConfigPath -Encoding UTF8
}
else {
Write-Host "No change needed in $ConfigPath" -ForegroundColor Cyan
}
}
catch {
Write-Host "Error processing $ConfigPath : $_" -ForegroundColor Red
}
}
# Iterate through each profile's config path
foreach ($userProfile in $cfgPaths.Keys) {
$cfg = $cfgPaths[$userProfile]
if (Test-Path $cfg) { Update-ConfigFile -ConfigPath $cfg }
else { Write-Host "Skipped (missing): $cfg" -ForegroundColor Yellow }
}
Stop-Transcript