Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module Z:\Tools\Modules\ZTIUtility\ZTIUtility.psm1
- [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
- $Message = ""
- If ((get-wmiobject -class Win32_ComputerSystem).DomainRole -match '3|2|4|5'){
- #For Windows Servers
- if ((Get-Module -Name ActiveDirectory -ListAvailable).Name -ne "ActiveDirectory") {
- Install-WindowsFeature -name RSAT-AD-PowerShell
- }
- }elseif ((get-wmiobject -class Win32_OperatingSystem).version -match '(^6\.1)') {
- #For Windows Clients
- if ((get-wmiobject -class Win32_QuickFixEngineering).HotfixID -match 'KB958830'){
- & dism /online /enable-feature /featurename:RemoteServerAdministrationTools /featurename:RemoteServerAdministrationTools-Roles /featurename:RemoteServerAdministrationTools-Roles-AD /featurename:RemoteServerAdministrationTools-Roles-AD-Powershell
- }else{
- $Message = "Computer Object Move Paused: You must manually install Powershell's Active Directory Modules - Typically found in RSAT installer"
- [System.Windows.Forms.MessageBox]::Show($Message)
- }
- }elseif ((get-wmiobject -class Win32_OperatingSystem).version -match '(^10\.)') {
- if ((get-wmiobject -class Win32_QuickFixEngineering).HotfixID -match 'KB2693643'){
- & dism /online /enable-feature /featurename:RSATClient /featurename:RSATClient-Roles /featurename:RSATClient-Features /featurename:RSATClient-Roles-AD /featurename:RSATClient-Roles-AD-DS /featurename:RSATClient-Roles-AD-DS-SnapIns /featurename:RSATClient-Roles-AD-Powershell
- }else{
- $Message = "Computer Object Move Paused: You must manually install Powershell's Active Directory Modules - Typically found in RSAT installer"
- [System.Windows.Forms.MessageBox]::Show($Message)
- }
- }else{
- $Message = "Computer Object Move Paused: You must manually install Powershell's Active Directory Modules - Typically found in RSAT installer"
- [System.Windows.Forms.MessageBox]::Show($Message)
- }
- #Workflow:
- #DomainJoinMachineObjectOU=<Set in custemsettings as a custom variable>
- #Set $DestinationMachineObjectOU to $MachineObjectOU in the task sequence using Set Task Sequence Variable
- #Set $DomainObjectOU to $DomainJoinMachineObjectOU in the task sequence using Set Task Sequence Variable (this is done so the machine joins to the Deployment OU)
- #After the last time your machine will reboot move the machine to $DestinationMachineObjectOU
- #Load the AD Powershell module so that we can move the machine OU
- #Import-Module ActiveDirectory
- #function borrowed from http://gallery.technet.microsoft.com/scriptcenter/Powershell-script-to-33887eb2#content
- function ConvertFrom-Base64($stringfrom) {
- $bytesfrom = [System.Convert]::FromBase64String($stringfrom);
- $decodedfrom = [System.Text.Encoding]::UTF8.GetString($bytesfrom);
- return $decodedfrom
- }
- # Grab the variables from the Task Sequence
- $tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
- $tsenv.GetVariables() | % { Set-Variable -Name "$_" -Value "$($tsenv.Value($_))" }
- #Set Credentials to Task Sequence variable values
- $ClearID = ConvertFrom-Base64 -stringfrom "$UserID"
- $ClearDomain = ConvertFrom-Base64 -stringfrom "$UserDomain"
- $ClearPW = ConvertFrom-Base64 -stringfrom "$UserPassword"
- $User = "$ClearDomain\$ClearID"
- $Password = ConvertTo-SecureString -String "$ClearPW" -AsPlainText -Force
- $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$Password
- #Load the AD Powershell module so that we can move the machine OU
- Import-Module ActiveDirectory
- Write-Host "Moving (Get-WmiObject Win32_ComputerSystem).Name to $MachineObjectOU"
- #Force the machine into the Destination OU.
- Get-ADComputer -Identity (Get-WmiObject Win32_ComputerSystem).Name -Credential $Credential | Move-ADObject -TargetPath "$MachineObjectOU" -Credential $Credential -Verbose
- Exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement