Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $SchedTaskName = "unpin unwanted applications"
- $Configtime = '11:15:00'
- $Logsource = "IntuneTest"
- $LogNAme = "Application"
- $FileContent = @'
- $ErrorActionPReference = SilentlyContinue
- $SchedTaskName = "unpin unwanted applications"
- $Logsource = "IntuneTest"
- function Pin-App { param(
- [string]$appname,
- [switch]$unpin
- )
- try{
- if ($unpin.IsPresent){
- ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'From "Start" UnPin|Unpin from Start'} | %{$_.DoIt()}
- return "App '$appname' unpinned from Start"
- }else{
- ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'To "Start" Pin|Pin to Start'} | %{$_.DoIt()}
- return "App '$appname' pinned to Start"
- }
- }catch{
- #Write-Error "Error Pinning/Unpinning App! (App-Name correct?)"
- }
- }
- Pin-App "Mail" -unpin
- Pin-App "Store" -unpin
- Pin-App "Calendar" -unpin
- Pin-App "Microsoft Edge" -unpin
- Pin-App "Photos" -unpin
- Pin-App "Cortana" -unpin
- Pin-App "Weather" -unpin
- Pin-App "Phone Companion" -unpin
- Pin-App "Music" -unpin
- Pin-App "xbox" -unpin
- Pin-App "movies & tv" -unpin
- Pin-App "microsoft solitaire collection" -unpin
- Pin-App "money" -unpin
- Pin-App "get office" -unpin
- Pin-App "onenote" -unpin
- Pin-App "news" -unpin
- Pin-App "paint 3d" -unpin
- Pin-App "Maps" -unpin
- Pin-App "Microsoft STore" -unpin
- Write-EventLog -Source $Logsource -LogName $LogName -EventId 8 -EntryType information -Message 'Task scheduled unpinned everything'
- $SchedTaskStartboundary = (& "$($env:windir)\system32\schtasks.exe" /Query /TN $SchedTaskName ) | Select-Object -last 1
- if ($SchedTaskStartboundary) {
- if ($SchedTaskStartboundary -notmatch $SchedTriggerAt) {
- & "$env:windir\system32\schtasks.exe" /Delete /TN $SchedTaskName /F
- Write-EventLog -Source $Logsource -LogName $LogName -EventId 8 -EntryType information -Message 'Task scheduled is unregistered.'
- }
- }
- '@
- New-Item -ItemType Directory c:\temp -ErrorAction SilentlyContinue
- $FileContent | out-file c:\temp\Unpinning.ps1
- #Create the scheduled task that will run the log rotation
- $taskstring = ('powershell.exe {0}' -f "c:\temp\Unpinning.ps1")
- $Configtime = (get-date).AddMinutes(1)
- [string]$ConfigTimeFormated = Get-Date $Configtime -Format HH:mm:00
- & "$env:windir\system32\schtasks.exe" /create /SC Once /TN $SchedTaskName /ST $ConfigTimeFormated /tr $taskstring /F /RL HIGHEST
- Write-EventLog -Source $Logsource -LogName $LogName -EventId 9 -EntryType information -Message 'IIS log rotation Scheduled task is created or updated.'
- $Logsource = "IntuneTest"
- #Check if log source exist, else create it
- $log = [System.Diagnostics.EventLog]::SourceExists($Logsource)
- if ($log -eq $false)
- {
- New-EventLog -LogName Application -Source $Logsource
- }
- $Message = "SuperDuper unpinner ran"
- Write-EventLog -Source $Logsource -LogName $LogNAme -EventId 6 -EntryType information -Message $message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement