Skip to content

Instantly share code, notes, and snippets.

@rafaelfoster
Created February 4, 2021 13:34
Show Gist options
  • Save rafaelfoster/85e8a2bbeec39905a3d7c925bda70ec2 to your computer and use it in GitHub Desktop.
Save rafaelfoster/85e8a2bbeec39905a3d7c925bda70ec2 to your computer and use it in GitHub Desktop.
slmgr /rearm
Function Get-RandomAlphanumericString {
[CmdletBinding()]
Param (
[int] $length = 8
)
Begin{
}
Process{
Write-Output ( -join ((0x30..0x39) + ( 0x41..0x5A) + ( 0x61..0x7A) | Get-Random -Count $length | % {[char]$_}) )
}
}
$randString = (Get-RandomAlphanumericString -length 4 | Tee-Object -variable teeTime )
$UserEmail = Read-Host -Prompt 'Digite o seu email do domínio @sophosbrlabs.com.br (digitar email completo)'
$UserName = $UserEmail.Split("@")
$ComputerName = $UserName[0]
$ComputerName = "WS-" + $ComputerName -replace '[.]'
$ComputerName = $ComputerName + "-BTH-" + $randString
echo $ComputerName
mkdir "C:\resources\"
$SophosSetupURL = 'https://api-cloudstation-us-east-2.prod.hydra.sophos.com/api/download/3efe4bda83da0472eef45407d3516874/SophosSetup.exe'
$outputSophos = 'C:\resources\SophosSetup.exe'
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($SophosSetupURL, $outputSophos)
'New-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce' -Name SophosSetup -Value 'C:\resources\SophosSetup.exe --quiet' -PropertyType ExpandString
C:\resources\SophosSetup.exe --computernameoverride $ComputerName |Out-Null
Write-Host "Renomeando o computador para que ele não fique duplicado no Sophos Central"
netdom renamecomputer $(Get-WmiObject Win32_Computersystem).name /Newname $ComputerName
Write-Host "Reiniciando o computador"
Start-Sleep -Seconds 3
shutdown -r -f -t 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment