Archive for the ‘ Powershell ’ Category

Backup / Restore startmenu design (Layout)

If you want to backup your startmenu layout you can export using:

1
export-startlayout –path C:\layout.xml

BUT,You can import a Start Menu layout using Group Policy Editor (gpedit). After importing the layout it will be fixed, that is you will not be able to change that layout by moving the tiles around.

or better yet copy it as below.

 

backup:

Files are saved in the location of the script.

1
2
Reg export ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount") ("backup_startmenu.reg") /y
Copy-Item ("$env:LOCALAPPDATA\Microsoft\Windows\Shell\DefaultLayouts.xml") -Destination ("backup_startmenu.xml")

 

restore:

1
2
3
Reg delete ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount") /f
Reg import ("backup_startmenu.reg")
Copy-Item ("backup_startmenu.xml") -Destination ("$env:LOCALAPPDATA\Microsoft\Windows\Shell\DefaultLayouts.xml")

 

All in one menu and options (save as anything.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
#------------------------------------------------------------------------------
# AUTHOR(s):
# Kyle Wadman
# 12/2019
# -----------------------------------------------------------------------------
CLS
$Loop = $true
While ($Loop)
{
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Start | PowerShell Script menu
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CLS
write-host
write-host +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
write-host "Startmenu backup/restore | -V1.0 Windows 10"
write-host +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
write-host
write-host -ForegroundColor yellow "Your can use the export-startlayout command to complete this task but on importing back into the system,"
write-host -ForegroundColor yellow "your startmenu will be fixed to the exported design. This method doesn't restricted changes after."
write-host
write-host 'PLEASE SELECT AN OPTION '
write-host -ForegroundColor gray '------------------------------------------------'
write-host -ForegroundColor green 'B) BACKUP'
write-host -ForegroundColor gray '------------------------------------------------'
write-host -ForegroundColor cyan 'R) RESTORE'
write-host -ForegroundColor gray '------------------------------------------------'
write-host -ForegroundColor yellow 'X) Exit'
write-host

$opt = Read-Host "Select an option "
write-host $opt
switch ($opt)
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# End of | PowerShell Script menu
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

{
b { #BACKUP SCRIPT
CLS
write-host "Exporting Reg >"; Reg export ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount") ("backup_startmenu.reg") /y
write-host "Collect XML >"; try{Copy-Item ("$env:LOCALAPPDATA\Microsoft\Windows\Shell\DefaultLayouts.xml") -Destination ("backup_startmenu.xml")} #-ErrorAction SilentyContinue
catch{write-host "Failed to find XML"; pause; break}; write-host "The operation completed successfully."
write-host -BackgroundColor yellow -ForegroundColor red " All Done "
pause
}

r { #RESTORE SCRIPT
CLS
write-host "Clean reg >"; Reg delete ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount") /f
write-host "Import reg >"; Reg import ("backup_startmenu.reg")
write-host "Place XML >"; try{Copy-Item ("backup_startmenu.xml") -Destination ("$env:LOCALAPPDATA\Microsoft\Windows\Shell\DefaultLayouts.xml")}
catch{write-host "Failed to Place XML"; pause; break}; write-host "The operation completed successfully."

write-host -BackgroundColor yellow -ForegroundColor red " You now need to logout and back in to see the results. "
pause
}

x{#BYE
CLS
write-host "Goodbye, It was nice to see you today."
exit
}

}
}

 

I did find someone has built this process into an application here.  For coded requirements, you can thank me later.

Maybe for personal backups, check out the software version.

Print Friendly, PDF & Email

Powershell Check Registry

The below code looks for a registry ‘String Name’ in a ‘current user’ registry path (Key).

  • HKCU (Current User)
  • HKLM (Local Machine)

If the StringName doesn’t exist, it runs the code in the ‘processing block’. It then writes the exact registry item it looked up in the first place.

IF/When the script is run again it will this time PASS the test and the code block “NO ACTION” will be executed.

 

This function can be added once to the top of your script, then called for multi use later.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Function CheckRegFlag($Func_State,$Func_key,$Func_StringName,$Func_StringValue){
switch($Func_State)
{
start {
$TestPath = (Get-ItemProperty $Func_key) -ne $null
IF ($TestPath -eq "") {
New-Item -Path $Func_key -force | Out-Null
}

$TestValue = (Get-ItemProperty $Func_key).$Func_StringName -ne $null
IF ($TestValue -eq "")
{$Func_WorkNeeded = "Y"; write-host "action needed"}
ELSE
{$Func_WorkNeeded = "N"; write-host "already run"}
}

stop { New-ItemProperty -Path $Func_key -Name $Func_StringName -Value $Func_StringValue |Out-Null; write-host "Saving Flag"}
Default { write-host "No State given"; pause; break}
}
return $Func_WorkNeeded
}

This next bit can be used time and time again to test and complete actions (adding your code to the DO All Commands here)

1
2
3
4
5
6
7
8
9
10
#REG values to check/write
$var_key = ("HKCU:\SOFTWARE\TestKey") #LOCATION OF STRING-NAME IN REG
$var_StringName = ("TestName") #THIS IS WHAT IS CHECKED FOR, NOT THE VALUE.
$var_StringValue = ("TestValue") #THIS IS FOR NOTES

$ActionMe = CheckRegFlag "start" "$var_key" "$var_StringName"
switch($ActionMe){
Y{ write-host "Do all commands here"
CheckRegFlag "stop" "$var_key" "$var_StringName" "$var_StringValue"}
}
Print Friendly, PDF & Email

WMindows 10 Profile backup

It’s been a while and this is shortly explained but the following script is designed to backup a users profile in windows 10 (1903) but should work on all Windows 10.

Line 149: $var_backupRoot needs to be updated to a backup ROOT location.

Download File

 

 

 

 

 

 

 

 

Print Friendly, PDF & Email