Powershell command to backup Mongodb dump

We want to automate backup for Mongodb using powershell mongodb dump command but getting error while connecting to mongo db. Please help.

What error are you getting?
Show us a scrernshot

Getting this error

2023-04-17T13:23:41.764+0530 Failed: can’t create session: could not connect to server: connection() error occurred during connection handshake: auth error: unable to authenticate using mechanism “SCRAM-SHA-256”: (AuthenticationFailed) Authentication failed.

using command as below

$date = Get-Date -UFormat %Y-%m-%d;
$backupFolder = $date;
$basePath = “G:\Backup”;
$destinationPath = Join-Path $basePath $backupFolder;

if(!(Test-Path -Path $destinationPath)) {
New-Item -ItemType directory -Path $destinationPath;
(C:"Program Files"\mongodb-database-tools\bin\mongodump.exe --uri --out $destinationPath);
}

skipped URI to hide environment details

Can you connect to your mongodb from shell?
Are you using correct user/PWD in your uri?

yes username and pwd are correct. Even I can take backup using same URI and it is working fine.

Are you using authentication DB in your uri?
Does you password has any special characters?
So mongodump works from command line but not from your automated script?

Nope I want to backup all DB but do you have a way then please share.
yes
It works from commmand line but not from powershell. I get below error from powershell
Failed: can’t create session: could not connect to server: connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism “SCRAM-SHA-1”: (AuthenticationFailed) Authentication failed.

Please help if you have any way to backup using powershell

How do you connect to mongodb using power shell command/variables?
May be your user id not setup properly or you may not be authenticating against the correct db
Check this link.May help