I work in higher ed and we need the computers in each of our 100+ classrooms to have a URL shortcut on the desktop to the room camera's IP address. I am trying to automate this using a PowerShell script. I have created a script that has a table, looks up the computer name, looks it up in the table to find the associated IP address, and creates a URL shortcut on the desktop. Unfortunately, I get an error any time I try to pass the $IP variable to $urlShortcut.TargetPath. I'm hoping this is an easy fix? Thanks in advance!
Here is a genericized version of my script. If I replace $urlShortcut.TargetPath = $IP with $urlShortcut.TargetPath = "https://www.google.com", for example, it creates the shortcut to Google.
#Create table
$table = @{}
$table.Add('Room 1,'1.1.1.1')
$table.Add('Room 2','1.1.1.2')
#Determine computer name
$CPUName = $env:computername
#Determine IP address based on room
$IP = $table[$CPUName]
#Display IP Address
write-output $IP
#Create shortcut on desktop
$wshShell = New-Object -ComObject "WScript.Shell"
$urlShortcut = $wshShell.CreateShortcut(
(Join-Path $wshShell.SpecialFolders.Item("AllUsersDesktop") "Camera Control.url")
)
$urlShortcut.TargetPath = $IP
$urlShortcut.Save()
1.1.1.1is not a valid path, try$urlShortcut.TargetPath = "http://$IP/"instead