Detection:
$SharesCMD = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\Shares.cmd"
if (Test-Path $SharesCMD) {
Write-Output "Shares.cmd file exists in the Startup folder."
exit 0
} else {
Write-Output "Shares.cmd file does not exist in the Startup folder."
exit 1
}
Remediation:
$SharesCMD = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\Shares.cmd"
$SharesCMDContent = @"
@echo off
echo Disconnect networkshares
net use * /delete /y
echo Reconnect networkshares
net use y: \\HOSTNAME\SHARE /user:.\USERNAME PASSWORD! /p:yes
exit
"@
New-Item $SharesCMD -ItemType File
Add-Content $SharesCMD $SharesCMDContent
$Startup = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup"
$Shell = New-Object -ComObject WScript.Shell
$Location = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::DesktopDirectory)
$Application = "Netwerkschijven herstellen.lnk"
$Shortcut = $shell.CreateShortcut("$Location\$Application")
$Shortcut.TargetPath = "$SharesCMD"
$Shortcut.IconLocation = "$SharesCMD,0"
$Shortcut.Description = "Netwerkschijven herstellen"
$Shortcut.WorkingDirectory = "$Startup"
if (-Not (Test-Path $Location\$Application)) {
$Shortcut.Save()
}