Problem with cmdlet New-PSDrive and parameter server

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Post Reply
Philaubur
Posts: 8
Joined: Tue Nov 20, 2018 5:00 am

Problem with cmdlet New-PSDrive and parameter server

Post by Philaubur » Thu Dec 06, 2018 5:47 am

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
Attachments
New-PSdrive-on-console.jpg
New-PSdrive-on-console.jpg (18.89 KiB) Viewed 81 times

User avatar
jvierra
Posts: 12950
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Problem with cmdlet New-PSDrive and parameter server

Post by jvierra » Thu Dec 06, 2018 6:13 am

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

User avatar
jvierra
Posts: 12950
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Problem with cmdlet New-PSDrive and parameter server

Post by jvierra » Thu Dec 06, 2018 6:28 am

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.

User avatar
mxtrinidad
Site Admin
Posts: 230
Joined: Sun Mar 03, 2013 12:42 pm

Re: Problem with cmdlet New-PSDrive and parameter server

Post by mxtrinidad » Thu Dec 06, 2018 9:07 am

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.

User avatar
jvierra
Posts: 12950
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Problem with cmdlet New-PSDrive and parameter server

Post by jvierra » Thu Dec 06, 2018 1:00 pm

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."

User avatar
jvierra
Posts: 12950
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Problem with cmdlet New-PSDrive and parameter server

Post by jvierra » Thu Dec 06, 2018 1:05 pm

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

Post Reply