Link to home
Start Free TrialLog in
Avatar of Zahid Ahamed
Zahid AhamedFlag for United States of America

asked on

Why i can't install dbatools

Hi Expert,
Why i can't install Install-Module -Name DBATools


Install-Module : The term 'Install-Module' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ Install-Module -Name DBATools -Force
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Install-Module:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Please help
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Why i can't install Install-Module -Name DBATools

try open a Powershell console (with Administrator priviledge) and run that command again.

User generated image
also make sure you got Internet connection on your machine before that execution.
Avatar of Zahid Ahamed

ASKER

I did Ryan but i am not sure why this is failing, also i do have the internet connection
User generated image

Avatar of oBdA
oBdA

Your PowerShell version is probably too old.
Enter $PSVersionTable in the console, and I think you'll find a PSVersion of 4.
Here's the latest Windows version of PowerShell; install it and then try the Install-Module again.
Windows Management Framework 5.1
https://www.microsoft.com/en-us/download/details.aspx?id=54616
Installed Windows Management Framework 5.1
But now i have encountered the below error

User generated image


emmm, I just tried and it worked for me.

User generated image
Could just run your "Save-Module -Name DBATools ..." without any issues.
Did you run the recommend "Get-PSRepository", and if so, what did it return?
If that server is behind a proxy, use Save-Module with the -Proxy (and -ProxyCredential, if required) arguments.
Since April 2020, TLS 1.2 is set as default for the PowerShell Gallery.
https://devblogs.microsoft.com/powershell/powershell-gallery-tls-support/ 

Run this, then reboot and see if it helps:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Open in new window

Hello oBdA,
I have finally saved these files under this location.
User generated imagePlease let me know what will be the next step...
If you're having trouble interacting with the PSGallery because of TLS version support, you can change the .Net Framework (because Windows PowerShell uses .Net) to enable strong crypto to resolve this.
https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls
I'm pretty sure the command in the previous post is only effective for the session it's run in.  The below registry edits are persistent and can affect other .Net applications (for instance, I used it to cure a problem in ADFS in Server 2012 R2 before).
                # For 32-bit applications on 32-bit systems and 64-bit applications on x64-based systems:
                New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319" -Name "SchUseStrongCrypto" -PropertyType DWORD -Value 1 -Force | Out-Null
                New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319" -Name "SystemDefaultTlsVersions" -PropertyType DWORD -Value 1 -Force | Out-Null

                # For 32-bit applications on x64-based systems:
                New-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319" -Name "SchUseStrongCrypto" -PropertyType DWORD -Value 1 -Force | Out-Null
                New-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319" -Name "SystemDefaultTlsVersions" -PropertyType DWORD -Value 1 -Force | Out-Null

Open in new window

SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks i just did
C:\Program Files\WindowsPowerShell\Modules\dbatools
What will be the next step to install dbatools?
That's it. The following command should show you the module if it all went as it should:
Get-Module dbatools -ListAvailable

Open in new window

Output should look like this:
    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.0.107    dbatools                            {Select-DbaObject, Set-DbatoolsConfig, Start-DbaMigration, Copy-DbaDatabase...}

Open in new window


Then you can import the module into a PowerShell session using
Import-Module dbatools

Open in new window

Thanks!
User generated image
Could you please give me an one example how to execute the below command and from where? I meant do i have to run this command from this location C:\Program Files\WindowsPowerShell\Modules\dbatools ??!!!

Copies all logins from Source Destination. If a SQL Login on Source exists on the Destination, the Login on Destination will be dropped and recreated.
If active connections are found for a login, the copy of that Login will fail as it cannot be dropped.

"Copy-DbaLogin -Source sqlserver2014a -Destination sqlcluster -Force"

Thanks Again!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you so much for your clarification. It worked for me.

User generated image
From now, i can use dbatools command from PowerShell console.
Thanks for your help!