Answered by:
Beginner question on "If" statement

Question
-
Hello and I hope my question isn't too basic for this forum. I came up with a simple script that copies a standard set of shortcuts from a server file share to the all user's desktop. I only want our VPN shortcut to be placed on the desktop of laptop and tablet computers, so I used two "If" statements that copy this shortcut if the 4th and 5th letter of the computer name are LT or TB. The script works fine until it hits the first If statement. At that point it assigns LT as the value for $computertype rather than copying the shortcut if $computertype is equal to LT.
$computertype = $env:COMPUTERNAME.Substring(3,2)
copy-item -Path "\\server\Package_Source_Files\Shortcuts\Aware\Aware Production.url" -Destination "C:\users\Public\Desktop" -Force
copy-item -Path "\\server\Package_Source_Files\Shortcuts\DES\Employee Self Service.url" -Destination "C:\users\Public\Desktop" -Force
Copy-Item -Path "\\server\Package_Source_Files\Shortcuts\DES\Learning Management System SSO.url" -Destination "C:\users\Public\Desktop" -Force
Copy-Item -Path "\\server\Package_Source_Files\Shortcuts\DES\TEMS.url" -Destination "C:\users\Public\Desktop" -Force
Copy-Item -Path "\\server\Package_Source_Files\Shortcuts\System 7\System 7.url" -Destination "C:\users\Public\Desktop" -Force
If ($computertype = "LT") {copy-item "\\server\Package_Source_Files\Shortcuts\F5\DSB VPN.url" -Destination "C:\Users\Public\Desktop" -Force}
If ($computertype = "TB") {Copy-Item "\\server\Package_Source_Files\Shortcuts\F5\DSB VPN.url" -Destination "C:\Users\Public\Desktop" -Force}
Wednesday, November 20, 2019 4:17 PM
Answers
-
In Powershell the equal sign is an assignment operator. If you're doing a comparison you'd use the "-eq" operator.
--- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)
Wednesday, November 20, 2019 4:33 PM
All replies
-
This would normally be done by Group Policy which can easily filter by the type of device.
To get the computer type use WMI to return the Win32_SystemEnclosure class ChassisTypes property. Search for examples of how to use this class to detect device type.
\_(ツ)_/
- Edited by jrv Wednesday, November 20, 2019 4:29 PM
Wednesday, November 20, 2019 4:28 PM -
In Powershell the equal sign is an assignment operator. If you're doing a comparison you'd use the "-eq" operator.
--- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)
Wednesday, November 20, 2019 4:33 PM