Problem with cmdlet New-PSDrive and parameter server

Ask your 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.
This topic is 5 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
Philaubur
Posts: 10
Last visit: Fri Nov 18, 2022 4:02 am

Problem with cmdlet New-PSDrive and parameter server

Post 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
Attachments
New-PSdrive-on-console.jpg
New-PSdrive-on-console.jpg (18.89 KiB) Viewed 4824 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem with cmdlet New-PSDrive and parameter server

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem with cmdlet New-PSDrive and parameter server

Post 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.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Problem with cmdlet New-PSDrive and parameter server

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem with cmdlet New-PSDrive and parameter server

Post 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."
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem with cmdlet New-PSDrive and parameter server

Post 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
This topic is 5 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked