Import Module Query

Is it possible to load a module and then execute a cmdlet at the beginning of a powershell command?

I want to import the following module:

import-module "C:\Program Files\DataCore\SANsymphony\Register-DcsCmdlets.ps1"

and then run the cmdlet below

Connect-DcsServer

However whenever I put them into my Powershell script it just imports the module but does not execute the cmdlet command.

Any suggestions?

July 3rd, 2015 11:12am

Hi Paddy,

  1. Does it work when you paste those lines into a regular powershell console?
  2. After importing it, try running Get-Command -Module "ModuleName". Do you get any results when doing so in the console? When doing so in the script?
  3. Try running Connect-DcsServer -Debug. When doing so in the script, if it works, what output do you get?

Cheers,
Fred

Free Windows Admin Tool Kit Click here and download it now
July 3rd, 2015 11:19am

It is not a module it is a script.  You need to dot source it.

. C:\'Program Files'\DataCore\SANsymphony\Register-DcsCmdlets.ps1

July 3rd, 2015 12:55pm

Actually, Import-Module works just as well for importing functions from ps1.

There are some differences between dotsourcing and importing it, but regular functions will work just dandy with it.

Free Windows Admin Tool Kit Click here and download it now
July 3rd, 2015 1:33pm

The functions don't always import correctly.

July 3rd, 2015 1:55pm

SANsymphony-V Cmdlets  are compiled for .NET 4.5.1, which by default is not supported in Windows  PowerShell in Windows Server 2008 R2 SP1. In order to run the SANsymphony-V Cmdlets, .NET 4.0 runtime  support is required. This is not required for Windows Server 2012.

To configure .NET 4.0 runtime support:

1           Create  a PowerShell configuration file named powershell.exe.config and add  the following commands:

<?xml version="1.0" encoding="utf-8"  ?>
<configuration>
  <startup  useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0"/>
        <supportedRuntime version="v2.0.50727"  />
    </startup>
</configuration>

2           Copy the file  to c:\windows\system32\WindowsPowerShell\v1.0\  and c:\windows\sysWOW64\WindowsPowerShell\v1.0\.

Free Windows Admin Tool Kit Click here and download it now
July 3rd, 2015 1:56pm

Be aware of this: http://www.datacore.com/SSV-WebHelp/Getting_Started_with_SANsymphony-V_Cmdlets.htm

July 3rd, 2015 1:57pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics