Powershell Import-Module SqlServer Error - powershell

I am trying to download the 'SqlServer' module, I recently upgraded Powershell from 4.0 to 5.0. I have set the execution policy to RemoteSigned. This is on a Windows 2012 R2 Server. I am getting this error.
Import-Module : The specified module 'SqlServer' was not loaded because no valid module file was found in any module directory.
I want to download the SqlServer module.

I cannot use comment right now so I'll just write it down here. Nowadays SQLServer module is shipped with SSMS releases and SQLPS module is shipped with SQL Server itself. I would suggest you download latest SSMS and it should work fine. Note that there's an earlier version of SQLServer module available in SQL Server 2016 Feature Pack.

Related

Powershell Solution: Run modules not supported on a older version of Powershell

I'm currently trying to remote to multiple servers that are on PowerShell 4.0 whereas the local computer currently runs on 5.0+. I am attempting to query servers that are Server 2016 for the Local Administrator group, but will fail for servers that are on 2012. Which upon researching the error messages for cmdlets from Microsoft.Powershell.LocalAccounts indicates that the modules don't exist for 2012.
Rather than updating the PowerShell version, or installing the modules to each server, I wondering if it's possible to execute cmdlets from the local 2016 into remote sessions of the 2012 servers.
Technically, yes, you could copy modules from the local server to one of the module directories on the remote server's $env:PSModulePath and import them in the remote session, but as #mklement0 stated there is no guarantee current modules will work with PowerShell 4.0, let alone Server 2012.
That said, Microsoft.PowerShell.LocalAccounts is a module provided by PowerShell 5.1, not the OS, and the features should still work on 2012. However, I don't have a 2012 instance I can test with. But you may be able to get your task done by upgrading your servers' PowerShell version to PowerShell 5.1 (Windows Management Framework 5.1) to leverage the additional features and built-in modules this version brings. But any modules that are shipped with later Windows versions and not PowerShell itself will remain unavailable.
$localAdminUsers = net localgroup administrators
After some talking with a colleague, I realized I had overcomplicated my script, when I could have used the command prompt. From there, I parse the string for the users I was looking for.
Thank you for your responses.

How do I install Microsoft.SqlServer.SqlManagementObjects (SMO) for SQL 2017 without Visual Studio?

Here's the scenario, we're installing Microsoft Dynamics 365 (Formerly CRM) v9 On Prem on SQL 2017. RTM is only compatible with SQL 2016, but as of update 0.03 it does support SQL 2017. Using a Setup script I can install the latest update (0.22) during installation, but the installer only installs the SQL components for SQL 2016 and not 2017. So when using it I get errors about missing CLR Type and SMO for Sql 2017. I was able to get CLR Type installed using SQL 2017 Feature Pack, but they have removed SMO from this, it's only installable through a Nuget package in Visual Studio from what I'm seeing.
I would rather not install Visual Studio on our Dynamics 365 web servers just to get this package. One work around I found was I installed SSMS 18 which added it, but again I'd rather not install any dev tools on the web servers just to get SMO. Does anyone have other options on how to satisfy this requirement? I tried some PowerShell scripts that supposedly would install it, but nothing worked.
Thanks.
If you have both admin and web access on the target host you can simply install SMO via PowerShell package manager:
Install-Package Microsoft.SqlServer.SqlManagementObjects -Version 161.44091.28
Alternatively you can download the NuGet package manually from:
https://www.nuget.org/api/v2/package/Microsoft.SqlServer.SqlManagementObjects/161.44091.28
move it to "-o$env:ProgramFiles\PackageManagement\ProviderAssemblies" and register by:
Register-PSRepository -Name "SMO" -SourceLocation "location" -InstallationPolicy Trusted
Install-Module SMO

Auto configuring IIS websites / app pools using PowerShell or other scripts

We have a need in our project to automate the process of creating AppPools and Websites in IIS . We would like to write some batch script to get this done. From my research I found that PowerShell has commands that can be used. However when I tried to run IIS module commands in PowerShell on Windows Server 2012 , it does not recognize the commands. Is it correct that this feature was only available for Windows 7 / IIS 7 ? Is it also available now on Windows 2012 R2 / IIS 8. If so where can I find proper documentation and help ?
This feature is of course available in Windows 8/8.1 and Windows Server 2012/2012 R2.
You probably forgot to run Add-PSSnapin WebAdministration before executing other IIS cmdlets.
You can find the full documentation on the Microsoft Technet.
If you run Windows 8.1 or Windows Server 2012 R2 (i.e. you have Windows PowerShell 4.0) you can also use the new PowerShell Desired State Configuration feature with the xWebAdministration Module to create WebAppPools and Websites.

Cannot Load Backup-database cmdlet in powershell v 3.0

I am trying to work around with writing powershell script to backup sql server 2008 R2 database but the example i have searched they require to add backup-sqldatabase cmdlet, but i am unable to see neither SQLPS or backup-sqldatabase cmdlets, I have recently ugraded to powershell v3 and i am running windows server2008 R2 and SQL Server 2008 R2
From http://blog.smu.edu/wis/2012/11/26/sql-server-powershell-module-sqlps/
Although the SQLPS module is installed along with SQL Server, you do not have to install SQL Server to obtain the module. You simply need to install three stand-alone packages from the Microsoft® SQL Server® 2012 Feature Pack, available here:
http://www.microsoft.com/en-us/download/details.aspx?id=29065
Install the following packages in this order:
Microsoft® System CLR Types for Microsoft® SQL Server® 2012 (SQLSysClrTypes.msi)
Microsoft® SQL Server® 2012 Shared Management Objects (SharedManagementObjects.msi)
Microsoft® Windows PowerShell Extensions for Microsoft® SQL Server® 2012 (PowerShellTools.msi)
Be sure to select the appropriate package platform for each, either x86 or x64.
To load the sqlps module in Windows PowerShell:
Import-Module sqlps

Installer for ISDeploymentWizard.exe

Is anyone aware of an installer (msi or otherwise) that drops the SSIS Deployment Wizard executable (ISDeploymentWizard.exe) onto a server (generally found in C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn). We have a web server (we use this as our TFS Agent) that we want to deploy our SSIS 2012 packages from - it is a fairly vanilla server (with IIS, .NET, etc) and hence we don't want a fully blown install of SSIS and/or VS2012 (SSDT) just to deploy SSIS packages.
I realise we can use T-SQL (which requires an instance level perm'd user as an OPENROWSET BULK import is used) and/or MOM to deploy SSIS packages to a remote SQL Server 2012 instance however the preference is to use the SSIS Deployment Wizard
I would have thought ISDeploymentWizard.exe would have been part of the SQL Server 2012 Feature Pack (http://www.microsoft.com/en-us/download/confirmation.aspx?id=35580) however it is unclear exactly whether this is the case and indeed which msi it would belong to
I needed the same ISDeploymentWizard.exe on our build server. We didn't want a full installation of SQLServer on the build box. Using the ISO (en_sql_server_2012_developer_edition_with_sp1_x64_dvd_1228540) from MSDN subscriptions
I chose "Integration Services"
However, if you look thru the files in the ISO there is
sql_is.msi
Which is likely the MSI you looking for. That placed isdeploymentwizard.exe in for out 64-bit machine.
C:\Program Files\Microsoft SQL Server\110\DTS\Binn\ISDeploymentWizard.exe