DataCore Cmdlet Configuration
If the DataCore Cmdlets are run from a PowerShell window opened through the installed shortcut, no additional configuration is necessary. The shortcut will automatically run the script Register-DcsCmdlets.ps1 from the installation folder. This script enables .NET 4.0 Command Language Runtime (CLR) support and imports the module DataCore.Executive.Cmdlets.dll that is required to run the cmdlets. The scriptRegister-DcsCmdlets.ps1is provided as a way to make required configuration changes for the session without altering existing customer PowerShell profiles during our software installation. In this manner, only the window opened from the shortcut is configured to run the DataCore cmdlets.
If running the DataCore Cmdlets from a window that is not opened through the installed shortcut, the module must be imported. See Importing the DataCore.Executive.Cmdlets.dll Module for instructions.
To run other applications for Windows PowerShell (such as Windows PowerShell Integrated Shell Environment (ISE) or PowerGUI) with the DataCore Cmdlets, some configuration is required. See Configuring Applications for Windows PowerShell for instructions.
Also, if running a PowerShell script in a DataCore SANsymphony task, the script will run in a non-interactive default environment. See About Automated Tasks for more information. Therefore, cmdlets that require user input or result in console output will not work. Some examples are write-host, read-host, and get-credential.
Importing the DataCore.Executive.Cmdlets.dll Module
The profile script named profile.ps1 can be used to import the module for the session. The profile script is a special script that runs every time a Windows PowerShell window is opened.
The location of the file determines under what conditions the module will be imported.
Usage | File Path |
---|---|
This profile applies to all users and all shells. |
%windir%\system32\WindowsPowerShell\v1.0\profile.ps1 |
This profile applies to all users, but only to the Microsoft.PowerShell shell. |
%windir%\system32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1 |
This profile applies only to the current user, but affects all shells. |
%UserProfile%\My Documents\WindowsPowerShell\profile.ps1 |
This profile applies only to the current user and the Microsoft.PowerShell shell. |
%UserProfile%\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 |
For more profile information, see https://msdn.microsoft.com/en-us/library/windows/desktop/bb613488(v%3dvs.85).aspx.
To import the module:
The profile script will get the installation path from the registry and import the module for the session. For instructions on importing the DataCore Intelligence Service cmdlets, see Enabling or Disabling Data Collection in the DataCore Intelligence Service Help.
- Create a profile script named profile.ps1 and add the following commands.
- Select the desired usage from the table above and copy the file to the corresponding file path. For instance, if you want to import the module for all users and whenever a PowerShell window is opened, then the profile script should be copied to %windir%\system32\WindowsPowerShell\v1.0\profile.ps1.
# Initializing DataCore PowerShell Environment
$bpKey = 'BaseProductKey'
$regKey = get-Item "HKLM:\Software\DataCore\Executive"
$strProductKey = $regKey.getValue($bpKey)
$regKey = get-Item "HKLM:\$strProductKey"
$installPath = $regKey.getValue('InstallPath')
Import-Module
"$installPath\DataCore.Executive.Cmdlets.dll" -ErrorAction Stop -Warningaction SilentlyContinue
Passing a Script Block
A script block can be passed to the script Register-DcsCmdlets.ps1 in order to pass a group of commands without following the configuration steps. The script block will be executed after the .NET 4.0 runtime session is enabled and our module is imported.
To pass a script block:
The following command line segment will pass a script block and keep the PowerShell window open:
$bpKey = '
$regKey = Get-Item
$strProductKey = $
$regKey = Get-Item
$installPath = $
$scriptBlock = {
$Server = $args[0]
$Username = $args[1]
$Password = $args[2]
Connect-DcsServer -server $Server -
$connection = Get-DcsConnection
Write-Host
"Connected to <$connection>"
Disconnect-DcsServer -connection $connection
}
& "$installPath\Register-DcsCmdlets.ps1" –ScriptBlock $scriptBlock –params "machine-name", "machine-username", "machine-password"
To exit the PowerShell window, replace the line above with this one:
& "$installPath\Register-DcsCmdlets.ps1" –ScriptBlock $scriptBlock –params " machine-name ", " machine-username ", " machine-password" –forceExit
Configuring Applications for Windows PowerShell
In order to work with DataCore Cmdlets, any other applications for Windows PowerShell, such as Windows PowerShell Integrated Shell Environment (ISE) or PowerGUI, must be configured to support .NET 4.0 runtime support. Configuration files are required for each executable file used by the application. The configuration files must contain the commands to enable .NET 4.0 runtime support and be named appropriately, as outlined below. The configuration files should reside in the installation folder for the software.
To configure .NET 4.0 runtime support:
- Create or edit an existing config file with the following commands for each executable file used in the software:
- The config file name should match the name of each executable file for the software with ".config" appended.
For example, if the software has two executable files named Console.exe and Editor.exe, then two configuration files named Console.exe.config and Editor.exe.config should exist in the installation folder for the software.
<?xml version="1.0"
encoding="utf-8" ?>
<configuration>
<startup
useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime
version="v4.0"/>
<supportedRuntime
version="v2.0.50727" />
</startup>
</configuration>