Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Set-OSCPin
- {
- <#
- .SYNOPSIS
- Set-OSCPin is an advanced function which can be used to pin a item or more items to the Start menu.
- .DESCRIPTION
- Set-OSCPin is an advanced function which can be used to pin a item or more items to the Start menu.
- .PARAMETER <Path>
- Specifies a path to one or more locations.
- .EXAMPLE
- C:\PS> Set-OSCPin -Path "C:\Windows"
- Pin "Windows" to the Start menu sucessfully.
- This command shows how to pin the "shutdown.exe" file to the Start menu.
- .EXAMPLE
- C:\PS> Set-OSCPin -Path "C:\Windows","C:\Windows\System32\shutdown.exe"
- Pin "Windows" to the Start menu sucessfully.
- Pin "shutdown.exe" to the Start menu sucessfully.
- This command shows how to pin the "Windows" folder and "shutdown.exe" file to the Start menu.
- #>
- [CmdletBinding()]
- Param
- (
- [Parameter(Mandatory,Position=0)]
- [Alias('p')]
- [String[]]$Path
- )
- $Shell = New-Object -ComObject Shell.Application
- $Desktop = $Shell.NameSpace(0X0)
- $WshShell = New-Object -comObject WScript.Shell
- $Flag=0
- 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 "Pin to Start")
- {
- $ItemVerb.DoIt()
- $Flag=1
- }
- }
- If($Flag=1)
- {
- Write-Host "Pin ""$ItemName"" to the Start menu sucessfully." -ForegroundColor Green
- }
- Else
- {
- Write-Host "The ""$ItemName"" cannot pin to the Start menu." -ForegroundColor Red
- }
- }
- }
- function Pin-App ([string]$appname, [switch]$unpin, [switch]$start, [switch]$taskbar, [string]$path) {
- if ($unpin.IsPresent) {
- $action = "Unpin"
- } else {
- $action = "Pin"
- }
- if (-not $taskbar.IsPresent -and -not $start.IsPresent) {
- Write-Error "Specify -taskbar and/or -start!"
- }
- if ($taskbar.IsPresent) {
- try {
- $exec = $false
- if ($action -eq "Unpin") {
- ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from taskbar'} | %{$_.DoIt(); $exec = $true}
- if ($exec) {
- Write "App '$appname' unpinned from Taskbar"
- } else {
- if (-not $path -eq "") {
- Pin-App-by-Path $path -Action $action
- } else {
- Write "'$appname' not found or 'Unpin from taskbar' not found on item!"
- }
- }
- } else {
- ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Pin to taskbar'} | %{$_.DoIt(); $exec = $true}
- if ($exec) {
- Write "App '$appname' pinned to Taskbar"
- } else {
- if (-not $path -eq "") {
- Pin-App-by-Path $path -Action $action
- } else {
- Write "'$appname' not found or 'Pin to taskbar' not found on item!"
- }
- }
- }
- } catch {
- Write-Error "Error Pinning/Unpinning $appname to/from taskbar!"
- }
- }
- if ($start.IsPresent) {
- try {
- $exec = $false
- if ($action -eq "Unpin") {
- ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from Start'} | %{$_.DoIt(); $exec = $true}
- if ($exec) {
- Write "App '$appname' unpinned from Start"
- } else {
- if (-not $path -eq "") {
- Pin-App-by-Path $path -Action $action -start
- } else {
- Write "'$appname' not found or 'Unpin from Start' not found on item!"
- }
- }
- } else {
- ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Pin to Start'} | %{$_.DoIt(); $exec = $true}
- if ($exec) {
- Write "App '$appname' pinned to Start"
- } else {
- if (-not $path -eq "") {
- Pin-App-by-Path $path -Action $action -start
- } else {
- Write "'$appname' not found or 'Pin to Start' not found on item!"
- }
- }
- }
- } catch {
- Write-Error "Error Pinning/Unpinning $appname to/from Start!"
- }
- }
- }
- function Pin-App-by-Path([string]$Path, [string]$Action, [switch]$start) {
- if ($Path -eq "") {
- Write-Error -Message "You need to specify a Path" -ErrorAction Stop
- }
- if ($Action -eq "") {
- Write-Error -Message "You need to specify an action: Pin or Unpin" -ErrorAction Stop
- }
- if ((Get-Item -Path $Path -ErrorAction SilentlyContinue) -eq $null){
- Write-Error -Message "$Path not found" -ErrorAction Stop
- }
- $Shell = New-Object -ComObject "Shell.Application"
- $ItemParent = Split-Path -Path $Path -Parent
- $ItemLeaf = Split-Path -Path $Path -Leaf
- $Folder = $Shell.NameSpace($ItemParent)
- $ItemObject = $Folder.ParseName($ItemLeaf)
- $Verbs = $ItemObject.Verbs()
- if ($start.IsPresent) {
- switch($Action){
- "Pin" {$Verb = $Verbs | Where-Object -Property Name -EQ "&Pin to Start"}
- "Unpin" {$Verb = $Verbs | Where-Object -Property Name -EQ "Un&pin from Start"}
- default {Write-Error -Message "Invalid action, should be Pin or Unpin" -ErrorAction Stop}
- }
- } else {
- switch($Action){
- "Pin" {$Verb = $Verbs | Where-Object -Property Name -EQ "Pin to Tas&kbar"}
- "Unpin" {$Verb = $Verbs | Where-Object -Property Name -EQ "Unpin from Tas&kbar"}
- default {Write-Error -Message "Invalid action, should be Pin or Unpin" -ErrorAction Stop}
- }
- }
- if($Verb -eq $null){
- Write-Error -Message "That action is not currently available on this Path" -ErrorAction Stop
- } else {
- $Result = $Verb.DoIt()
- }
- }
- <#
- Pin-App "Microsoft Edge" -unpin -taskbar
- Pin-App "Store" -unpin -taskbar
- Pin-App "Fresh Paint" -unpin -start
- Pin-App "Wunderlist" -unpin -start
- Pin-App "Network Speed Test" -unpin -start
- Pin-App "Microsoft Edge" -unpin -start
- Pin-App "Alarms & Clock" -unpin -start
- Pin-App "Remote Desktop" -unpin -start
- Pin-App "Voice Recorder" -unpin -start
- Pin-App "Bing Wikipedia Browser" -unpin -start
- Pin-App "Photos" -unpin -start
- Pin-App "Calculator" -unpin -start
- Pin-App "Maps" -unpin -start
- Pin-App "Microsoft Store" -unpin -taskbar
- Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Outlook 2016.lnk"
- Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Word 2016.lnk"
- Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Excel 2016.lnk"
- Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Skype for Business 2016.lnk"
- Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Mozilla Firefox.lnk"
- Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Google Chrome.lnk"
- Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Remote Desktop Connection.lnk"
- Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OpenVPN Connect.lnk"
- Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OneNote 2016.lnk"
- Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PowerPoint 2016.lnk"
- Pin-App "Mail" -unpin -start
- Pin-App "Store" -unpin -taskbar
- Pin-App "Calendar" -unpin -start
- Pin-App "Microsoft Edge" -unpin -start
- Pin-App "Microsoft Edge" -unpin -taskbar
- Pin-App "Photos" -unpin -start
- Pin-App "Cortana" -unpin -start
- Pin-App "Cortana" -unpin -taskbar
- Pin-App "Weather" -unpin -start
- Pin-App "Phone Companion" -unpin -start
- Pin-App "Music" -unpin -start
- Pin-App "xbox" -unpin -start
- Pin-App "movies & tv" -unpin -start
- Pin-App "microsoft solitaire collection" -unpin -start
- Pin-App "money" -unpin -start
- Pin-App "get office" -unpin -start
- Pin-App "onenote" -unpin -start
- Pin-App "news" -unpin -start
- Pin-App "Groove Music" -unpin -start
- Pin-App "Sway" -unpin -start
- #>
- Pin-App "Skype" -unpin -start
- Pin-App "Microsoft Edge" -unpin -taskbar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement