This is the first post in a blog series about working with remote systems using PowerShell Studio.
The following topics are covered:
Part 1 – Caching PowerShell modules from remote systems
Part 2 – PowerShell remoting
In this first installment I will show you how to use SAPIEN Technologies’ Cache Export tool to collect module information from a remote system, and then use PowerShell Studio to create scripting solutions by using the exported cache.
Part 1 – Caching Remote Systems PowerShell Module
The ability to access modules residing in remote systems allows us to create PowerShell solutions that span infrastructure and DevOps environments. PowerShell Studio and PrimalScript include components, such as the “CacheExport2018.exe”, to help you access modules on remote systems.
Cache Export Executable
PowerShell Studio and PrimalScript include a component that will collect the module information from the remote system—”CacheExport.exe“. This program will extract module information into a file which can be accessed from the Cache Editor feature in PowerShell Studio and PrimalScript. The file “CacheExport2018.zip” contains the cache export executable.
CacheExport2018.zip Location
“CacheExport2018.zip” is located in the SAPIEN Technologies products installation folder under “Redistributables“:
PowerShell Studio file location:
“C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2018\Redistributables”
PrimalScript file location:
“C:\Program Files\SAPIEN Technologies, Inc\PrimalScript 2018\Redistributables”
Building the Cache Export File from a Remote System
The files in “CacheExport2018.zip” need to be extracted on the server where you are going to create the Export Cache file. The steps outlined below are my preferred method because I don’t have to copy over the executable or leave it on the server.
Use Shared Folder
- Create a shared folder locally.
- Copy “CacheExport2018.zip” to the shared folder and extract the files, which will create the “CacheExport2018” folder containing the executable “CacheExport.exe“.
Now we can proceed to connect to this shared folder from the remote system.
Connect to the Shared Folder from the Remote System
- Open a Remote Desktop session to the remote system.
- Use PowerShell or File Explorer to map a drive (x:) to the shared folder that contains the Cache Export executable.
- Navigate to the attached shared folder (e.g., x:\CacheExport2018).
Build the Cache File
- Run “CacheExport.exe” to build the cache file:
- If using PowerShell Console, type the program name CacheExport <Tab>, then press <Enter> to execute.
- If using File Explorer, just double-click on the file name “CacheExport.exe“.
- In the Cache Export pop-up window, change the Export cache files to: filepath to the shared folder.
- Select Rebuild All Cache Files to build the export file.
At the end of this process, select Save to store the cache file in the shared folder.
Reminder: This folder resides where you will use PowerShell Studio (or PrimalScript) to access the exported cache modules.
IMPORTANT: The Cache Export file naming format is “<servername>.CacheExport”. Please do not rename this file.
Load the Exported Cached Modules
The “<servername>.CacheExport” file has been created from the remote system. Now we can access the file from PowerShell Studio. On the Home ribbon > in the Platform section > select Import Remote Cache:
Navigate to the “<servername>.CacheExport” file and click Open:
In the Import Remote Cache dialog, select the Using Windows PowerShell Remoting checkbox > enter the user credentials > then click OK:
Access the Exported Cached Modules
In the Platform section, change the selection from “Local Machine” to the remote system name (e.g., “SUN“):
After selecting the remote system name, the Object Browser panel will refresh and display the Remote System modules as well as any installed snap-ins*:
*Note: PowerShell snap-ins will not be supported in the newer version of PowerShell (> v5).
Now all of the the remote system modules are accessible from the PowerShell Studio Editor.
You can also use the PowerShell Cache Editor to select/deselect modules from the remote system (in the Platform section > select the desired machine > then click the Edit Cache button):
*Note: When selecting a “Computer” from the list in the PowerShell Cache Editor, all checked modules belong to the selected computer.
In our next blog post I will cover “PowerShell Studio: Using PowerShell Remote“.
Related Articles
- Developing PowerShell scripts for other machines (Part 1)
- Video featuring PowerShell Studio Cache Editor
- PowerShell Studio Feature Nugget – Refreshing Local Cache PowerShell Cmdlets and Modules
Feedback
As always, if you have any ideas, comments, or feedback, please visit our feedback forum and reference this post.
Max Trinidad is a Technology Evangelist at SAPIEN Technologies Inc., and a Microsoft PowerShell MVP. You can reach him at maxt@sapien.com