Forum Discussion

Rob_Lam's avatar
Rob_Lam
Brass Contributor
Sep 06, 2024

How to combine 4 scripts into 1?

Hi

 

I'm trying to use Intune to deploy microsoft apps icons onto the desktop

At the moment I have 4 scripts for Outlook,Word,PowerPoint and OneNote

 

$TargetFile = "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.exe"
$DesktopPath = [Environment]::GetFolderPath("Desktop")
$ShortcutFile = "$DesktopPath\Outlook.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()

 

$TargetFile = "C:\Program Files\Microsoft Office\root\Office16\ONENOTE.exe"
$DesktopPath = [Environment]::GetFolderPath("Desktop")
$ShortcutFile = "$DesktopPath\OneNote.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()

 

 

$TargetFile = "C:\Program Files\Microsoft Office\root\Office16\POWERPNT.exe"
$DesktopPath = [Environment]::GetFolderPath("Desktop")
$ShortcutFile = "$DesktopPath\POWERPNT.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()

 

$TargetFile = "C:\Program Files\Microsoft Office\root\Office16\WINWORD.exe"
$DesktopPath = [Environment]::GetFolderPath("Desktop")
$ShortcutFile = "$DesktopPath\Word.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()

 

How do I combine these 4 scripts into 1?

  • Rob_Lam Saving everything in one .ps1 file will work, but you can also use this :

     

    $shortcuts = @{
        Outlook    = "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.exe"
        OneNote    = "C:\Program Files\Microsoft Office\root\Office16\ONENOTE.exe"
        PowerPoint = "C:\Program Files\Microsoft Office\root\Office16\POWERPNT.exe"
        Word       = "C:\Program Files\Microsoft Office\root\Office16\WINWORD.exe"
    }
    
    foreach ($shortcut in $shortcuts.GetEnumerator()) {
        $TargetFile = $shortcut.Value
        $DesktopPath = [Environment]::GetFolderPath("Desktop")
        $ShortcutFile = "$DesktopPath\$($shortcut.name).lnk"
        $WScriptShell = New-Object -ComObject WScript.Shell
        $Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
        $Shortcut.TargetPath = $TargetFile
        $Shortcut.Save()
    }
  • Rob_Lam Saving everything in one .ps1 file will work, but you can also use this :

     

    $shortcuts = @{
        Outlook    = "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.exe"
        OneNote    = "C:\Program Files\Microsoft Office\root\Office16\ONENOTE.exe"
        PowerPoint = "C:\Program Files\Microsoft Office\root\Office16\POWERPNT.exe"
        Word       = "C:\Program Files\Microsoft Office\root\Office16\WINWORD.exe"
    }
    
    foreach ($shortcut in $shortcuts.GetEnumerator()) {
        $TargetFile = $shortcut.Value
        $DesktopPath = [Environment]::GetFolderPath("Desktop")
        $ShortcutFile = "$DesktopPath\$($shortcut.name).lnk"
        $WScriptShell = New-Object -ComObject WScript.Shell
        $Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
        $Shortcut.TargetPath = $TargetFile
        $Shortcut.Save()
    }

Resources