Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-Shortcut {
- param(
- $path = $null
- )
- $obj = New-Object -ComObject WScript.Shell
- if ($path -eq $null) {
- $pathUser = [System.Environment]::GetFolderPath('StartMenu')
- $pathCommon = $obj.SpecialFolders.Item('AllUsersStartMenu')
- $path = dir $pathUser, $pathCommon -Filter *.lnk -Recurse
- }
- $path | ForEach-Object {
- $link = $obj.CreateShortcut($_.FullName)
- $info = @{}
- $info.Hotkey = $link.Hotkey
- $info.TargetPath = $link.TargetPath
- $info.LinkPath = $link.FullName
- $info.Arguments = $link.Arguments
- $info.Target = try {Split-Path $info.TargetPath -Leaf } catch { 'n/a'}
- $info.Link = try { Split-Path $info.LinkPath -Leaf } catch { 'n/a'}
- $info.WindowStyle = $link.WindowStyle
- $info.IconLocation = $link.IconLocation
- New-Object PSObject -Property $info
- }
- }
- function Set-Shortcut {
- param(
- [Parameter(ValueFromPipelineByPropertyName=$true)]
- $LinkPath,
- $Hotkey,
- $IconLocation,
- $Arguments,
- $TargetPath
- )
- begin {
- $shell = New-Object -ComObject WScript.Shell
- }
- process {
- $link = $shell.CreateShortcut($LinkPath)
- $PSCmdlet.MyInvocation.BoundParameters.GetEnumerator() |
- Where-Object { $_.key -ne 'LinkPath' } |
- ForEach-Object { $link.$($_.key) = $_.value }
- $link.Save()
- }
- }
- # assign F11 hotkey to PowerShell (uncomment line, make sure you have full admin privileges:
- #Get-Shortcut | Where-Object { $_.LinkPath -like '*Windows PowerShell.lnk' } | Set-Shortcut -Hotkey F11
- [system.io.directory]::CreateDirectory("C:\Users\Public\Icons")
- c:
- $folderpath =split-path $myinvocation.mycommand.path
- copy icons\*.* C:\Users\Public\Icons
- $shortcuts = Get-Shortcut|Where-Object{$_.Link -ilike "*VMware*"}
- $icons = get-childitem "C:\Users\Public\Icons\"|Where-Object{$_.name -like "*.ico"}
- foreach($shortcut in $shortcuts)
- {
- if (($shortcut.Link)-ilike $icons|Where-Object{$_.name -like "$*($shortcut.link)*"})
- {
- Write-host ("Icon exists for "+ $Shortcut.Link +" Applying now......") -foregroundcolor "green"
- $shortcut.IconLocation = ("C:\Users\Public\Icons\"+[io.path]::GetFileNameWithoutExtension($shortcut.Link)+".ico"+",0")
- }
- Else{write-host ("No Icon exists for "+ $Shortcut.Link +" Not Applying Changes") -foregroundcolor "yellow"}
- }
- $name = [io.path]::GetFileNameWithoutExtension($shortcut.Link)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement