Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Create a file containing timestamp, hostname, hostid and a random bitlocker password
- #Send this file to server then start encrypting the disk
- #Remove-Item -Recurse -Force $env:WinDir\System32\GroupPolicyUsers
- #Remove-Item -Recurse -Force $env:WinDir\System32\GroupPolicy
- Function recoveryKeyGen
- {
- $recoveryKey = ""
- for($i=0; $i -lt 8; $i++)
- {
- $completed = $null
- DO
- {
- $recoveryKeyPart = (Get-Random -Minimum 100000 -Maximum 720895)
- if($recoveryKeyPart %11 -eq 0)
- {
- $recoveryKey = $recoveryKey + $recoveryKeyPart
- $completed = $true
- }
- } While (-not $completed)
- if ($i -ne 7)
- {
- $recoveryKey = $recoveryKey + "-"
- }
- }
- $recoveryKey
- }
- if(-Not (Test-Path C:\Temp))
- {
- New-Item -ItemType Directory -Force -Path C:\Temp
- }
- $recoveryKeyPath = "C:\Temp\" + $env:COMPUTERNAME + "_" + $env:USERNAME + "_recoveryKey.txt"
- if(Test-Path $recoveryKeyPath)
- {
- Remove-Item $recoveryKeyPath
- }
- $timeStamp = "[{0:dd/MM/yy} {0:HH:mm:ss}]" -f (Get-Date)
- Add-Content $recoveryKeyPath $timeStamp
- $computerName = "COMPUTERNAME : " + $env:COMPUTERNAME
- Add-Content $recoveryKeyPath $computerName
- $ipv4 = "IP : "
- $ipv4B = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | where {$_.DefaultIPGateway -ne $null}).IPAddress | select-object -first 1
- #$ipv4B = Test-Connection -ComputerName $env:COMPUTERNAME -Count 1 | Select IPV4Address | %{ "{0,-10}" -f $_.IPV4Address }
- $ipv4 = $ipv4 + $ipv4B
- Add-Content $recoveryKeyPath $ipv4
- $computerSystem = (Get-WmiObject -Class:Win32_ComputerSystem)
- if ( $computerSystem.Manufacturer -like "Hewlett*" )
- {
- Write-Host HP machine
- }
- elseif( $computerSystem.Manufacturer -like "Dell*" )
- {
- Write-Host DELL machine
- }
- $macAddress = "HOSTID : "
- #filter with "*Network Connection" on older machine
- $macAddressB = Get-WmiObject win32_networkadapterconfiguration | select description, macaddress | ? description -like "Realtek*" | select macaddress -ExpandProperty macaddress
- $macAddress = $macAddress + $macAddressB
- Add-Content $recoveryKeyPath $macAddress
- $recoveryKey = "RECOVERYKEY : "
- $recoveryKeyB = recoveryKeyGen
- $recoveryKey = $recoveryKey + $recoveryKeyB
- Add-Content $recoveryKeyPath $recoveryKey
- #Send file to nas or AD share before continuing
- if(Test-Path O:)
- {
- Remove-PSDrive -Name O
- }
- New-PSDrive -Name O -PSProvider filesystem -Root \\ad.test.fr\nas\folder | Out-Null
- Copy-Item -Path $recoveryKeyPath -Destination O:\
- #manage-bde -protectors -add c: -RecoveryPassword $recoveryKeyB
- #manage-bde -on c:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement