2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Active Directoryでコンピューターを移動してから保護

Last updated at Posted at 2019-06-18

問題

原因不明でコンピューターオブジェクトが消えてしまった。マネジャーは誰が消した!と大騒ぎだが、バイトさんさえDC接続許可しておいて犯人探しは虚しい。私は孔子より老子派だ。

ソリューション

操作ミスとみなし、再発のないよう対策はする。
コンピューターオブジェクトの[誤って削除されないようにオブジェクトを保護する]プロパティをオンにしましょう。

既存コンピューターの一括変更

Get-ADComputer -filter * -Properties ProtectedFromAccidentalDeletion 
| where {$_.ProtectedFromAccidentalDeletion -eq $false} 
| Set-ADObject -ProtectedFromAccidentalDeletion:$true

新規コンピューター

コンピューターオブジェクトを指定OUに移動後、保護オン。

move_computer.ps1
param(
    [string]$sid
)

function Move-Computer {
    param(
        [string]$sid
    )

    $cname = "${sid}"
    $obj = Get-ADComputer -LDAPFilter "(Name=${cname})"

    $ouName = "grp-${sid}"

    $tpath = Get-ADOrganizationalUnit -LDAPFilter "(Name=${ouName})"

    #まず、指定OUに移動
    Move-ADObject -Identity $obj.ObjectGUID -TargetPath $tpath

    #保護する
    Set-ADObject -Identity $obj.ObjectGUID -ProtectedFromAccidentalDeletion:$true

    $msg = "${cname} を移動・保護完了しました。"
    Write-Host `n $msg -foregroundcolor White -backgroundcolor Blue
}

Move-Computer -sid $sid

他スクリプトから参照時

build.ps1
$path = "\\ad-server\share\ps1\move_computer.ps1"
Invoke-Command -ComputerName ad-server -FilePath $path -ArgumentList s-123

参考

https://blogs.technet.microsoft.com/mconeill/2015/04/12/protect-ous-from-accidental-deletion/
http://adfordummiez.com/?p=431

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?