Share via

The term '-SysvolPath' is not recognized..?!

touqeeranjum 80 Reputation points
2023-02-10T11:39:29.0466667+00:00

Hi,

I have the following Powershell script :

$password = ConvertTo-SecureString "Password" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("Administrator", $password)
Install-WindowsFeature -name AD-Domain-Services -IncludeManagementTools
Import-Module ADDSDeployment
Install-ADDSDomainController `
-NoGlobalCatalog:$false `
-CreateDnsDelegation:$false `
-Credential $cred `
-SafeModeAdministratorPassword $password `
-CriticalReplicationOnly:$false `
-DatabasePath "C:\Windows\NTDS" `
-DomainName $domainName `
-InstallDns:$true `
-LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$true `
-SiteName $serverSite `
-SysvolPath "C:\Windows\SYSVOL" `
-Confirm:$false `
-Force:$true

Unsure why I'm receiving the error 

The term '-SiteName' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

If I remove -SiteName then I receive error:

The term '-SysvolPath' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Not understanding why the error appears.

Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
0 comments No comments

Answer accepted by question author
  1. Rich Matheisen 48,116 Reputation points
    2023-02-10T15:43:37.08+00:00

    The use of back-ticks has always been tough to debug. I don't see anything wrong with the code you posted but check for a back-tick that is NOT followed by a CrlF.

    You can avoid the need for annoying back-ticks by using splatting when there are lots of parameters. You get the benefit of having a good code editor do syntax checking as you write the code, too.

    Try this:

    $password = ConvertTo-SecureString "Password" -AsPlainText -Force
    $cred = New-Object System.Management.Automation.PSCredential ("Administrator", $password)
    Install-WindowsFeature -name AD-Domain-Services -IncludeManagementTools
    Import-Module ADDSDeployment
    $p = @{
        NoGlobalCatalog = $false
        CreateDnsDelegation = $false
        Credential = $cred
        SafeModeAdministratorPassword = $password
        CriticalReplicationOnly = $false
        DatabasePath = "C:\Windows\NTDS"
        DomainName = $domainName
        InstallDns = $true
        LogPath = "C:\Windows\NTDS"
        NoRebootOnCompletion = $true
        SiteName = $serverSite
        SysvolPath = "C:\Windows\SYSVOL"
        Confirm= $false
        Force = $true
    }
    
    Install-ADDSDomainController @p
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. MotoX80 37,676 Reputation points
    2023-02-10T13:40:47.9933333+00:00

    That would seem to indicate that the command continuation is not being recognized on the line above the "not recognized" cmdlet. I haven't been able to find any document that says that there is a limit on the number of line continuations, so maybe you have an unprintable character somewhere.

    Try changing the order of the switches. Move '-SiteName' above the NoRebootOnCompletion line. Keep doing that to see if you can identify the problem line.

    Maybe copy and paste the entire script into notepad and then copy and paste it back into ISE or VScode (or whatever editor you use). If you already use notepad to edit the script, then try editing it with ISE to see if it shows a formatting error.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.