Setting up PowerShell Environment
NCache provides Windows PowerShell compatibility to simplify its administrative processes. PowerShell commands help handle remote NCache tasks all over a network from a single machine.
Pre-Requisites
Setting up PowerShell environment requires NCache version 4.8 or above.
PowerShell version 4.0 or above is required to integrate NCache PowerShell provider with it.
You need to refresh the
PSMosulePath
environment variable using NCache PowerShell commands for Windows Server 2016.
Refer to the Microsoft Windows PowerShell section for more details on Getting Started with Windows PowerShell.
NCache PowerShell Management
Go to the Start Menu on the Taskbar and type NCache PowerShell Management to search for NCache PowerShell environment.
To launch an instance of PowerShell, click on the search result that says NCache PowerShell Management. This instance of PowerShell will have ncacheps already imported in it so, when launched, it displays a list of all PowerShell command line tools supported by NCache.
Standard PowerShell
To see the setup variable %NCHOME%
that comes with the NCache installation, launch a new instance of Windows PowerShell. This environment variable is used by PowerShell cmdlets.
To launch a new instance, go to the Start Menu on the Taskbar and type Windows PowerShell.
To launch PowerShell with Administrative privileges, right-click on Windows PowerShell. In the dropdown list, select the option that says Run as Administrator.
Before starting, verify that the
$Env:NCHOME
variable is pointing the directory where NCache is installed.
PS C:\WINDOWS\system32> $Env:NCHOME
C:\Program Files\NCache
Import NCache PowerShell Module
If the PSModulePath
environment variable has not been refreshed, you may not be able to run any NCache PowerShell cmdlets.Import ncacheps.dll NCache PowerShell module located in %NCHOME%\bin\tools\ncacheps.
To import the module, run the following command on Windows PowerShell:le:
Import-Module 'C:\Program Files\NCache\bin\tools\ncacheps\ncacheps.dll'
Run the following command as administrator to check whether the PSMosulePath
variable has been refreshed successfully or not.
echo %PSModulePath%
The following command displays the path to ncacheps. All environment variables are refreshed if the output of this command shows %NCHOME%\bin\tools
.
When to Run PowerShell as Administrator
Administrative privileges are required when performing these following operations:
- Restarting NCache Service
- Running any custom scripts that use NCache cmdlets.
Run Custom Scripts
To create and execute PowerShell scripts using command line tools, do the following:
Search for Windows PowerShell in the Start Menu and Run as Administrator
You need to set script execution policy to
RemoteSigned
by executing the following command:
Set-ExecutionPolicy RemoteSigned
This allows remote execution of commands.
List NCache PowerShell Cmdlets
To get a list of all the functionalities that NCache supports for PowerShell, run the following command:
Get-Command –Module ncacheps
Get Help for PowerShell cmdlets
In order to get a detailed help on any of the cmdlet provided by NCache, run the following command accordingly:
Get-Help <CmdletName> –Full
For example, in order to get a detailed help on the Get-Caches
cmdlet, run the following command.
Get-Help Get-Caches –Full
Troubleshooting
Unable to Run NCache PowerShell Cmdlets (For Windows Environment)
You will see this error only if the PSModulePath
environment variable has not been successfully refreshed after installing NCache. Import the PowerShell module ncacheps.dll provided by NCache at %NCHOME%\bin\tools\ncacheps.
In order to import the ncacheps.dll module, run the following command:
Import-Module 'C:\Program Files\NCache\bin\tools\ncacheps\ncacheps.dll'
In order to verify whether the PSModulePath
environment variable has been refreshed or not, execute the following command as Administrator.
echo %PSModulePath%
This command displays the path where the ncacheps is placed. If the path displayed is %NCHOME%\bin\tools then it shows the environment variables have been successfully refreshed.