I am trying to create a powershell script which will create a session in a remote machine and run a series of commands. These commands in question are to drop a Mongodb database before deployment of code.
I have the session side working but when I try to run the cmd I get X is not recognized as the name of a cmdlet.
The process I take when I am logged into the remote machine and using cmd is:
'C:\Program Files\MongoDB\Server\4.0\bin\mongo.exe'use <database>db.dropDatabase()
This works correctly and I am trying to run those in powershell. They need to be run line by line in order to work.
ps1:
$session = New-PSSession -ComputerName "remoteMachine" -Credential $cred
Enter-PSSession -Session $session
Invoke-Command -ComputerName "remoteMachine" -ScriptBlock {
& 'C:\Program Files\MongoDB\Server\4.0\bin\mongo.exe'
& 'use <database>'
& 'db.dropDatabase()'
}
Exit-PSSession
Get-PSSession | Remove-PSSession
When this is run I am getting the following errors:
The term 'use Assessment' is not recognized as the name of a cmdlet,
The term 'db.dropDatabase()' is not recognized as the name of a cmdlet,