Skip to main content
SnapCenter 6.0 cmdlets

Implement automatic import module using PowerShell

Contributors netapp-nsriram

You must install PowerShell 7 before you upgrade to SnapCenter 6.0 or later. PowerShell 7 does not automatically load the modules. You cannot execute the PowerShell commands without these modules. You can either use the UI or one of the scripts provided in this section to automatically import the modules.

Import the modules using UI

PowerShell 7 installation provides a desktop shortcut on the SnapCenter Server to start and import the module. This shortcut sets up a PowerShell session with the necessary modules that were imported earlier.

Script to update the script to include the Import-Module command

Each script explicitly imports the SnapCenter module before attempting to use its commands. This ensures that the module is loaded regardless of the environment it has run in.

Step
  1. Run the following command at the beginning of the PowerShell script:

    Import-Module SnapCenter -DisableNameChecking

Script to update the Windows task scheduler command

You can modify the task in the Task Scheduler to first load the module and then execute the script. This can be done by chaining commands in the 'Actions' settings when you edit the task.

Step
  1. Run the following command for the task:

    "C:\Program Files\PowerShell\7\pwsh.exe" -noe -c "& { . 'C:\Program Files\PowerShell\7\Modules\SnapCenter\Scripts\Initialize-SnapCenterPS-Environment.ps1' 'NetApp'; & '<customer script file path>' }"

    For example, "C:\Program Files\PowerShell\7\pwsh.exe" -noe -c "& { . 'C:\Program Files\PowerShell\7\Modules\SnapCenter\Scripts\Initialize-SnapCenterPS-Environment.ps1' 'NetApp'; & 'C:\test.ps1' }"

Script to update the PowerShell profile file

To ensure that the SnapCenter module is imported every time a PowerShell session starts, you must edit the PowerShell profile script. This is useful if you have multiple scripts that depend on the SnapCenter module.

Steps
  1. Run the following command to create the profile file:

    notepad $PROFILE

    This will open the profile file or creates it if it does not exist.

  2. Run the following command to check if the SnapCenter module exists before trying to import.

    Ensure that you update the path accordingly.

    $modulePath = 'C:\Program Files\PowerShell\7\Modules\SnapCenter\SnapCenter.psd1' if (Test-Path $modulePath) { Import-Module $modulePath -DisableNameChecking } else { Write-Warning "SnapCenter module not found at path: $modulePath" }