How to resolve 'failoverclusters' was not loaded PowerShell script error - powershell

I am trying to run the Batch file which runs the SSIS package. The SSIS package call the PowerShell script to fetch the data from different servers. I am able to get the SSIS package working without any error. But whenever I try to run the batch file which calls the SSIS package, it fails with below error:
import-module : The specified module 'failoverclusters' was not loaded because no valid module file was found in any
module directory.
At E:\XYZ\SSISPckg\Hypv\BASE\XYZ70GTNPENG003.ps1:6 char:1
+ import-module failoverclusters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (failoverclusters:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
The term 'Get-ClusterGroup' 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.
no vms in XYZ70GTNPENG003
Microsoft (R) SQL Server Execute Package Utility
Version 15.0.4223.1 for 32-bit
Copyright (C) 2019 Microsoft. All rights reserved.
I did not get such error when I executed the PowerShell script from SSIS.
I was able to identify FailoverClusters module in powershell folder. I was able to locate it by running Get-Module -ListAvailable command.
I have already executed Install-WindowsFeature "RSAT-Clustering-Powershell" to install the required module. Except this module, I was able to import the other Hyper-V module.
So, can someone please help with understanding where I am making mistake. I am able to run the SSIS package which calls the powershell script using Execute Process Task. But if I call the batch file which run the SSIS package, it fails with above error.

The issue is that the FailoverClusters module is only available from the x64 bit version of PowerShell. e.g. when you are opening PowerShell by yourself, it by default, opens the x64 bit version of PowerShell, and hence, is why your testing works. A 32 bit x86 version of the FailoverClusters module does not exist, and can't be run from a 32 bit environment.
You can see this is the case when you launch Windows PowerShell (x86) and try to load the module:
PS C:\> Import-Module failoverclusters
Import-Module : The specified module 'failoverclusters' was not loaded because no valid module file was found in any
module directory.
At line:1 char:1
+ Import-Module failoverclusters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (failoverclusters:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
When running SSIS packages from a .bat file, it defaults to the x86 version, which will launch the 32-bit x86 version of PowerShell, and hence, will throw the error message.
What you have to do is in your .bat file, explicitly launch the SSIS package with the x64 version of DTExec.exe something like this:
& "C:\Program Files\Microsoft SQL Server\150\DTS\Binn\DTExec.exe" /FILE MyFile.dtsx
This will launch the x64 bit version of DTExec.exe which will in turn launch the x64 version of PowerShell, and make the FailoverClusters module available.

Related

Why do I get an error running Get-WindowsCapability in PowerShell ISE on Windows Server 2012 r2?

I am running the PowerShell ISE on a Windows Server 2012 r2 machine.
When I run the following:
Get-WindowsCapability
I get the following error:
Get-WindowsCapability : The term 'Get-WindowsCapability' 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
Get-WindowsCapability
+ CategoryInfo : ObjectNotFound: (Get-WindowsCapability:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Am I missing a PowerShell package?
How do get this feature working?
Thanks, JohnB
Get-WindowsCapability is a cmdlet from the DISM module.
DISM was deployed natively with Server 2012 R2, but depending on the version of PowerShell or other configuration settings (like where your Windows partition is setup or image specific customizations), sometimes we find that we need to import the module before using it, like so:
Import-Module DISM
#or, to see which commands are in the module
Import-Module DISM -Verbose
If this fails, double check that it wasn't removed somehow. For instance, does it appear when you run the following?
Get-Module DISM -ListAvailable
If it doesn't appear, then it seems the module was removed and maybe the Windows component. No worries, we can get it back with the module too by installing the Windows Automated Deployment Kit (ADK), found here.
Update: you may find the module under this path as well
C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\.
The module file to import would be under the x86\DISM folder or x64\DISM, and named dism.psm1
This command seems not to be available in Windows Server 2012. For a list of all available commands, see Deployment Image Servicing and Management (DISM).

Powershell AzureML Get-AmlWorkspace

Get-AmlWorkspace : One or more errors occurred.
At line:1 char:1
+ Get-AmlWorkspace
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-AmlWorkspace],
AggregateException
+ FullyQualifiedErrorId :
System.AggregateException,AzureML.PowerShell.GetWorkspace
I am trying to use Powershell to connect to Azure ML studio as it looks like an easier way to manage a workspace. I've downloaded the dll file from https://github.com/hning86/azuremlps and changed my config.json file, but get the error above if I try to run any AzureML commands. I've unblocked the DLL file and imported the AzureMLPS module, and I can see the module and commands I am trying to use have been imported by doing Get-Module and Get-Command
For info I've not used Powershell before.
Any suggestions much appreciated!
Have you installed Azure PowerShell Installer on your local machine?
Click here for more info.
Download the latest Azure PowerShell Installer (4.3.1), then install on your local machine. Then retry using Azure PowerShell module and commands.
I installed mine last May, using Azure PowerShell 4.0.1, and the command Get-AmlWorkspace is working.
# Set local folder location
Set-Location -Path "C:\Insert here the location of AzureMLPS.dll"
# Unblock and import Azure Powershell Module (leverages config.json file)
Unblock-File .\AzureMLPS.dll
Import-Module .\AzureMLPS.dll
# Get Azure ML Workspace info
Get-AmlWorkspace
The output on my side looks like this:

How to load PowerShell Module from custom script on vNext build agent?

I am using the standard TFS vNext build step to execute a PowerShell script. Inside the script I am trying to take advantage of some of the functions within the standard TFS Agent modules.
Listed here:
http://blog.majcica.com/2015/11/14/available-modules-for-tfs-2015-build-tasks/
I have seen the following two lines in many PowerShell scripts found in the build steps:
Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Internal"
Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Common"
I have tried to use the same lines in my script, however I get the error:
VERBOSE: Loading module from path
'C:\TFS2015-Agent\Agent1\agent\agent\worker\Modules\Microsoft.TeamFoundation.DistributedTask.Task.Common\Microsoft.TeamFoundation.DistributedTask.Task.Common.dll'.
Import-Module : Could not load file or assembly 'Microsoft.TeamFoundation.DistributedTask.Agent.Interfaces, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
The system cannot find the file specified.
At C:\tfsVnBw1\3\s\Configuration\BuildScripts\CommonFunctions.ps1:25 char:5
+ Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Common" - Error ... + CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
If I try not to import, it writes something like:
The 'Find-Files' command was found in the module 'Microsoft.TeamFoundation.DistributedTask.Task.Common',
but the module could not be loaded. For more information, run 'Import-Module Microsoft.TeamFoundation.DistributedTask.Task.Common'.
At C:\tfsVnBw1\3\s\Configuration\BuildScripts\CommonFunctions.ps1:71 char:16
+ $files = #(FindFiles $filePattern)
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Find-Files:String) [FindFiles], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
Is it not possible to use the Modules from 'normal' PowerShell scripts and not only from PowerShell scripts registered as an actual build step?
Try to specify build agent’s module path, such as:
# Import the Task.Common and Task.Internal dll that has all the cmdlets we need for Build
$agentWorkerModulesPathRoot = "$($env:AGENT_HOMEDIRECTORY)\agent\worker"
$agentDistributedTaskInterfacesModulePath = "$agentWorkerModulesPathRoot\Microsoft.TeamFoundation.DistributedTask.Agent.Interfaces.dll"
$agentWorkerModulesPath = "$($env:AGENT_HOMEDIRECTORY)\agent\worker\Modules"
$agentDistributedTaskCommonModulePath = "$agentWorkerModulesPath\Microsoft.TeamFoundation.DistributedTask.Task.Common\Microsoft.TeamFoundation.DistributedTask.Task.Common.dll"
Write-Host "Importing VSTS Module $agentDistributedTaskInterfacesModulePath"
Import-Module $agentDistributedTaskInterfacesModulePath
Write-Host "Importing VSTS Module $agentDistributedTaskCommonModulePath"
Import-Module $agentDistributedTaskCommonModulePath
Is it not possible to use the Modules from 'normal' PowerShell scripts and not only from PowerShell scripts registered as an actual build step?
It is possible to have a PowerShell script in build step reference a module. I prefer to use the inline PowerShell task as it means I don't have to go through the rigmarole of gated check-in just to change the way the code is packaged. I use it quite often to do things like...
download a common assembly versioning ps1 script from a shared project in TFVC and execute it to stamp assemblies, nuget packages, etc with the build number.
change the build number
Save-Module for a module in a private PS repository, and include it in an artifact (install helpers)
Save-Module again to a temp folder, then import the module and use it to do something to the code being built.
Generate release notes or similar docs
... but you can use the regular "Run a PowerShell script" to do all these too.
Perhaps simpler though is to put the module in the path and update PowerShell if it's < 5.1, If you have PowerShell 3 or later on the build server, and the module is already installed on the server and in the agent account's $PSModulePath, then you don't even need to Import-Module, you can invoke the commands in that module directly.

Error Running Powershell Script Using PSCX

We're running a Team City build server which already executes this script locally with no problem. However, when I try to run this script manually I have the following problem:
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.
PowerShell Community Extensions Imported.
PS C:\Users\user.domain> cd D:\pkg\platform-2b0c7e3f71f9-BUILD01; powershell.exe -noprofile -executionpolicy Bypass -file D:\pkg\platform-2b0c7e3f71f9-BUILD01\stage.ps1 production \\192.168.x.x\staging \\testserver.domain.com\staging
D:\pkg\platform-2b0c7e3f71f9-BUILD01
Start Staging: 12/15/2014 11:18:14
Verifying target environment configuration and staging targets
Copying source and environment switch
...
Verifying configuration files are valid XML files
Test-Xml : The 'Test-Xml' command was found in the module 'Pscx', but the module could not be loaded. For more information, run 'Import-Module Pscx'.
At D:\pkg\platform-2b0c7e3f71f9-BUILD01\stage.ps1:72 char:9
+ if (!(Test-Xml $file))
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Test-Xml:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
So I see the PowerShell Community Extenstions are getting imported (line 4) which makes me wonder what is going on. I am running the script as the exact same user that runs it under Team City. I've checked the build step I'm trying to replicate:
and I can't think of anything that I've missed (working directory option is set to the script file's directory). Any ideas would be appreciated...
Line 4 loads Pscx, Line 5 opens up a new powershell session with -NoProfile option, so it's unlikely that Pscx is loaded in that Powershell session.

Powershell 4 Get-ScheduledTask and Windows

I thought no matter what OS you had, if you had Powershell installed, you would have access to the same default cmdlets.
So I want to use Get-ScheduledTask on my Windows 7 machine. I have Powershell 4 installed. However, when I run it, I get the error:
Get-ScheduledTask : The term 'Get-ScheduledTask' 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
+ Get-ScheduledTask
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-ScheduledTask:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
If I run on my Windows 8.1 with Powershell 4 already pre-installed along with the OS, it works.
Can I get the cmdlets on my Windows 7 machine? There is nothing on the Microsoft Get-ScheduledTask page about Windows 7 so I am guessing not.
If not then would it be a case of using the command line:
scheduled task command line
No doubt someone will point me at this question but that was for Powershell 2. I am on Powershell 4.
Now I am a big fan of not reinventing the wheel, but this guys scripts look a good alternative.
Get-ScheduledTask relies on underlying features of the OS that Windows 7 doesn't have, so there is no way to run the cmdlet on that OS, even with PowerShell v4. In your case, you can either leverage schtasks.exe or the Schedule.Service COM object.
This answer that you linked gives the best overview of these methods, but in the interests of completeness, I'll link the relevant resources here:
schtasks.exe
MS PowerShellPack TaskScheduler module -> (leverages the Schedule.Service COM object)