I'm new to coding trying to figure out powershell and confused at If statements. Trying to get this code so it'll create the job scheduling to run on login but it won't create it on the initial first run. I want to add in an if statement at the end to run the command to check if it exists on a desktop as some end users I want to deploy this too will already have it. But I'm unsure where the error lies with the code and how to address or simplify the code? Any help would be greatly appreciated
$PathTest = Test-Path -Path "C:\Users\public\desktop\Google.lnk"
$Google = {$ShortcutPath = "C:\users\public\desktop\Google.lnk"
$IconLocation = "C:\windows\System32\SHELL32.dll"
$IconArrayIndex = 150
$Shortcut = $Shell.CreateShortcut($ShortcutPath)
$Shortcut.TargetPath = "http://www.google.com"
$Shortcut.IconLocation = "$IconLocation, $IconArrayIndex"
$Shortcut.Save()
}
$Trigger = New-JobTrigger -AtLogOn -RandomDelay 00:00:30
Register-ScheduledJob -Trigger $Trigger -RunAs32 -ScriptBlock {$Google} -Name Google
If ($PathTest -is True) {
$PathTest
} Else {
$Google
}