Lately, I was attempting to automate the creation of my Windows 7 Golden Image by building it from scratch in task sequences with System Center Configuration Manager (SCCM/ConfigMgr). No way I’m gonna use some old scripting language like batch or vbs and I coudln’t find any PowerShell script around so I just made one! Moreover, Windows 7 comes with PowerShell (2.0) by default so there is absolutely no reason to overlook the benefits of such a powerful scripting tool! ;)

This script is based on VMware/EMC documents, some useful resources found on Internet and my personal experience. It was made for non-persistent floating pools with Persona Management enabled!

Please review this script THOROUGHLY before use as it will drastically modify Windows. Change it to fit your environment if needed! 

Disclaimer: This script is provided “AS IS” with no warranties, confers no rights, and is not supported by VMware.

 PowerShell |  copy code |? 
001
<# 
002
 .DISCLAIMER
003
  This script is provided "AS IS" with no warranties, confers no rights, and is not supported by VMware.
004
  
005
 .SYNOPSIS 
006
 Windows 7 (Enterprise) VDI Golden Image Optimizations Script
007
 
008
    .DESCRIPTION 
009
 Made for Windows 7 (Enteprise) and VMware View non-persistent floating pools with View Persona Management enabled
010
 
011
    .NOTES 
012
        NAME:  WIN7 VDI OPT.ps1 
013
        AUTHOR: Olivier AH-SON
014
        LASTEDIT: 10/09/2013 
015
        KEYWORDS: vdi, golden image, windows 7, optimization, powershell
016
 
017
#> 
018
 
019
 
020
### Function to set a registry property value
021
### Create the registry key if it doesn't exist
022
Function Set-RegistryKey
023
{
024
 [CmdletBinding()]
025
 Param(
026
 [Parameter(Mandatory=$True,HelpMessage="Please Enter Registry Item Path",Position=1)]
027
 $Path,
028
 [Parameter(Mandatory=$True,HelpMessage="Please Enter Registry Item Name",Position=2)]
029
 $Name,
030
 [Parameter(Mandatory=$True,HelpMessage="Please Enter Registry Property Item Value",Position=3)]
031
 $Value,
032
 [Parameter(Mandatory=$False,HelpMessage="Please Enter Registry Property Type",Position=4)]
033
 $PropertyType = "DWORD"
034
 )
035
 
036
 # If path does not exist, create it
037
 If( (Test-Path $Path) -eq $False ) {
038
 
039
 $newItem = New-Item -Path $Path -Force
040
 
041
 } 
042
 
043
 # Update registry value, create it if does not exist (DWORD is default)
044
 $itemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
045
 If($itemProperty -ne $null) {
046
 $itemProperty = Set-ItemProperty -Path $Path -Name $Name -Value $Value
047
 } Else {
048
 
049
 $itemProperty = New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $PropertyType
050
 }
051
 
052
}
053
 
054
### Get script path
055
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
056
 
057
### Set location to the root of the system drive
058
Set-Location -Path $env:SystemDrive
059
 
060
### Disable firewall on all profiles (domain, etc.) (Never disable the service!)
061
netsh advfirewall set allprofiles state off | Out-Host
062
 
063
### Disable Error Reporting
064
Set-RegistryKey -Path "HKLM:\SOFTWARE\Microsoft\PCHealth\ErrorReporting" -Name "DoReport" -Value 0
065
 
066
### Disable automatic updates
067
Set-RegistryKey -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" -Name "AUOptions" -Value 1
068
Set-RegistryKey -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" -Name "AUState" -Value 7
069
 
070
###  Remove Windows components
071
$featuresToDisable = @(
072
 "MediaPlayback",
073
 # If "WindowsMediaPlayer" removed, be aware WMV embedded videos on websites won't work (typically videos on Microsoft website)
074
 # Removed because another player is used as the standard
075
 "WindowsMediaPlayer", 
076
 "MediaCenter", 
077
 "OpticalMediaDisc", 
078
 "TabletPCOC", 
079
 "Printing-Foundation-InternetPrinting-Client", 
080
 "Printing-Foundation-Features", 
081
 "FaxServicesClientPackage",
082
 # If you want to keep the Start Menu search bar,
083
 # don't remove the "SearchEngine-Client-Package" component 
084
 "SearchEngine-Client-Package", 
085
 "WindowsGadgetPlatform"
086
)
087
 
088
foreach($feature in $featuresToDisable)
089
{
090
 dism /online /Disable-Feature /Quiet /NoRestart /FeatureName:$feature  | Out-Host
091
}
092
 
093
### Disable NTFS last access timestamp
094
fsutil behavior set disablelastaccess 1  | Out-Host
095
 
096
### Disable TCP/IP / Large Send Offload
097
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -Name "DisableTaskOffload" -Value 1
098
 
099
### Disable hard disk timeouts 
100
POWERCFG /SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 0012ee47-9041-4b5d-9b77-535fba8b1442 6738e2c4-e8a5-4a42-b16a-e040e769756e 0  | Out-Host
101
POWERCFG /SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 0012ee47-9041-4b5d-9b77-535fba8b1442 6738e2c4-e8a5-4a42-b16a-e040e769756e 0  | Out-Host
102
 
103
### Disable hibernation
104
powercfg /hibernate off | Out-Host
105
 
106
### Disable monitor time out (never)
107
powercfg -change -monitor-timeout-ac 0
108
 
109
###Disable system restore
110
# System Restore will be disabled on the system drive (usually C:)
111
Disable-ComputerRestore -Drive $env:SystemDrive 
112
Set-RegistryKey -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name "DisableSR" -Value 1
113
 
114
### Disable memory dumps (system crashes, BSOD)
115
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl" -Name "CrashDumpEnabled" -Value 0
116
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl" -Name "LogEvent" -Value 0
117
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl" -Name "SendAlert" -Value 0
118
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl" -Name "AutoReboot" -Value 1
119
 
120
### Disable default system screensaver
121
Set-RegistryKey -Path "Registry::\HKEY_USERS\.DEFAULT\Control Panel\Desktop" -Name "ScreenSaveActive" -Value 0
122
 
123
### Increase service startup timeouts
124
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Control" -Name "ServicesPipeTimeout" -Value 180000
125
 
126
### Increase Disk I/O Timeout to 200 seconds
127
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Disk" -Name "TimeOutValue" -Value 200
128
 
129
### Disable paging the executive
130
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" -Name "DisablePagingExecutive" -Value 1
131
 
132
### Size virtual machine RAM
133
# Disable the automatic management of the paging filing size
134
$ComputerSystem = gwmi Win32_ComputerSystem -EnableAllPrivileges
135
$ComputerSystem.AutomaticManagedPagefile = $False
136
$AutomaticManagedPagefile = $ComputerSystem.Put()
137
 
138
# Modify the existing page file of the C drive to set a fixed size of 2048MB
139
# Keeping the pagefile at a single size prevents the system from expanding, which creates a significant amount of IO
140
$CurrentPageFile = gwmi -query "Select * FROM Win32_PageFileSetting WHERE Name='C:\\pagefile.sys'"
141
$CurrentPageFile.InitialSize = [int]2048
142
$CurrentPageFile.MaximumSize = [int]2048
143
$pageFile = $CurrentPageFile.Put()
144
 
145
### Disable Machine Account Password Changes
146
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters" -Name "DisablePasswordChange" -Value 1
147
 
148
### Configure Event Logs to 1028KB (Minimum size under Vista/7) and overflowaction to "overwrite" 
149
$logs = Get-EventLog -LogName * | foreach{$_.Log.ToString()}
150
$limitParam = @{
151
  logname = ""
152
  Maximumsize = 1024KB
153
  OverflowAction = "OverwriteAsNeeded"
154
}
155
 
156
foreach($log in $logs) {
157
 
158
    $limitParam.logname = $log 
159
    Limit-EventLog @limitParam | Where {$_.Log -eq $limitparam.logname}
160
    Clear-EventLog -LogName $log
161
 
162
}
163
 
164
### Set PopUp Error Mode to "Neither" 
165
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Windows" -Name "ErrorMode" -Value 2
166
 
167
### Disable UAC secure desktop prompt
168
Set-RegistryKey -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "PromptOnSecureDesktop" -Value 0
169
 
170
### Disable New Network dialog
171
$newNetworkDialog = New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Network\NewNetworkWindowOff" -Force
172
 
173
### Disable AutoUpdate of drivers from WU
174
Set-RegistryKey -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DriverSearching" -Name "searchorderConfig" -Value 0
175
 
176
### Turn off Windows SideShow
177
Set-RegistryKey -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Sideshow" -Name "Disabled" -Value 1
178
 
179
### Disable IE First Run Wizard and RSS Feeds
180
Set-RegistryKey -Path "HKLM:\SOFTWARE\Policies\Microsoft\Internet Explorer\Main" -Name "DisableFirstRunCustomize" -Value 1
181
 
182
### Disable the ability to clear the paging file during shutdown 
183
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SessionManager\Memory Management" -Name "ClearPageFileAtShutdown" -Value 0
184
 
185
###############################################
186
# Disable unnecessary services
187
###############################################
188
$servicesToDisable = @(
189
 "SensrSvc", # Adaptive Brightness
190
 "ALG", # Application Layer Gateway Service
191
 "BITS", # Background Intelligent Transfer Service
192
 "BDESVC", # BitLocker Drive Encryption Service
193
 "wbengine", # Block Level Backup Engine Service
194
 "bthserv", # Bluetooth Support Service
195
 "PeerDistSvc", # BranchCache
196
 "Browser", # Computer Browser
197
 "UxSms", # Desktop Window Manager Session Manager - Disable only if Aero not necessary
198
 "DPS", # Diagnostic Policy Service
199
 "WdiServiceHost", # Diagnostic Service Host
200
 "WdiSystemHost", # Diagnostic System Host
201
 "defragsvc", # Disk Defragmenter
202
 "TrkWks", # Distributed Link Tracking Client
203
 "EFS", # Encrypting File System (EFS)
204
 "Fax", # Fax - Not present in Windows 7 Enterprise
205
 "fdPHost", # Function Discovery Provider Host
206
 "FDResPub", # Function Discovery Resource Publication
207
 #"HomeGroupListener", # HomeGroup Listener - Not present in Windows 7 Enterprise
208
 "HomeGroupProvider", # HomeGroup Provider
209
 "UI0Detect", # Interactive Services Detection
210
 "iphlpsvc", # IP Helper
211
 "Mcx2Svc", # Media Center Extender Service
212
 "MSiSCSI", # Microsoft iSCSI Initiator Service
213
 "netprofm", # Network List Service
214
 "NlaSvc", # Network Location Awareness
215
 "CscService", # Offline Files
216
 "WPCSvc", # Parental Controls
217
 "wercplsupport", # Problem Reports and Solutions Control Panel Support
218
 "SstpSvc", # Secure Socket Tunneling Protocol Service
219
 "wscsvc", # Security Center
220
 "ShellHWDetection", # Shell Hardware Detection
221
 "SNMPTRAP", # SNMP Trap
222
 "SSDPSRV", # SSDP Discovery
223
 "SysMain", # Superfetch
224
 "TabletInputService", # Tablet PC Input Service
225
 "TapiSrv", # Telephony
226
 "Themes", # Themes - Disable only if you want to run in Classic interface
227
 "upnphost", # UPnP Device Host
228
 "SDRSVC", # Windows Backup
229
 "WcsPlugInService", # Windows Color System
230
 "wcncsvc", # Windows Connect Now - Config Registrar
231
 "WinDefend", # Windows Defender
232
 "WerSvc", # Windows Error Reporting Service
233
 "ehRecvr", # Windows Media Center Receiver Service
234
 "ehSched", # Windows Media Center Scheduler Service
235
 "WMPNetworkSvc", # Windows Media Player Network Sharing Service
236
 "WSearch", # Windows Search
237
 "wuauserv", # Windows Update
238
 "Wlansvc", # WLAN AutoConfig
239
 "WwanSvc" # WWAN AutoConfig
240
)
241
 
242
foreach($service in $servicesToDisable)
243
{
244
    Stop-Service -Name $service -Force # 'Force' parameter stops dependent services 
245
    Set-Service -Name $service -StartupType Disabled
246
}
247
###############################################
248
 
249
# Disable SuperFetch
250
# Service stopped and disabled
251
Set-RegistryKey -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters" -Name "EnableSuperfetch" -Value 0
252
 
253
### Disable schedule tasks
254
$tasksToDisable = @(
255
 "microsoft\windows\Application Experience\AitAgent",
256
 "microsoft\windows\Application Experience\ProgramDataUpdater",
257
 "microsoft\windows\Autochk\Proxy",
258
 "microsoft\windows\Bluetooth\UninstallDeviceTask", 
259
 "microsoft\windows\Customer Experience Improvement Program\Consolidator", 
260
 "microsoft\windows\Customer Experience Improvement Program\KernelCeipTask",
261
 "microsoft\windows\Customer Experience Improvement Program\UsbCeip",
262
 "microsoft\windows\Defrag\ScheduledDefrag",
263
 "microsoft\windows\Diagnosis\Scheduled",
264
 "microsoft\windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticDataCollector",
265
 "microsoft\windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticResolver", 
266
 "microsoft\windows\Maintenance\WinSAT", 
267
 "microsoft\windows\MobilePC\HotStart", 
268
 "microsoft\windows\RAC\RacTask",
269
 "microsoft\windows\Ras\MobilityManager",
270
 "microsoft\windows\Registry\RegIdleBackup",
271
 "microsoft\windows\SideShow\AutoWake", 
272
 "microsoft\windows\SideShow\GadgetManager",
273
 "microsoft\windows\SideShow\SessionAgent",
274
 "microsoft\windows\SideShow\SystemDataProviders",
275
 "microsoft\windows\SystemRestore\SR",
276
 "microsoft\windows\UPnP\UPnPHostConfig",
277
 "microsoft\windows\WDI\ResolutionHost",
278
 "microsoft\windows\Windows Filtering Platform\BfeOnServiceStartTypeChange", 
279
 "microsoft\windows\Windows Media Sharing\UpdateLibrary", 
280
 "microsoft\windows\WindowsBackup\ConfigNotification"
281
)
282
 
283
foreach ($task in $tasksToDisable) 
284
{
285
 schtasks /change /tn $task /Disable | Out-Host
286
}
287
 
288
### Disable unnecessary boot features (for the current operating system)[A]
289
# Disable the boot debugging 
290
bcdedit /bootdebug off
291
bcdedit /debug off
292
# Disable the bootlog
293
bcdedit /set bootlog no
294
# Disable the boot screen animation
295
# Note: bootux - Not supported in Windows 8 and Windows Server 2012.
296
bcdedit /set bootux disabled
297
# Note: Do not use the quietboot option in Windows 8 as it will prevent the display of bug check data in addition to all boot graphics.
298
bcdedit /set quietboot on
299
 
300
 
301
### Perform a disk cleanup 
302
# Automate by creating the reg checks corresponding to "cleanmgr /sageset:100" so we can use "sagerun:100" 
303
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders" -Name "StateFlags0100" -Value 2
304
Set-RegistryKey -Path "HKLM:\software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files" -Name "StateFlags0100" -Value 2
305
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files" -Name "StateFlags0100" -Value 2
306
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Memory Dump Files" -Name "StateFlags0100" -Value 2
307
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Offline Pages Files" -Name "StateFlags0100" -Value 2
308
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old ChkDsk Files" -Name "StateFlags0100" -Value 2
309
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations" -Name "StateFlags0100" -Value 0
310
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin" -Name "StateFlags0100" -Value 2
311
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup Log Files" -Name "StateFlags0100" -Value 2
312
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System error memory dump files" -Name "StateFlags0100" -Value 2
313
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System error minidump files" -Name "StateFlags0100" -Value 2
314
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files" -Name "StateFlags0100" -Value 2
315
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Setup Files" -Name "StateFlags0100" -Value 2
316
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Thumbnail Cache" -Name "StateFlags0100" -Value 2
317
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Upgrade Discarded Files" -Name "StateFlags0100" -Value 0
318
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Archive Files" -Name "StateFlags0100" -Value 2
319
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Queue Files" -Name "StateFlags0100" -Value 2
320
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Archive Files" -Name "StateFlags0100" -Value 2
321
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Queue Files" -Name "StateFlags0100" -Value 2
322
Set-RegistryKey -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Upgrade Log Files" -Name "StateFlags0100" -Value 2
323
 
324
cleanmgr.exe /sagerun:100  | Out-Host
325
 
326
# Customization of the default user 
327
$defaultUserHivePath = $env:SystemDrive + "\Users\Default\NTUSER.DAT"
328
$userLoadPath = "HKU\TempUser" 
329
 
330
# Load Hive
331
reg load $userLoadPath $defaultUserHivePath | Out-Host
332
# Create PSDrive
333
$psDrive = New-PSDrive -Name HKUDefaultUser -PSProvider Registry -Root $userLoadPath
334
# Reduce menu show delay 
335
Set-RegistryKey -Path "HKUDefaultUser:\Control Panel\Desktop" -Name "MenuShowDelay" -Value 0
336
# Disable cursor blink 
337
Set-RegistryKey -Path "HKUDefaultUser:\Control Panel\Desktop" -Name "CursorBlinkRate" -Value -1
338
Set-RegistryKey -Path "HKUDefaultUser:\Control Panel\Desktop" -Name "DisableCursorBlink" -Value 1
339
# Force off-screen composition in IE 
340
Set-RegistryKey -Path "HKUDefaultUser:\Software\Microsoft\Internet Explorer\Main" -Name "Force Offscreen Composition" -Value 1
341
# Disable screensavers
342
Set-RegistryKey -Path "HKUDefaultUser:\Software\Policies\Microsoft\Windows\Control Panel\Desktop" -Name "ScreenSaveActive" -Value 0
343
Set-RegistryKey -Path "HKUDefaultUser:\Control Panel\Desktop\" -Name "ScreenSaveActive" -Value 0
344
Set-RegistryKey -Path "Registry::\HKEY_USERS\.DEFAULT\Control Panel\Desktop" -Name "ScreenSaveActive" -Value 0
345
# Don't show window contents when dragging 
346
Set-RegistryKey -Path "HKUDefaultUser:\Control Panel\Desktop" -Name "DragFullWindows" -Value 0
347
# Don't show window minimize/maximize animations
348
Set-RegistryKey -Path "HKUDefaultUser:\Control Panel\Desktop\WindowMetrics" -Name "MinAnimate" -Value 0
349
# Disable font smoothing 
350
Set-RegistryKey -Path "HKUDefaultUser:\Control Panel\Desktop" -Name "FontSmoothing" -Value 0
351
 
352
# Disable most other visual effects 
353
Set-RegistryKey -Path "HKUDefaultUser:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects" -Name "VisualFXSetting" -Value 3
354
Set-RegistryKey -Path "HKUDefaultUser:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ListviewAlphaSelect" -Value 0
355
Set-RegistryKey -Path "HKUDefaultUser:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "TaskbarAnimations" -Value 0
356
Set-RegistryKey -Path "HKUDefaultUser:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ListviewWatermark" -Value 0
357
Set-RegistryKey -Path "HKUDefaultUser:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ListviewShadow" -Value 0
358
Set-RegistryKey -Path "HKUDefaultUser:\Control Panel\Desktop" -Name "UserPreferencesMask" -Value ([byte[]](0x90,0x12,0x01,0x80)) -PropertyType "Binary"
359
 
360
# Disable Action Center Icon
361
Set-RegistryKey -Path "HKUDefaultUser:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "HideSCAHealth" -Value 1
362
 
363
# Disable Network Icon
364
Set-RegistryKey -Path "HKUDefaultUser:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name "HideSCANetwork" -Value 1
365
 
366
# Disable IE Persistent Cache 
367
Set-RegistryKey -Path "HKUDefaultUser:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Cache" -Name "Persistent" -Value 0
368
Set-RegistryKey -Path "HKUDefaultUser:\Software\Microsoft\Feeds" -Name "SyncStatus" -Value 0
369
 
370
# Remove PSDrive
371
$psDrive = Remove-PSDrive HKUDefaultUser
372
# Clean up references not in use
373
$variables = Get-Variable | Where { $_.Name -ne "userLoadPath" } | foreach { $_.Name }
374
foreach($var in $variables) { Remove-Variable $var -ErrorAction SilentlyContinue }
375
[gc]::collect()
376
# Unload Hive
377
reg unload $userLoadPath | Out-Host
378
 
379
# Hide the VMWare tray icon for all users
380
Set-RegistryKey -Path "HKLM:\SOFTWARE\VMware, Inc.\VMware Tools" -Name "ShowTray" -Value 0
381
 
382
Exit 0
383
 
384

If you want to use it in a Task Sequence like me, create a package without program and run a command line:

powershell -ExecutionPolicy Unrestricted -File “WIN7 VDI OPT.ps1″

This can be also used with Microsoft Deployment Toolkit (MDT).

A few notes:

References: