I wrote a script in Wscript but , new to PS. Please can some one guide me. The Script should look at AD and if present look in which location its added and then create shortcut for that location

set Variable GrpName to

Parse String "%grpname%" into GRP and LCTN

set Variable GRP to %GRP%

set variable LCTN to %LCTN%

set variable PRF to C:\Program Files (x86)

set variable XYZ to %PRF%\ABC\DEF

set config to \\srvrlocatn

set config to %config%\Lctn

set config1 to \\inilocatn

Read ini value from %config%IPA.ini into variable IPA

Get Environmental Variable PROGRAMDATA into Variable PROGRAMDATA

set Variable IEXPLORER to C:\program files (x86)\Interenet Explorer\iexplore.exe

If LCTN Equals "NYC" then

create shortcut from %IEXPLORER% to %programdata%\ABCshortcut_NYC

Thank you

Answer Summary:
1 Comment   [ + ] Show Comment


  • Is this to be run on start-up for each system? If so you would be better to start looking though WMI.

    This will get you kicking just replace FQDN with your FQDN and see how that goes for a starter.

    All this does is looks at the WMI of the system and pulls information stored there.

    get-wmiobject win32_ntdomain | Where-Object -FilterScript {$_.DNSForestName -eq 'FQDN'} | select *

    If this has the information you want we can then narrow it down to a single item and make it into a variable based on the word.
Please log in to comment

Answer Chosen by the Author


This will write the shortcut

$DestinationPath = 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Blah IE.lnk'
$SourceExe = 'C:\program files (x86)\Interenet Explorer\iexplore.exe'
$ArgumentsToSourceExe = 'http://blah.com'

$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
$Shortcut.TargetPath = $SourceExe
$Shortcut.Arguments = $ArgumentsToSourceExe
Answered 06/22/2016 by: rileyz
Red Belt

Please log in to comment


Answer this question or Comment on this question for clarity