MDT 작업 순서 중 Powershell AD 모듈 가져 오기


13

이 짧은 powershell 스크립트를 작성하여 MDT 작업 순서의 일부로 컴퓨터의 이름을 바 꾸었습니다.

Import-Module ActiveDirectory

$AdminUsername = 'domain.com\administrator'
$AdminPassword = 'password' | ConvertTo-SecureString -asPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $AdminUsername, $AdminPassword              

$Domain = Get-ADDomainController DomainName domain.com -Discover -NextClosestSite
$Site = $Domain.Site
$DomainComputer = Get-WmiObject Win32_BIOS 
$Serial = $DomainComputer.SerialNumber
$Computername = $Site + "-" + $Serial

Rename-Computer -NewName $Computername -DomainCredential $cred 

MDT는이 작업을 실행할 때 로컬 관리자로 실행합니다. AD 모듈을로드하려고 할 때 다음 오류가 발생합니다.

Warning: Error initializing default drive:  'The server has rejected the client credentials.'.

도메인 관리자로 로그인 한 상태에서 컴퓨터의 로컬 관리자가 아닌 작업 순서가 컴퓨터에서 끝난 직후 모듈을 가져올 수 있습니다. MDT 작업 순서를 도메인 관리자로 실행하거나 작업 순서 중에 로컬 관리자의 권한을 높이는 방법이 있습니까?

제공 할 수있는 도움에 대해 미리 감사드립니다.

Mx

업데이트 : 2015 년 10 월 13 일

나는 MDT 스크립트 내에서 AD 모듈을 사용하지 않기로 결정하고 이것을 게시 한 직후에 이것을 수행하는 다른 방법을 고안했습니다. AD 모듈을 사용한 결과는 기껏해야 예측할 수 없었습니다. 나는 후손을 위해 여기에 게시하고 싶었다. 이것을 MDT 작업 순서에서 "Run Powershell Script"로 State Restore> Custom Tasks 폴더에 추가 한 다음 바로 그 아래에 Restart Computer 작업을 추가합니다. 작년에 1600+ 클라이언트 배포에서 매력처럼 작동했습니다.

$type = [System.DirectoryServices.ActiveDirectory.DirectoryContextType]"Domain"
$context = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext($type, "yourdomain.edu", "domainadmin", "yourpasswordhere")
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetDomain($context)
$DC = $domain.FindDomainController().Name
$Prefix = $DC.Substring(0,5)
$DomainComputer = Get-WmiObject Win32_BIOS 
$Serial = $DomainComputer.SerialNumber
$Computername = $Prefix + "-" + $Serial
$Password = "yourpasswordhere"
$Username = "yourdomain.edu\domainadmin"
$Computer = Get-WmiObject Win32_ComputerSystem
$Computer.Rename($Computername,$Password,$Username)

당신은 $AdminPasswordPSCredential ArgumentList에 실종되지 않았 습니까?
Mathias R. Jessen

사과, 실제 스크립트에 있지만 복사하여 붙여 넣기를 생략해야합니다.
Mx Gorply

당신은 작업 순서가 실행해야합니까 CMDPowerShell? powershell을 실행하는 경우 다음 cmd명령 을 시도하십시오 . powershell 또한 boot.wim 빌드 구성 화면에서 Powershell 상자가 선택되어 있는지 확인합니다.
Elliot Labs LLC

@MxGorply 다음을 확인할 수 있습니까? 1. 상태 복원 단계에서와 같이 OS 설치 후 Windows가 시작된 후 스크립트가 실행되고 있는지 또는 WinPE의 이전 단계에서 또는 새로 고치는 OS에서 스크립트가 실행되고 있는지 확인하십시오. 2.이 단계를 실행하기 전에 도메인 가입 / 결합 도메인 단계를 이미 실행 한 적이 있습니다.
Bernie White

4
@MxGorply Ah 좋아요, 명령 실행에 문제가 없습니까? 경고는 모듈을 가져올 때 유효하지 않은 현재 자격 증명을 사용하여 자동으로 바인딩하려고 시도하기 때문에 예상되는 것입니다. 명령이 실행 중이면 자격 증명을 제공하기 전에 경고가 걱정됩니다. -WarningAction SilentlyContinueimport-module 명령에서 메시지를 억제하는 데 사용할 수 있습니다 .
Bernie White

답변:


1

도메인 사용자로 로그온하지 않은 경우 PSDrive를 명시 적으로 인스턴스화 한 다음 여기에서 * -AD * 명령을 실행해야합니다.

Import-Module ActiveDirectory -WarningAction SilentlyContinue
New-PSDrive -Name AD -PSProvider ActiveDirectory -Server <your DC> -Root //RootDSE/ -Credential $cred
Set-Location AD:
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.