Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. $SchedTaskName = "unpin unwanted applications"
  2. $Configtime = '11:15:00'
  3. $Logsource = "IntuneTest"
  4. $LogNAme = "Application"
  5.  
  6. $FileContent = @'
  7. $ErrorActionPReference = SilentlyContinue
  8. $SchedTaskName = "unpin unwanted applications"
  9. $Logsource = "IntuneTest"
  10. function Pin-App { param(
  11. [string]$appname,
  12. [switch]$unpin
  13. )
  14. try{
  15. if ($unpin.IsPresent){
  16. ((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()}
  17. return "App '$appname' unpinned from Start"
  18. }else{
  19. ((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()}
  20. return "App '$appname' pinned to Start"
  21. }
  22. }catch{
  23. #Write-Error "Error Pinning/Unpinning App! (App-Name correct?)"
  24. }
  25. }
  26.  
  27. Pin-App "Mail" -unpin
  28. Pin-App "Store" -unpin
  29. Pin-App "Calendar" -unpin
  30. Pin-App "Microsoft Edge" -unpin
  31. Pin-App "Photos" -unpin
  32. Pin-App "Cortana" -unpin
  33. Pin-App "Weather" -unpin
  34. Pin-App "Phone Companion" -unpin
  35. Pin-App "Music" -unpin
  36. Pin-App "xbox" -unpin
  37. Pin-App "movies & tv" -unpin
  38. Pin-App "microsoft solitaire collection" -unpin
  39. Pin-App "money" -unpin
  40. Pin-App "get office" -unpin
  41. Pin-App "onenote" -unpin
  42. Pin-App "news" -unpin
  43. Pin-App "paint 3d" -unpin
  44. Pin-App "Maps" -unpin
  45. Pin-App "Microsoft STore" -unpin
  46.  
  47. Write-EventLog -Source $Logsource -LogName $LogName -EventId 8 -EntryType information -Message 'Task scheduled unpinned everything'
  48.  
  49. $SchedTaskStartboundary = (& "$($env:windir)\system32\schtasks.exe" /Query /TN $SchedTaskName ) | Select-Object -last 1
  50. if ($SchedTaskStartboundary) {
  51. if ($SchedTaskStartboundary -notmatch $SchedTriggerAt) {
  52. & "$env:windir\system32\schtasks.exe" /Delete /TN $SchedTaskName /F
  53. Write-EventLog -Source $Logsource -LogName $LogName -EventId 8 -EntryType information -Message 'Task scheduled is unregistered.'
  54. }
  55. }
  56.  
  57.  
  58. '@
  59.  
  60. New-Item -ItemType Directory c:\temp -ErrorAction SilentlyContinue
  61. $FileContent | out-file c:\temp\Unpinning.ps1
  62.  
  63. #Create the scheduled task that will run the log rotation
  64.  
  65. $taskstring = ('powershell.exe {0}' -f "c:\temp\Unpinning.ps1")
  66. $Configtime = (get-date).AddMinutes(1)
  67. [string]$ConfigTimeFormated = Get-Date $Configtime -Format HH:mm:00
  68. & "$env:windir\system32\schtasks.exe" /create /SC Once /TN $SchedTaskName /ST $ConfigTimeFormated /tr $taskstring /F /RL HIGHEST
  69. Write-EventLog -Source $Logsource -LogName $LogName -EventId 9 -EntryType information -Message 'IIS log rotation Scheduled task is created or updated.'
  70.  
  71.  
  72. $Logsource = "IntuneTest"
  73. #Check if log source exist, else create it
  74. $log = [System.Diagnostics.EventLog]::SourceExists($Logsource)
  75. if ($log -eq $false)
  76. {
  77. New-EventLog -LogName Application -Source $Logsource
  78. }
  79. $Message = "SuperDuper unpinner ran"
  80. Write-EventLog -Source $Logsource -LogName $LogNAme -EventId 6 -EntryType information -Message $message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement