Windows 10 powershell pin to taskbar

I am trying to pin a program to the taskbar in Windows 10 (RTM) using this code: $shell = new-object -com "Shell.Application" $folder = $shell.Namespace((Join-Path $env:SystemRoot System32

Refer to @Humberto Freitas answer that i tweaked for my aim, you can try this vbscript in order to pin a program to taskbar using Vbscript in Windows 10.

Vbscript : TaskBarPin.vbs

Option Explicit
REM Question Asked here ==> 
REM https://stackoverflow.com/questions/31720595/pin-program-to-taskbar-using-ps-in-windows-10/34182076#34182076
Dim Title,objFSO,ws,objFile,sKey1,sKey2,KeyValue
Title = "Pin a program to taskbar using Vbscript in Windows 10"
'----------------------------------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Ws     = CreateObject("WScript.Shell")
objFile    = DeQuote(InputBox("Type the whole path of the program to be pinned or unpinned !",Title,_
"%ProgramFiles%windows ntaccessorieswordpad.exe"))
REM Examples
REM "%ProgramFiles%Mozilla Firefoxfirefox.exe"
REM "%ProgramFiles%GoogleChromeApplicationchrome.exe"
REM "%ProgramFiles%windows ntaccessorieswordpad.exe"
REM "%Windir%Notepad.exe"
ObjFile = ws.ExpandEnvironmentStrings(ObjFile)
If ObjFile = "" Then Wscript.Quit()
sKey1      = "HKCUSoftwareClasses*shell{:}\"
sKey2      = Replace(sKey1, "\", "ExplorerCommandHandler")
'----------------------------------------------------------------------
With CreateObject("WScript.Shell")
    KeyValue = .RegRead("HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorer" & _
    "CommandStoreshellWindows.taskbarpinExplorerCommandHandler")
    .RegWrite sKey2, KeyValue, "REG_SZ"
    
    With CreateObject("Shell.Application")
        With .Namespace(objFSO.GetParentFolderName(objFile))
            With .ParseName(objFSO.GetFileName(objFile))
                .InvokeVerb("{:}")
            End With
            
        End With
    End With
    .Run("Reg.exe delete """ & Replace(sKey1, "\", "") & """ /F"), 0, True
End With
'----------------------------------------------------------------------
Function DeQuote(S)
    If Left(S,1) = """" And Right(S, 1) = """" Then 
        DeQuote = Trim(Mid(S, 2, Len(S) - 2))
    Else 
        DeQuote = Trim(S)
    End If
End Function
'----------------------------------------------------------------------

EDIT : on 24/12/2020

Refer to :
Where is Microsoft Edge located in Windows 10? How do I launch it?

Microsoft Edge should be in the taskbar. It is the blue ‘e’ icon.

Taskbar

If you do not have that or have unpinned it, you just need to repin it. Unfortunately the MicrosoftEdge.exe can not be run by double clicking and creating a normal shortcut will not work. You may have found it at this location.

Location

What you need to do is just search for Edge in the Start menu or search bar. Once you see Microsoft Edge, right click on it and Pin to taskbar.

Search


You can run the Microsoft Edge with this vbscript : Run-Micro-Edge.vbs

CreateObject("wscript.shell").Run "%windir%explorer.exe shell:AppsfolderMicrosoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge"

Microsoft doesn’t officially support programmatically changing the Taskbar pins. However, with the PowerShell module PinnedApplications from Jan Egil Ring, you can easily pin and unpin apps to the Taskbar on Windows 7 and Windows 8.x computers.

  • Author
  • Recent Posts

Michael Pietroforte is the founder and editor in chief of 4sysops. He has more than 35 years of experience in IT management and system administration.

First, copy and paste the PowerShell module to an editor on your computer. I suggest you save the file to one of your PowerShell module folders. With $env:PSModulePath, you can get a list of your module paths.

PS C:> $env:PSModulePath
C:UsersadministratorDocumentsWindowsPowerShellModules;C:Program FilesWindowsPowerShellModules;C:Windowssystem32WindowsPowerShellv1.0Modules

In this example, we use C:UsersAdministratorDocumentsWindowsPowerShellModules. You have to create a folder with the name PinnedApplications in the module folder and then save the file as PinnedApplications.psm1 to this folder. This would be the file path:

C:UsersAdministratorDocumentsWindowsPowerShellModulesPinnedApplicationsPinnedApplications.psm1

Make sure your execution policy is set to unrestricted (Set-ExecutionPolicy Unrestricted). Next, you can import the module with the Import-Module cmdlet.

PS C:> Import-Module PinnedApplications
PS C:>

If no error message appears, you are fine. Use the Get-Command cmdlet to check what commands the module contains.

PS C:> Get-Command -Module PinnedApplications
CommandType     Name                                               ModuleName 
-----------     ----                                               ----------
Function        Set-PinnedApplication                              PinnedApplications

From now on, you can use Set-PinnedApplication to pin and unpin apps to the Windows Taskbar.

With Get-Help Set-PinnedApplication, you get an overview of the cmdlet.

Get-Help Set-PinnedApplication

Get-Help Set-PinnedApplication

The synopsis indicates that the cmdlet was made for Windows 7 and Windows 2008 R2. I tried the module with Windows 8.1, and it appears to work fine for pinning and unpinning apps to the Taskbar. However, in my tests, the actions PinToStartMenu and UnPinFromStartMenu didn’t work on Windows 8.1 but worked well on a Windows 7 machine.

The example below demonstrates how you can pin Notepad to the Taskbar:

PS C:> Set-PinnedApplication -Action PinToTaskbar -FilePath C:Windowssystem32notepad.exe
PS C:>

Notepad pinned to Taskbar

Notepad pinned to Taskbar

Wouldn’t it be wonderful if you could unpin the Store app from the Taskbar with PowerShell? It is not easy as one might think. In my next post, I show you how you can use the Set-PinnedApplication function of Jan Egil Ring’s module in a logon script so you can unpin the Store app on all computers in your network.

  • Remove From My Forums
  • Question

  • Function Set-PinToStartMenu($Path){
    #Pins an Icon to the Taskbar
    
    $Shell = New-Object -ComObject Shell.Application 
    $Desktop = $Shell.NameSpace(0X0) 
    $WshShell = New-Object -comObject WScript.Shell
    
    if(!(Test-Path -Path $path))
    { return 0 }
    
    Foreach($itemPath in $Path)
    {
        $itemName = Split-Path -Path $itemPath -Leaf
        # pin application to Windows Taskbar
        $ItemLnk = $Desktop.ParseName($itemPath)
        $ItemVerbs = $ItemLnk.Verbs()
        Foreach($ItemVerb in $ItemVerbs)
        {
            If($ItemVerb.Name.Replace("&","") -match "Pin to Start")
            {
                $ItemVerb.DoIt()
            }
        }
    }
    }
    Function Set-PinToTaskbar($Path){
    #Pins an Icon to the Taskbar
    
    $Shell = New-Object -ComObject Shell.Application 
    $Desktop = $Shell.NameSpace(0X0) 
    $WshShell = New-Object -comObject WScript.Shell
    if(!(Test-Path -Path $path))
    { return 0 }
    Foreach($itemPath in $Path)
    {
        $itemName = Split-Path -Path $itemPath -Leaf
        # pin application to Windows Taskbar
        $ItemLnk = $Desktop.ParseName($itemPath)
        $ItemVerbs = $ItemLnk.Verbs()
        Foreach($ItemVerb in $ItemVerbs)
        {
            If($ItemVerb.Name.Replace("&","") -match "Pin to Taskbar")
            {
                $ItemVerb.DoIt()
            }
        }
    }
    }
    
    Function Set-UnpinFromStartMenu($Path){
    #Unpins an Icon to the Start Menu
    
    if(!(Test-Path -Path $path))
    { return 0 }
    
    $Shell = New-Object -ComObject Shell.Application 
    $Desktop = $Shell.NameSpace(0X0) 
    $WshShell = New-Object -comObject WScript.Shell
    
    Foreach($itemPath in $Path)
    {
        $itemName = Split-Path -Path $itemPath -Leaf
        # pin application to Windows Start Menu
        $ItemLnk = $Desktop.ParseName($itemPath)
        $ItemVerbs = $ItemLnk.Verbs()
        Foreach($ItemVerb in $ItemVerbs)
        {
            If($ItemVerb.Name.Replace("&","") -match "Unpin from Start")
            {
                $ItemVerb.DoIt()
            }
        }
    }
    }
    
    
    Function Set-UnpinFromTaskbar($Path){
    #Unpins an Icon to the Taskbar
    
    $Shell = New-Object -ComObject Shell.Application 
    $Desktop = $Shell.NameSpace(0X0) 
    $WshShell = New-Object -comObject WScript.Shell
    
    if(!(Test-Path -Path $path))
    { return 0 }
    
    Foreach($itemPath in $Path)
    {
        $itemName = Split-Path -Path $itemPath -Leaf
        # pin application to Windows Taskbar
        $ItemLnk = $Desktop.ParseName($itemPath)
        $ItemVerbs = $ItemLnk.Verbs()
        Foreach($ItemVerb in $ItemVerbs)
        {
            If($ItemVerb.Name.Replace("&","") -match "Unpin from Taskbar")
            {
                $ItemVerb.DoIt()
            }
        }
    }
    }

    I have no issue pinning to startmenu and unpinning from startmenu (except cortana/store/edge).

    I want to unpin cortana. 

    I also want to pin outlook to the taskbar.

    the problem is that the verb for pin to taskbar is missing, 

    so none of them work

    Set-PinToTaskbar «C:UsersAll UsersMicrosoftWindowsStart MenuProgramsMicrosoft OfficeMicrosoft Outlook 2010.lnk» 
    Set-PinToTaskbar «C:Program Files (x86)Microsoft Office 15rootoffice15outlook.exe»
    Set-PinToTaskbar «C:Program Files (x86)Microsoft OfficeOffice14outlook.exe»
    Set-PinToTaskbar «C:Program FilesMicrosoft Office 15rootoffice15outlook.exe»
    Set-PinToTaskbar «C:Program FilesMicrosoft OfficeOffice14outlook.exe»

Answers

  • chrisloup

    I am not sure about your unpin Cortana, did you mean to disable Cortana?

    If so, you can use powershell script to change following keys to disable Cortana:

    HKLMSOFTWAREPoliciesMicrosoftWindowsWindows Search
    Value: AllowCortana

    Change to 0 to Disable Cortana, 1 to Enable.

    Update or Add Registry Key Value with PowerShell
    http://blogs.technet.com/b/heyscriptingguy/archive/2015/04/02/update-or-add-registry-key-value-with-powershell.aspx

    For further, I have no idea since I am not the expert on Script.

    It is recommended to post in script center for more help:
    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.  Thank you for your understanding.


    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Edited by

      Monday, August 31, 2015 6:20 AM

    • Proposed as answer by
      Kate LiMicrosoft employee
      Monday, September 7, 2015 8:29 AM
    • Marked as answer by
      MeipoXuMicrosoft contingent staff
      Tuesday, September 8, 2015 8:59 AM

I have seen many similar questions posted on stackoverflow.com, but this is different, and before you are wondering, why don’t I post the question on stackoverflow.com? Because I am currently banned from asking questions there, and I currently don’t have enough time to edit all those questions.

A brief description of what I want to do: I want to pin elevated cmd, powershell, pwsh, python etc. to taskbar programmatically, and of course I know how to create shortcuts using explorer.exe and pin them, but I consider the GUI method to be tiresome and tedious, having to click many times to get a simple job done, and I want to pin many programs…

I have found this:

How to create a Run As Administrator shortcut using Powershell

An example:

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$HomeDesktopPowerShell.lnk")
$Shortcut.TargetPath = "C:WindowsSystem32WindowsPowerShellv1.0PowerShell.exe"
$Shortcut.Save()
$bytes = [System.IO.File]::ReadAllBytes("$HomeDesktopPowerShell.lnk")
$bytes[0x15] = $bytes[0x15] -bor 0x20
[System.IO.File]::WriteAllBytes("$HomeDesktopPowerShell.lnk", $bytes)

The example will create a shortcut to default PowerShell named «PowerShell» on desktop with admin rights.

Now, to wrap it in a function:

function admin-shortcut {
  PARAM (
    [Parameter(ValueFromPipeline=$true, Mandatory=$true, Position=0)] [system.string] $path,
    [Parameter(ValueFromPipeline=$true, Mandatory=$true, Position=1)] [system.string] $name
    )
    $WshShell = New-Object -comObject WScript.Shell
    $Shortcut = $WshShell.CreateShortcut("$HomeDesktop$name.lnk")
    $Shortcut.TargetPath = $path
    $Shortcut.Save()
    $bytes = [System.IO.File]::ReadAllBytes("$HomeDesktop$name.lnk")
    $bytes[0x15] = $bytes[0x15] -bor 0x20
    [System.IO.File]::WriteAllBytes("$HomeDesktop$name.lnk", $bytes)
}

I have seen many posts on stackoverflow.com about methods to pin programs directly to taskbar, but none of them solves my problem as I want to give the pinned shortcuts Administrator privileges, none of the methods I have seen does it.

So I Googled how to create an admin shortcut using PowerShell, and found the method mentioned above, now I only need to figure out how to pin the .lnk files to taskbar, unfortunately all Google search results of «how to pin shortcuts to taskbar» talks about pinning the program directly, none of them involves .lnk files, and I already explained why they won’t work in this case.

So do you have any ideas? Any help will be appreciated.


Outdated methods that no longer work on Windows 10:

Method #1

$shell = new-object -com "Shell.Application"  
$folder = $shell.Namespace((Join-Path $env:SystemRoot System32WindowsPowerShellv1.0))
$item = $folder.Parsename('powershell_ise.exe')
$item.invokeverb('taskbarpin');

Method #2

$shell = new-object -com "Shell.Application"  
$folder = $shell.Namespace('C:Windows')    
$item = $folder.Parsename('notepad.exe')
$verb = $item.Verbs() | ? {$_.Name -eq 'Pin to Tas&kbar'}
if ($verb) {$verb.DoIt()}

Method #3

$sa = new-object -c shell.application
$pn = $sa.namespace($env:windir).parsename('notepad.exe')
$pn.invokeverb('taskbarpin')

I pasted all these codes into PowerShell, no error messages showed up, but these commands literally do nothing, I had even restarted explorer.exe, still no change observed…


But no, wait! All is not lost, I can drag the resultant shortcut to taskbar to pin it to taskbar, and I can right click and pin to start, but imagine dragging 2 dozens of them… If I can figure out what exactly these actions do, I can replicate them with commands…


I have opened %Appdata%MicrosoftInternet ExplorerQuick LaunchUser PinnedTaskBar

Folder and found some (non-UWP) app icons that I have pinned are indeed there,

and I have found some app icons that I have added to start menu here:

%AppData%MicrosoftInternet ExplorerQuick LaunchUser PinnedStartMenu

However, I have confirmed simply copying the shortcuts there wouldn’t work.

Found this:https://docs.microsoft.com/en-us/windows/configuration/configure-windows-10-taskbar, it is useful.


I have found a method to do this, since all I want is to add lines to the xml file, I can use this:

[string[]]$xmlconfig=get-content $template | % {
    $_
    if ($_ -match $pattern) {$line}
}

I know this is stupid, that’s why I didn’t post it as an answer, but it does get the job done, don’t laugh at me as I am still learning, I am currently researching how to properly manipulate .xml files…

I tried:

[xml]$template=Get-Content $templatefile
$template.SelectNodes("//DesktopApp")

But it doesn’t work, it also doesn’t work on xml objects converted from .admx files, however .ChildNodes works, and it is not shown by Get-Member… I think treating it like plain text file is the best method now, otherwise I have to use something like this:

$template.LayoutModificationTemplate.CustomTaskbarLayoutCollection.TaskbarLayout.TaskbarPinList.DesktopApp.DesktopApplicationLinkPath

I have already solved it, I will post it as an answer now, I didn’t pursue the registry key, and I no longer want to pin programs to start menu as I don’t normally use it…

Add Application to Windows 10 Taskbar

Remove Application from Windows 10 Taskbar

PowerShell-Functions for Taskbar-Pinning in Windows 10

This small powershell Script adds or removes your own Applications from / to Windows 10 Taskbar (Taskbar-Pinning). The functionality is a bit tricky in Windows 10 as Microsoft doesn’t like to offer Applications to pin themselves during installation.

Script: TaskbarPinning.ps1

Tested with: Windows 10 v1709 (English & German)

Usage: Variant 1: Pin / Unpin regular Executables (no UWP Apps)

Import-Module .TaskbarPinning.ps1

# Add Taskbar-Pinning
Add-TaskbarPinning("C:WindowsNotepad.exe")

# Remove Taskbar-Pinning
Remove-TaskbarPinning("C:WindowsNotepad.exe")

Usage: Variant 2: Pin / Unpin Applications and UWP Apps already listed in Start Menu

Note: Handling Add-/Remove-TaskbarPinningApp can only be done by Processes named explorer
Workaround to do this with Powershell: Make a copy of PowerShell named explorer.exe in Temp-Directory and use this

copy $env:windirSystem32WindowsPowerShellv1.0powershell.exe $env:TEMPexplorer.exe

& $env:TEMPexplorer.exe
Import-Module .TaskbarPinning.ps1

List all by Explorer known Apps containing a given Subtring

List-ExplorerApps("Microsoft")

Shows a List like this:

Name                                                                                             Value
----                                                                                             -----
{6D809377-6AF0-444B-8957-A3773F02200E}MicrosoftWeb Platform InstallerWebPlatformInstaller.exe Microsoft Web Platform Installer
Microsoft.ConnectivityStore_8wekyb3d8bbwe!App                                                    Microsoft Wi-Fi
Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge                                              Microsoft Edge
Microsoft.MicrosoftSolitaireCollection_8wekyb3d8bbwe!App                                         Microsoft Solitaire Collection
Microsoft.WindowsStore_8wekyb3d8bbwe!App                                                         Microsoft Store

Add or Remove TaskbarPinning of an App

# Add or Remove UWP Apps like Edge
Add-TaskbarPinningApp("Microsoft Edge")
Remove-TaskbarPinningApp("Microsoft Edge")

Today I was looking for a solution to create a shortcut to Windows .exe files / Windows binaries / Windows Applications (whatever you want to call them). For future reference, here is a solution which works perfectly with Windows Server 2016 and Windows 10. All credits go to the original author for the starting point. I just made some simple amends and modified the script to take a list of arguments so multiple applications can be added to the Windows Taskbar at the same time.

This solution can be used with configuration management and provisioning tools. All you have to do is supply a list of applications to be pinned and invoke a powershell script. Awesome!

# Function Credit: https://community.spiceworks.com/topic/2165665-pinning-taskbar-items-with-powershell-script
Function Set-PinTaskbar {
    Param (
        [parameter(Mandatory=$True, HelpMessage="Target item to pin")]
        [ValidateNotNullOrEmpty()]
        [string] $Target
        ,
        [Parameter(Mandatory=$False, HelpMessage="Target item to unpin")]
        [switch]$Unpin
    )
    If (!(Test-Path $Target)) {
        Write-Warning "$Target does not exist"
        Break
    }

    $KeyPath1  = "HKLM:SOFTWAREClasses"
    $KeyPath2  = "*"
    $KeyPath3  = "shell"
    $KeyPath4  = "{:}"
    $ValueName = "ExplorerCommandHandler"
    $ValueData =
        (Get-ItemProperty `
            ("HKLM:SOFTWAREMicrosoftWindowsCurrentVersionExplorer" + `
                "CommandStoreshellWindows.taskbarpin")
        ).ExplorerCommandHandler

    $Key2 = (Get-Item $KeyPath1).OpenSubKey($KeyPath2, $true)
    $Key3 = $Key2.CreateSubKey($KeyPath3, $true)
    $Key4 = $Key3.CreateSubKey($KeyPath4, $true)
    $Key4.SetValue($ValueName, $ValueData)

    $Shell = New-Object -ComObject "Shell.Application"
    $Folder = $Shell.Namespace((Get-Item $Target).DirectoryName)
    $Item = $Folder.ParseName((Get-Item $Target).Name)

    # Registry key where the pinned items are located
    $RegistryKey = "HKCU:SoftwareMicrosoftWindowsCurrentVersionExplorerTaskband"
    # Binary registry value where the pinned items are located
    $RegistryValue = "FavoritesResolve"
    # Gets the contents into an ASCII format
    $CurrentPinsProperty = ([system.text.encoding]::ASCII.GetString((Get-ItemProperty -Path $RegistryKey -Name $RegistryValue | Select-Object -ExpandProperty $RegistryValue)))
    # Specifies the wildcard of the current executable to be pinned, so that it won't attempt to unpin / repin
    $Executable = "*" + (Split-Path $Target -Leaf) + "*"
    # Filters the results for only the characters that we are looking for, so that the search will function
    [string]$CurrentPinsResults = $CurrentPinsProperty -Replace '[^x20-x2f^x30-x39x41-x5Ax61-x7F]+', ''

    # Unpin if the application is pinned
    If ($Unpin.IsPresent) {
        If ($CurrentPinsResults -like $Executable) {
            $Item.InvokeVerb("{:}")
        }
    }
    Else {
        # Only pin the application if it hasn't been pinned
        If (!($CurrentPinsResults -like $Executable)) {
            $Item.InvokeVerb("{:}")
        }
    }
    
    $Key3.DeleteSubKey($KeyPath4)
    If ($Key3.SubKeyCount -eq 0 -and $Key3.ValueCount -eq 0) {
        $Key2.DeleteSubKey($KeyPath3)
    }
}

#Set-PinTaskbar("C:windowssystem32notepad.exe");
#Set-PinTaskbar("C:windowssystem32calc.exe");

Posted on

05 May 2019

by Joel Murphy. Last updated:

September 09, 2019

.



👀 Looking for more content?

There’s plenty more content to explore:

  • Blog Posts
  • Tutorials
  • Portfolio Items
  • Money Saving Guides
  • Product Reviews

I run this as part of my imaging. First I create a Start Layout that I like and Export it. You can add the taskbar to that also.

Powershell

Import-StartLayout -LayoutPath "C:Taskbar.xml" -MountPath c:

This is what my Taskbar.xml looks like

XML

<LayoutModificationTemplate
    xmlns="http://schemas.microsoft.com/Start/2014/LayoutModification"
    xmlns:defaultlayout="http://schemas.microsoft.com/Start/2014/FullDefaultLayout"
    xmlns:start="http://schemas.microsoft.com/Start/2014/StartLayout"
    xmlns:taskbar="http://schemas.microsoft.com/Start/2014/TaskbarLayout"
    Version="1">
  <DefaultLayoutOverride>
    <StartLayoutCollection>
	   <defaultlayout:StartLayout GroupCellWidth="6">
        <start:Group Name="Browsers">
          <start:Tile Size="2x2" Column="0" Row="0" AppUserModelID="Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge" />
          <start:DesktopApplicationTile Size="2x2" Column="4" Row="0" DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsGoogle Chrome.lnk" />
          <start:DesktopApplicationTile Size="2x2" Column="2" Row="0" DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsFirefox.lnk" />
        </start:Group>
        <start:Group Name="Microsoft Office 2019">
          <start:DesktopApplicationTile Size="2x2" Column="2" Row="2" DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsPublisher.lnk" />
          <start:DesktopApplicationTile Size="2x2" Column="0" Row="2" DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsWord.lnk" />
          <start:DesktopApplicationTile Size="2x2" Column="4" Row="0" DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsOneNote 2016.lnk" />
          <start:DesktopApplicationTile Size="2x2" Column="0" Row="0" DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsPowerPoint.lnk" />
          <start:DesktopApplicationTile Size="2x2" Column="4" Row="2" DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsOutlook.lnk" />
          <start:DesktopApplicationTile Size="2x2" Column="2" Row="0" DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsExcel.lnk" />
        </start:Group>
        <start:Group Name="General">
		  <start:Tile Size="2x2" Column="4" Row="0" AppUserModelID="Microsoft.WindowsCalculator_8wekyb3d8bbwe!App" />
          <start:DesktopApplicationTile Size="2x2" Column="2" Row="0" DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsZoomZoom.lnk" />
          <start:DesktopApplicationTile Size="2x2" Column="0" Row="0" DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsAcrobat Reader DC.lnk" />
        </start:Group>
      </defaultlayout:StartLayout>
    </StartLayoutCollection>
  </DefaultLayoutOverride>
    <CustomTaskbarLayoutCollection PinListPlacement="Replace">
 	<defaultlayout:TaskbarLayout>
 		<taskbar:TaskbarPinList>
			<taskbar:DesktopApp DesktopApplicationLinkPath="%APPDATA%MicrosoftWindowsStart MenuProgramsSystem ToolsFile Explorer.lnk" />
			<taskbar:DesktopApp DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsGoogle Chrome.lnk" /> 
			<taskbar:DesktopApp DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsOutlook.lnk" /> 
			<taskbar:DesktopApp DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsWord.lnk" /> 
			<taskbar:DesktopApp DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsExcel.lnk" /> 
			<taskbar:DesktopApp DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsAcrobat Reader DC.lnk" /> 
			<taskbar:DesktopApp DesktopApplicationLinkPath="%ALLUSERSPROFILE%MicrosoftWindowsStart MenuProgramsZoomZoom.lnk" /> 
		</taskbar:TaskbarPinList>
	</defaultlayout:TaskbarLayout>
  </CustomTaskbarLayoutCollection>
</LayoutModificationTemplate>

Notice the Bottom half labeled «TaskbarLayout»


3 found this helpful
thumb_up
thumb_down

The method you are looking for is Pin to Tas&kbar, but has been removed. MSFT’s official word is that it was been removed so that programs can not pin unwanted items to the taskbar. (Win10) In short, there are some clunky workaround applications, but assume this is not available. They also said that they would continue to make changes that will eventually prevent any application from pinning to a user’s taskbar. Just got done on a long stretch of trying to get the IE/Edge Pin/Unpin working and finally threw in the towel.

If you want to see if something has the Pin to Tas&kbar method available, run this:

(New-Object -ComObject shell.application).Namespace('C:FolderPathContainingApplication').parsename('Application').verbs() | select Name

If you find an application that still has the method available, you can pin it with this:

$shell = New-Object -COM "Shell.Application"
$folder = $Shell.Namespace('C:FolderPathContainingApplication')
$item = $Folder.Parsename('Application.exe')
$verb = $Item.Verbs() | ? {$_.Name -eq 'Pin to Tas&kbar'}
$verb.DoIt()

Home »
» PowerShell: Pin and Unpin Applications to the Start Menu and Taskbar

PowerShell: Pin and Unpin Applications to the Start Menu and Taskbar

I am in the middle of building a new Windows 10 image and testing out all of the GPOs and applications. One of the settings we do is to add apps to the taskbar and start menu. I had written a script a couple of years ago to do this, but it was in a rush when I had just started this position. With the help of using Sapien’s PowerShell studio, this script was a breeze to write. I didn’t have time to really put much thought into the script. This time around, I have much more time to write the scripts.

The first thing is the old script does not work with Windows 10. I started to do a little research and found this person’s script. I liked it and ended up taking some references from it, but as you have probably seen in some of my other scripts, I also like verification and adding more features. The first of the features I added is being able to generate an official list of all applications on the machine that are listed within the specified GUID. The reason for this feature is that you will need to add that application exactly like it appears in the generated list, otherwise it will not pin or unpin it. I also put a feature to allow the generated list to be exported to a csv file.

The next feature is being able to add all of the apps you want to be pinned or unpinned to a text file. The script will read the text file and process each app. One thing you will see I did was to put a unpin first within the pin functions. I did this so if there is an app already pinned and a possible change was made to the app affecting the pinned shortcut, an updated one will appear. I also put examples at the bottom on how to hardcode apps directly into the script if you do not want to use a text file.

The final feature was to use boolean variables to reflect on success or failure of each processed step. This allows the script to exit out with an error code 1, thereby flagging it as failed if implemented in SCCM/MDT.

Here is a screenshot on how to populate a the text file. As you can see in the script, I hardcoded ‘Applications.txt’ as the name of the file to contain the list of applications. It must be in the same directory as the powershell script. You can override the hardcoded filename by using the -AppsFile parameter. To unpin apps, change the add to remove in the list below.

NOTE: It has come to my attention that on newer versions of Windows 10, the pin to taskbar verb has been removed. The version of Windows 10 I am using, which still works even with all update patches applied, is 1511 (10586.420).

You can download the script from here.

 <#  
      .SYNOPSIS  
           A brief description of the ApplicationShortcutsWindows10.ps1 file.  
        
      .DESCRIPTION  
           This script will add shortcuts to the taskbar.  
        
      .PARAMETER AppsFile  
           Name of the text file that contains a list of the applications to be added or removed  
        
      .PARAMETER ConsoleTitle  
           ConsoleTitle assigned to the PowerShell console  
        
      .PARAMETER OutputToTextFile  
           Select if output needs to go to a text file  
        
      .PARAMETER GetApplicationList  
           Get a list of applications with the specific name needed to use or pinning and unpinning  
        
      .EXAMPLE  
           Read apps from within a text file that resides in the same directory as this script  
                powershell.exe -executionpolicy bypass -file ApplicationShortcutsWin10.ps1 -AppsFile 'Applications.txt'  
   
           Get an official list of applications with the exact names that need to be used for pinning/unpinning  
                powershell.exe -executionpolicy bypass -file ApplicationShortcutsWin10.ps1 -GetApplicationList  
   
           Get an official list of applications with the exact names that need to be used for pinning/unpinning and write to the text file ApplicationList.csv residing in the same directory as this script  
                powershell.exe -executionpolicy bypass -file ApplicationShortcutsWin10.ps1 -GetApplicationList -OutputToTextFile  
   
           Near the bottom of the script are commented out lines that give examples of how to hardcode apps inside this script  
   
      .NOTES  
           ===========================================================================  
           Created with:     SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.123  
           Created on:       6/29/2016 10:33 AM  
           Created by:       Mick Pletcher  
           Organization:  
           Filename:         ApplicationShortcutsWindows10.ps1  
           ===========================================================================  
 #>  
   
 [CmdletBinding()]  
 param  
 (  
           [string]$AppsFile = 'Applications.txt',  
           [ValidateNotNullOrEmpty()][string]$ConsoleTitle = 'Application Shortcuts',  
           [switch]$OutputToTextFile,  
           [switch]$GetApplicationList  
 )  
   
 function Add-AppToStartMenu {  
 <#  
      .SYNOPSIS  
           Pins an application to the start menu  
        
      .DESCRIPTION  
           Add an application to the start menu  
        
      .PARAMETER Application  
           Name of the application. This can be left blank and the function will use the file description metadata instead.  
        
      .NOTES  
           Additional information about the function.  
 #>  
        
      [CmdletBinding()][OutputType([boolean])]  
      param  
      (  
                [Parameter(Mandatory = $true)][string]$Application  
      )  
        
      $Success = $true  
      $Status = Remove-AppFromStartMenu -Application $Application  
      If ($Status -eq $false) {  
           $Success = $false  
      }  
      Write-Host 'Pinning'$Application' to start menu.....' -NoNewline  
      ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | Where-Object{ $_.Name -eq $Application }).verbs() | Where-Object{ $_.Name.replace('&', '') -match 'Pin to Start' } | ForEach-Object{ $_.DoIt() }  
      If ($? -eq $true) {  
           Write-Host 'Success' -ForegroundColor Yellow  
      } else {  
           Write-Host 'Failed' -ForegroundColor Red  
           $Success = $false  
      }  
      Return $Success  
 }  
   
 function Add-AppToTaskbar {  
 <#  
      .SYNOPSIS  
           Pins an application to the taskbar  
        
      .DESCRIPTION  
           Add an application to the taskbar  
        
      .PARAMETER Application  
           Name of the application. This can be left blank and the function will use the file description metadata instead.  
        
      .NOTES  
           Additional information about the function.  
 #>  
        
      [CmdletBinding()][OutputType([boolean])]  
      param  
      (  
                [Parameter(Mandatory = $true)][string]$Application  
      )  
        
      $Success = $true  
      $Status = Remove-AppFromTaskbar -Application $Application  
      If ($Status -eq $false) {  
           $Success = $false  
      }  
      Write-Host 'Pinning'$Application' to start menu.....' -NoNewline  
      ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | Where-Object{ $_.Name -eq $Application }).verbs() | Where-Object{ $_.Name.replace('&', '') -match 'Pin to taskbar' } | ForEach-Object{ $_.DoIt() }  
      If ($? -eq $true) {  
           Write-Host 'Success' -ForegroundColor Yellow  
      } else {  
           Write-Host 'Failed' -ForegroundColor Red  
           $Success = $false  
      }  
      Return $Success  
 }  
   
 function Get-ApplicationList {  
 <#  
      .SYNOPSIS  
           Get list of Applications  
        
      .DESCRIPTION  
           Get a list of available applications with the precise name to use when pinning or unpinning to the taskbar and/or start menu  
        
      .PARAMETER SaveOutput  
           Save output to a text file  
        
      .EXAMPLE  
           PS C:> Get-ApplicationList  
        
      .NOTES  
           Additional information about the function.  
 #>  
        
      [CmdletBinding()]  
      param  
      (  
                [switch]$SaveOutput  
      )  
        
      $RelativePath = Get-RelativePath  
      $OutputFile = $RelativePath + "ApplicationList.csv"  
      $Applications = (New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items()  
      $Applications = $Applications | Sort-Object -Property name -Unique  
      If ($SaveOutput.IsPresent) {  
           If ((Test-Path -Path $OutputFile) -eq $true) {  
                Remove-Item -Path $OutputFile -Force  
           }  
           "Applications" | Out-File -FilePath $OutputFile -Encoding UTF8 -Force  
           $Applications.Name | Out-File -FilePath $OutputFile -Encoding UTF8 -Append -Force  
      }  
      $Applications.Name  
 }  
   
 function Get-Applications {  
 <#  
      .SYNOPSIS  
           Get Application List  
        
      .DESCRIPTION  
           Get the list of applications to add or remove  
        
      .EXAMPLE  
           PS C:> Get-Applications  
        
      .NOTES  
           Additional information about the function.  
 #>  
        
      [CmdletBinding()][OutputType([object])]  
      param ()  
        
      $RelativePath = Get-RelativePath  
      $File = $RelativePath + $AppsFile  
      $Contents = Get-Content -Path $File -Force  
      Return $Contents  
 }  
   
 function Get-RelativePath {  
 <#  
      .SYNOPSIS  
           Get the relative path  
        
      .DESCRIPTION  
           Returns the location of the currently running PowerShell script  
        
      .NOTES  
           Additional information about the function.  
 #>  
        
      [CmdletBinding()][OutputType([string])]  
      param ()  
        
      $Path = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent) + ""  
      Return $Path  
 }  
   
 function Invoke-PinActions {  
 <#  
      .SYNOPSIS  
           Process the application list  
        
      .DESCRIPTION  
           Add or remove applications within the text file to/from the taskbar and start menu.  
        
      .PARAMETER AppList  
           List of applications  
        
      .EXAMPLE  
           PS C:> Invoke-PinActions -AppList 'Value1'  
        
      .NOTES  
           Additional information about the function.  
 #>  
        
      [CmdletBinding()][OutputType([boolean])]  
      param  
      (  
                [Parameter(Mandatory = $false)][ValidateNotNullOrEmpty()][object]$AppList  
      )  
        
      $Success = $true  
      foreach ($App in $AppList) {  
           $Entry = $App.Split(',')  
           If ($Entry[1] -eq 'startmenu') {  
                If ($Entry[2] -eq 'add') {  
                     $Status = Add-AppToStartMenu -Application $Entry[0]  
                     If ($Status -eq $false) {  
                          $Success = $false  
                     }  
                } elseif ($Entry[2] -eq 'remove') {  
                     $Status = Remove-AppFromStartMenu -Application $Entry[0]  
                     If ($Status -eq $false) {  
                          $Success = $false  
                     }  
                } else {  
                     Write-Host $Entry[0]" was entered incorrectly"  
                }  
           } elseif ($Entry[1] -eq 'taskbar') {  
                If ($Entry[2] -eq 'add') {  
                     $Status = Add-AppToTaskbar -Application $Entry[0]  
                     If ($Status -eq $false) {  
                          $Success = $false  
                     }  
                } elseif ($Entry[2] -eq 'remove') {  
                     $Status = Remove-AppFromTaskbar -Application $Entry[0]  
                     If ($Status -eq $false) {  
                          $Success = $false  
                     }  
                } else {  
                     Write-Host $Entry[0]" was entered incorrectly"  
                }  
           }  
      }  
      Return $Success  
 }  
   
 function Remove-AppFromStartMenu {  
 <#  
      .SYNOPSIS  
           Remove the pinned application from the start menu  
        
      .DESCRIPTION  
           A detailed description of the Remove-AppFromStartMenu function.  
        
      .PARAMETER Application  
           Name of the application. This can be left blank and the function will use the file description metadata instead.  
        
      .NOTES  
           Additional information about the function.  
 #>  
        
      [CmdletBinding()][OutputType([boolean])]  
      param  
      (  
                [Parameter(Mandatory = $true)][string]$Application  
      )  
        
      $Success = $true  
      Write-Host 'Unpinning'$Application' from start menu.....' -NoNewline  
      ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | Where-Object{ $_.Name -eq $Application }).verbs() | Where-Object{ $_.Name.replace('&', '') -match 'Unpin from Start' } | ForEach-Object{ $_.DoIt() }  
      If ($? -eq $true) {  
           Write-Host 'Success' -ForegroundColor Yellow  
      } else {  
           Write-Host 'Failed' -ForegroundColor Red  
           $Success = $false  
      }  
      Return $Success  
 }  
   
 function Remove-AppFromTaskbar {  
 <#  
      .SYNOPSIS  
           Unpins an application to the taskbar  
        
      .DESCRIPTION  
           Remove the pinned application from the taskbar  
        
      .PARAMETER Application  
           Name of the application. This can be left blank and the function will use the file description metadata instead.  
        
      .NOTES  
           Additional information about the function.  
 #>  
        
      [CmdletBinding()][OutputType([boolean])]  
      param  
      (  
                [Parameter(Mandatory = $true)][string]$Application  
      )  
        
      $Success = $true  
      Write-Host 'Unpinning'$Application' from task bar.....' -NoNewline  
      ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | Where-Object{ $_.Name -eq $Application }).verbs() | Where-Object{ $_.Name.replace('&', '') -match 'Unpin from taskbar' } | ForEach-Object{ $_.DoIt() }  
      If ($? -eq $true) {  
           Write-Host 'Success' -ForegroundColor Yellow  
      } else {  
           Write-Host 'Failed' -ForegroundColor Red  
           $Success = $false  
      }  
      Return $Success  
 }  
   
 function Set-ConsoleTitle {  
 <#  
      .SYNOPSIS  
           Console Title  
        
      .DESCRIPTION  
           Sets the title of the PowerShell Console  
        
      .PARAMETER Title  
           Title of the PowerShell Console  
        
      .NOTES  
           Additional information about the function.  
 #>  
        
      [CmdletBinding()]  
      param  
      (  
                [Parameter(Mandatory = $true)][String]$Title  
      )  
        
      $host.ui.RawUI.WindowTitle = $Title  
 }  
   
 Clear-Host  
 $Success = $true  
 Set-ConsoleTitle -Title $ConsoleTitle  
 If ($GetApplicationList.IsPresent) {  
      If ($OutputToTextFile.IsPresent) {  
           Get-ApplicationList -SaveOutput  
      } else {  
           Get-ApplicationList  
      }  
 }  
 If (($AppsFile -ne $null) -or ($AppsFile -ne "")) {  
      $ApplicationList = Get-Applications  
      $Success = Invoke-PinActions -AppList $ApplicationList  
 }  
   
 #Hardcoded applications  
 <#  
 $Success = Add-AppToStartMenu -Application 'Microsoft Outlook 2010'  
 $Success = Add-AppToTaskbar -Application 'Microsoft Outlook 2010'  
 #>  
   
 If ($Success -eq $false) {  
      Exit 1  
 }  
   

Like this post? Please share to your friends:
  • Windows 10 portable с флешки без установки
  • Windows 10 please wait что делать
  • Windows 10 pin код стал недоступным
  • Windows 10 pin код в домене
  • Windows 10 photo viewer zip скачать бесплатно для windows