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
Problem with cmdlet New-PSDrive and parameter server
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.
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.
Problem with cmdlet New-PSDrive and parameter server
- Attachments
-
- New-PSdrive-on-console.jpg (18.89 KiB) Viewed 4857 times
Re: Problem with cmdlet New-PSDrive and parameter server
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.
See:
help about_Splatting
Code: Select all
$parms = @{
Name = $NomProvider
PSProvider = 'ActiveDirectory'
Root = ''
Scope = 'Global'
credential = $cred
Server = $Domaine
}
New-PSDrive @parms
help about_Splatting
Re: Problem with cmdlet New-PSDrive and parameter server
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.
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.
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: Problem with cmdlet New-PSDrive and parameter server
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.
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
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.
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."
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
Re: Problem with cmdlet New-PSDrive and parameter server
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
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