Up 0 Down 0

Desktop Shortcut to Office.com

Detection:

$shortcutPath = "C:\Users\Public\Desktop\Office.url"
if (Test-Path $shortcutPath) {
    Write-Output "The shortcut already exists at $shortcutPath."
    exit 0
} else {
    Write-Output "The shortcut does not exist at $shortcutPath."
    exit 1
}

Remediation:
$shortcutPath = "C:\Users\Public\Desktop\Office.url"
$url = "https://www.office.com"
if (-not (Test-Path $shortcutPath)) {
    # Create the content for the shortcut
    $shortcutContent = @"
[InternetShortcut]
URL=$url
"@
    $shortcutContent | Out-File -Encoding ASCII -FilePath $shortcutPath
    if (Test-Path $shortcutPath) {
        Write-Output "Shortcut successfully created at $shortcutPath."
        exit 0
    } else {
        Write-Output "Failed to create the shortcut at $shortcutPath."
        exit 1
    }
} else {
    Write-Output "Shortcut already exists at $shortcutPath. No action needed."
    exit 0
}