Skip to content

Commit a320004

Browse files
committed
Update format
1 parent fca2a38 commit a320004

File tree

1 file changed

+54
-53
lines changed

1 file changed

+54
-53
lines changed

Diff for: AD-COMPUTER-New-ADDomainJoin/New-ADDomainJoin.ps1

+54-53
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
function New-ADDomainJoin
2-
{
3-
<#
1+
function New-ADDomainJoin {
2+
<#
43
.Synopsis
54
Perform offline domain join in c#/PowerShell without djoin.exe
65
.Description
@@ -48,36 +47,36 @@ function New-ADDomainJoin
4847
.link
4948
https://github.com/lazywinadmin/PowerShell
5049
#>
51-
[CmdletBinding()]
52-
PARAM(
53-
[Parameter(Mandatory=$true)]
54-
$machinename,
55-
56-
[Parameter(Mandatory=$true)]
57-
$domain,
58-
59-
[Alias("RunAs")]
60-
[System.Management.Automation.PSCredential]
61-
[System.Management.Automation.Credential()]
62-
$Credential = [System.Management.Automation.PSCredential]::Empty,
63-
64-
$machineaccountou=$null,
65-
66-
$dcname
67-
)
68-
Try{
69-
$FunctionName = (Get-Variable -Name MyInvocation -Scope 0 -ValueOnly).MyCommand
70-
71-
# Detect OS
72-
$OSVersion = [Environment]::OSVersion
73-
$OSVersionMajorMinor = "$($OSVersion.version.major).$($OSVersion.version.minor)"
74-
Write-Verbose -Message "[$FunctionName] OS detected - $OSVersionMajorMinor"
75-
if($OSVersionMajorMinor -lt 6.2){$CodeToUse = 'W2008'}
76-
else{$CodeToUse = 'W2012'}
77-
78-
# W2008
79-
Write-Verbose -Message "[$FunctionName] Declare code for Windows Server 2008/Windows 7"
80-
$source2008 = @'
50+
[CmdletBinding()]
51+
PARAM(
52+
[Parameter(Mandatory = $true)]
53+
$machinename,
54+
55+
[Parameter(Mandatory = $true)]
56+
$domain,
57+
58+
[Alias("RunAs")]
59+
[System.Management.Automation.PSCredential]
60+
[System.Management.Automation.Credential()]
61+
$Credential = [System.Management.Automation.PSCredential]::Empty,
62+
63+
$machineaccountou = $null,
64+
65+
$dcname
66+
)
67+
Try {
68+
$FunctionName = (Get-Variable -Name MyInvocation -Scope 0 -ValueOnly).MyCommand
69+
70+
# Detect OS
71+
$OSVersion = [Environment]::OSVersion
72+
$OSVersionMajorMinor = "$($OSVersion.version.major).$($OSVersion.version.minor)"
73+
Write-Verbose -Message "[$FunctionName] OS detected - $OSVersionMajorMinor"
74+
if ($OSVersionMajorMinor -lt 6.2) { $CodeToUse = 'W2008' }
75+
else { $CodeToUse = 'W2012' }
76+
77+
# W2008
78+
Write-Verbose -Message "[$FunctionName] Declare code for Windows Server 2008/Windows 7"
79+
$source2008 = @'
8180
using System;
8281
using System.Security.Principal;
8382
using System.Runtime.InteropServices;
@@ -325,9 +324,9 @@ Try{
325324
}
326325
'@
327326

328-
# W2012
329-
Write-Verbose -Message "[$FunctionName] Declare code for Windows Server 2012/Windows 8"
330-
$source2012 = @'
327+
# W2012
328+
Write-Verbose -Message "[$FunctionName] Declare code for Windows Server 2012/Windows 8"
329+
$source2012 = @'
331330
using System;
332331
using System.Security.Principal;
333332
using System.Runtime.InteropServices;
@@ -692,24 +691,26 @@ namespace Djoin
692691
}
693692
'@
694693

695-
switch ($CodeToUse) {
696-
'W2008' {
697-
Write-Verbose -Message "[$FunctionName] Importing code for Windows Server 2008/Windows 7"
698-
Add-Type -TypeDefinition $Source2008 -Language CSharp }
699-
default {
700-
Write-Verbose -Message "[$FunctionName] Importing code for Windows Server 2012/Windows 8"
701-
Add-Type -TypeDefinition $Source2012 -Language CSharp}
702-
}
694+
switch ($CodeToUse) {
695+
'W2008' {
696+
Write-Verbose -Message "[$FunctionName] Importing code for Windows Server 2008/Windows 7"
697+
Add-Type -TypeDefinition $Source2008 -Language CSharp
698+
}
699+
default {
700+
Write-Verbose -Message "[$FunctionName] Importing code for Windows Server 2012/Windows 8"
701+
Add-Type -TypeDefinition $Source2012 -Language CSharp
702+
}
703+
}
703704

704-
Write-Verbose -Message "[$FunctionName] Performing offline domain join...."
705+
Write-Verbose -Message "[$FunctionName] Performing offline domain join...."
705706

706-
$DomainJoinBlob = ""
707-
[void]([Djoin.DomainJoin]::GetDomainJoin($($Credential.username),$($Credential.GetNetworkCredential().password),$domain,$machinename,$machineaccountou,$dcname,[ref]$DomainJoinBlob))
707+
$DomainJoinBlob = ""
708+
[void]([Djoin.DomainJoin]::GetDomainJoin($($Credential.username), $($Credential.GetNetworkCredential().password), $domain, $machinename, $machineaccountou, $dcname, [ref]$DomainJoinBlob))
708709

709-
# return the blob
710-
return $DomainJoinBlob
711-
}
712-
catch {
713-
throw $_
714-
}
710+
# return the blob
711+
return $DomainJoinBlob
712+
}
713+
catch {
714+
throw $_
715+
}
715716
}

0 commit comments

Comments
 (0)