We have answer of your question!

100% solved queries, no empty question

Question: Have PowerShell create a shortcut based on OS bits


0

Advertisement


I'm tying to deploy a PowerShell script via a SCCM task sequence. As part of that I need to copy and rename a shortcut from the C:\Program Files x86\TESTapp\test.exe directory. I have that done, however I was just informed that some client are on 32bit OS's.

What is the best way to have PowerShell determine what path to take, ie: "Program Files (x86)" or "Program Files"

Here is what I have that's currently not working:

Switch (Get-WmiObject Win32_OperatingSystem).OSArchitecture {
  "32-bit" {$PF = "Program Files"}
  "64-bit" {$PF = "Program Files x86"}
}

$TargetFile = "$env:C:\$PF\TESTapp\Test.exe"
$ShortcutFile = "$env:Public\Desktop\NewName-Test.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()

Any suggestions would be greatly appreciated.

Thank you!

Question author Monty-peterson | Source

Answer


1


Advertisement


your mistake is - you forgot the () on the switch expression:

Switch ((Get-WmiObject Win32_OperatingSystem).OSArchitecture) {
  "32-bit" {$PF = "Program Files"}
  "64-bit" {$PF = "Program Files x86"}
}

$TargetFile = "C:\$PF\TESTapp\Test.exe"
$ShortcutFile = "$env:Public\Desktop\NewName-Test.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()
Answer author 4c74356b41

Advertisement


Tickanswer.com is providing the only single recommended solution of the question Have PowerShell create a shortcut based on OS bits under the categories i.e powershell , . Our team of experts filter the best solution for you.

Related Search Queries:

create a shortcut to run a powershell script ,

You may also add your answer!