This repository has been archived on 2020-04-19. You can view files and clone it, but cannot push or open issues or pull requests.
2017-07-14 23:58:11 +02:00
|
|
|
# load ActiveDirectory module
|
|
|
|
Try
|
|
|
|
{
|
|
|
|
Import-Module ActiveDirectory -ErrorAction Stop
|
|
|
|
}
|
|
|
|
Catch
|
|
|
|
{
|
|
|
|
Write-Warning $_
|
|
|
|
Break
|
|
|
|
}
|
|
|
|
|
|
|
|
function Disable-Computer
|
|
|
|
{
|
|
|
|
$samAccountName = Read-Host 'Please enter a computer name'
|
|
|
|
$date = Get-Date -format "yyyy-MM-dd"
|
|
|
|
Get-ADComputer -Identity $samAccountName | Disable-ADAccount
|
2017-07-15 10:44:49 +02:00
|
|
|
$description-paramters = @{'Identity'=$samAccountName;
|
|
|
|
'Description'='disabled by $(whoami) $date'}
|
|
|
|
Set-ADComputer $description-parameters
|
2017-07-15 12:18:07 +02:00
|
|
|
Write-Host
|
2017-07-15 10:44:49 +02:00
|
|
|
Write-Host $samAccountName ' has been disabled' -backgroundcolor green
|
2017-07-15 12:18:07 +02:00
|
|
|
Write-Host
|
|
|
|
Read-Host 'Press a key to continue'
|
2017-07-14 23:58:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Disable-Computer
|