Skip to content

Instantly share code, notes, and snippets.

@warfighter8
Last active June 17, 2016 01:03
Show Gist options
  • Save warfighter8/77f46a2d058378f2c87be8349689291d to your computer and use it in GitHub Desktop.
Save warfighter8/77f46a2d058378f2c87be8349689291d to your computer and use it in GitHub Desktop.
Automated Admin privilege, Setup windows 10 startmenu from xml, setup default app associations, remove all but whitelisted apps from current user, remove all but whitelisted apps for default user, and reset unsigned powershell script permissions.
param([switch]$Elevated)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
if ($elevated)
{
# tried to elevate, did not work, aborting
}
else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
'running with full privileges'
#Variables
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
#Start Script
Copy-Item $scriptpath\Startmenu.xml C:\
# Create a Shortcut with Windows PowerShell for Internet Explorer accessible by all users
$TargetFile = "C:\Program Files\Internet Explorer\iexplore.exe"
$ShortcutFile = "C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Internet Explorer.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()
#Import provided startmenu.xml
Import-StartLayout -LayoutPath C:\Startmenu.xml -MountPath $env:SystemDrive\
#Set Default app associations from xml
DISM.exe /Online /Import-DefaultAppAssociations:$scriptPath\MyDefaultAppAssociations.xml
####Uninstall Default apps
Get-AppxPackage | where-object {$_.Name -notlike "*WindowsStore*"} | where-object {$_.Name -notlike "*calculator*"} | where-object {$_.Name -notlike "*maps*"} | where-object {$_.Name -notlike "*photos*"} | Remove-AppxPackage
Get-appxprovisionedpackage -online | where-object {$_.PackageName -notlike "*WindowsStore*"} | where-object {$_.PackageName -notlike "*calculator*"} | where-object {$_.PackageName -notlike "*maps*"} | where-object {$_.PackageName -notlike "*photos*"} | Remove-AppxProvisionedPackage -online
#Restore Powershell Security
Set-ExecutionPolicy AllSigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment