Page 1 of 1

Problem with cmdlet New-PSDrive and parameter server

Posted: Thu Dec 06, 2018 5:47 am
by Philaubur
Hello,

This cmdlet make me a problem

New-PSDrive `
-Name $NomProvider `
-PSProvider ActiveDirectory `
-Root "" `
-Scope Global `
-credential $cred `
-Server $Domaine

On a powershell console, it works very well but, on SPS 2018 it's not work.

This error message is displayed:
"A parameter cannot be found that matches parameter name 'server'"

An idea ?
Regards

Re: Problem with cmdlet New-PSDrive and parameter server

Posted: Thu Dec 06, 2018 6:13 am
by jvierra
Do not use line continuation characters as they make life more difficult and are a hangover from PS1. To list parameters conveniently use a splat.

Code: Select all

$parms = @{
    Name = $NomProvider
    PSProvider = 'ActiveDirectory'
    Root = ''
    Scope = 'Global'
    credential = $cred
    Server = $Domaine
}
New-PSDrive @parms
See:
help about_Splatting

Re: Problem with cmdlet New-PSDrive and parameter server

Posted: Thu Dec 06, 2018 6:28 am
by jvierra
Ok. I see your issue. "-Server" value is likely in the wrong format, is the wrong object type or is null.

It may also be that you have issues with the AD version on your system. Be sure you are using the correct version of PS in the tool ribbon.

The error is a runtime error and should not have anything to do with SPS.

Re: Problem with cmdlet New-PSDrive and parameter server

Posted: Thu Dec 06, 2018 9:07 am
by mxtrinidad
Sorry! But, there's nothing wrong with using the continuation '`' as it helps make the script line readable. But, it's a personal choice as is really optional.

If you do a Get-Help New-PSDrive, in Windows PowerShell 5.1, you'll notice you're using a parameter "-server" that doesn't exist. The error is correct leaning to the actual issue with the cmdlet. It's nothing to with the continuation character.

So, when in doubt, use the Get-Help for the cmdlet to verify the parameters being use.

Re: Problem with cmdlet New-PSDrive and parameter server

Posted: Thu Dec 06, 2018 1:00 pm
by jvierra
The backtick is not illegal but it is very much prone to breakage. Splatting is much easier to manage.

Yes it is a matter of choice but most coders dropped using it many years ago in favor of splatting.

Also the "-Server" parameter is very much required when mapping to the "ActiveDirectory" provider. The parameter is not listed in help. until you switch to the "AD:" folder then it should list.

Code: Select all

PS AD:\> help new-psdrive -par server

-Server <string>
    Specifies the specific instance of Active Directory (DS or LDS) to connect to. The parameter input value can be a: domain name, forest name or host name:port.

    Required?                    false
    Position?                    named
    Default value
    Accept pipeline input?       false
    Accept wildcard characters?  false
Note that this parameter is only available for the AD provider. If you run the help from a non-AD drive you will get an error saying "Get-Help : No parameter matches criteria server."

Re: Problem with cmdlet New-PSDrive and parameter server

Posted: Thu Dec 06, 2018 1:05 pm
by jvierra
Here is a blog from the AD PowerShell Team at MS discussing the provider and New-PsDrive.

https://blogs.msdn.microsoft.com/adpowershell/2009/03/11/active-directory-powershell-the-drive-is-the-connection/

You can also read about all of the CmdLet extensions under the ActiveDirectory provider

help activedirectory

The same is true for other providers although the AD provider has the most significant impact on the "core" CmdLets.

help registry