After installing Windows I always started configuring the same old basic settings:
- move Desktop, Documents, Music, Videos, Pictures folders to D:\
- configure some basic settings in Windows Explorer folder options (e.g. show hidden files, show file extensions)
- remove Internet Explorer from taskbar and add PowerShell to it
Today I set up a few virtual machines and decided to finally script the above steps with PowerShell to save some time. Here’s the final script:
-
function changeUserFolders()
-
{
-
$profileRoot = "D:\Profil\Stefan\";
-
-
$folderSettings = @{
-
"Desktop" = "Desktop";
-
"Personal" = "Dokumente";
-
"My Music" = "Musik";
-
"My Pictures" = "Bilder";
-
"My Video" = "Videos";
-
"{374DE290-123F-4565-9164-39C4925E467B}" = "D:\Download";
-
};
-
-
$regkeys = @("HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders");
-
-
foreach ($key in $folderSettings.keys)
-
{
-
$path = $folderSettings[$key];
-
if ($path -notmatch ":")
-
{
-
$path = [System.IO.Path]::Combine($profileRoot, $path);
-
}
-
if (!(test-path $path))
-
{
-
mkdir $path;
-
}
-
foreach ($regkey in $regkeys)
-
{
-
set-ItemProperty -path $regkey -name $key $path;
-
}
-
}
-
-
cd (gc env:\userprofile);
-
foreach ($dir in @("Desktop", "Documents", "Downloads", "Music", "Pictures", "Videos"))
-
{
-
del $dir -force -recurse;
-
}
-
}
-
-
function setExplorerSettings()
-
{
-
$settings = @{
-
"Hidden" = 1;
-
"SuperHidden" = 1;
-
"HideFileExt" = 0;
-
"WebView" = 0;
-
"SeparateProcess" = 1;
-
"DontPrettyPath" = 1;
-
"SharingWizardOn" = 0;
-
"AlwaysShowMenus" = 1;
-
"HideDrivesWithNoMedia" = 0;
-
"NavPaneShowAllFolders" = 1;
-
"NavPaneExpandToCurrentFolder" = 1;
-
};
-
-
foreach ($key in $settings.keys)
-
{
-
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -name $key -value $settings[$key];
-
}
-
stop-process -processname explorer
-
}
-
-
function getVerbs($dir, $file)
-
{
-
$shell = new-object -com "Shell.Application";
-
$folder = $shell.Namespace($dir);
-
$item = $folder.Parsename($file);
-
return $item.Verbs();
-
}
-
-
function executeVerb($dir, $file, $verb)
-
{
-
if ($verb)
-
{
-
$verb.DoIt();
-
}
-
}
-
-
function pinToTaskbar($dir, $file)
-
{
-
executeVerb $dir $file "An Tas&kleiste anheften";
-
}
-
-
function unpinToTaskbar($dir, $file)
-
{
-
executeVerb $dir $file "Von Tas&kleiste lösen";
-
}
-
-
function createLinks()
-
{
-
$winDir = gc env:\SystemRoot;
-
$progDir = gc "env:\ProgramFiles";
-
$prog86Dir = gc "env:\ProgramFiles(x86)";
-
-
$psDir = [System.IO.Path]::Combine($winDir, "system32\WindowsPowerShell\v1.0");
-
$ieDir = [System.IO.Path]::Combine($progDir, "Internet Explorer");
-
$ie86Dir = [System.IO.Path]::Combine($progDir, "Internet Explorer");
-
-
pinToTaskbar $psDir "powershell.exe";
-
unpinToTaskbar $ieDir "iexplore.exe";
-
unpinToTaskbar $ie86Dir "iexplore.exe";
-
}
-
-
changeUserFolders;
-
setExplorerSettings;
-
createLinks;



