I'm running Windows 7 with PowerShell 2 installed.
I've downloaded version 2.1 from here - http://pscx.codeplex.com/releases
The Release notes say
unblock the zip file - {which I did}
extract the contents of the ZIP file to your $env:Home\Documents\WindowsPowerShell\Modules folder
I was unsure what $env:Home was so a bit of searching determined that the release notes are expecting an environment variable called Home which doesn't exist on my machine.
A bit more searching says use what is defined as ~ on my machine. So in a PS prompt I run cd ~
Which on my machine led to a network drive U:
I created the following directories U:\Documents\WindowsPowerShell\Modules and copied the extracted Pscx-2.1.0 to the Modules folder. Opened a PowerShell prompt and typed Get-Module -ListAvailable. This didn't give me Pscx in the results.
The above steps actually gave me this folder tree U:\Documents\WindowsPowerShell\Modules\Pscx-2.1.0\Pscx-2.1.0
So I copied the files up a level and tried again with U:\Documents\WindowsPowerShell\Modules\Pscx-2.1.0\ and also tried with U:\Documents\WindowsPowerShell\Modules\Pscx\
I also tried all of the above with this path U:\WindowsPowerShell\Modules\Pscx-2.1.0\
I'm guessing that the Modules aren't actually supposed to be in this directory, so a bit more searching leads to this command. (Get-ChildItem Env:\PSModulePath).Value
which gives the following result
C:\Users\my.name\Documents\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
So I copy the Pscx-2.1.0 folder to here C:\Users\my.name\Documents\WindowsPowerShell\Modules\Pscx-2.1.0
And still no luck.
What step am I missing?
I hadn't actually completed the last step of my above question completely which turned out to be the answer.
Here is that answer for completeness
Unblock the zip file you have downloaded
extract the zip file - this will likely give a folder structure of Pscx-2.1.0/Pscx-2.1.0/{lots of files}
rename the child folder to Pscx - ie - Pscx-2.1.0/Pscx/{lots of files}
In Powershell prompt run (Get-ChildItem Env:\PSModulePath).Value and note the modules folder location.
Copy the child Pscx folder to the Modules folder location given above.
In Powershell prompt run Get-Module -ListAvailable to see the Pscx module available.
In PowerShell 5.0, you can do:
Find-Package pscx | ? ProviderName -eq PSModule | Install-Package -Force
The -Force parameter will cause it to upgrade if an older version is already installed.
In PowerShell 5.1, you'll need:
Find-Package pscx | ? ProviderName -eq PowerShellGet | Install-Package -Force
or
Find-Package pscx -ProviderName PowerShellGet | Install-Package -Force
or just
Install-Package pscx -Force
Just run
choco install pscx
See chocolatey.org for a one-liner to get the choco command.
Keep in mind you may still have to call this in your scripts before running their commands:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser #allows scripts to run from the interwebs, such as pcsx
Update: Looks like PsGet is no longer maintained, but source is still available on github.
You can also use PsGet to easily search and install PowerShell modules.
You can check which modules have been added to PsGet by browsing for all modules:
> Get-PsGetModuleInfo *
Or locate this one specfically:
> Get-PsGetModuleInfo pscx
Then you can install based on that information:
> Install-Module pscx
After spending lot of time searching here and there, i found this blog has very clear steps to solve. try it may helps u ..
http://blogs.technet.com/b/heyscriptingguy/archive/2011/07/18/install-the-pscx-and-80-new-cmdlets-to-ease-powershell-use.aspx
Related
I'm trying to uninstall a module from powershell but I can't.
Powershell says it can't find that module by name but when I list all installed modules, it is right there. What I'm doing wrong?
Try Remove-Module -Name oh-my-posh
I am in a tricky situation where I need to install the MSOnline PowerShell module on a PC and it needs to install NuGet first. Unfortunately, the company firewall does not trust the NuGet website, so the PowerShell cmdlets fail at installation.
I was wondering whether I could simply copy a directory containing the MSOnline module from one PC to my target PC. Is this a viable workaround? Or is there another workaround?
I understand that ideally, I should try to have the website whitelisted, but there is a question of timing here.
As exlpained in the comment of #TheMadTechnician you can copy the module from the $env:PSMdulePath the your requested target machines.
If you've multiple machines for module distribtion you can setup your own private Powershell gallery via a network share as explained here (if that's possible in your company). Based on that multiple machines can use the Get-PSRepository, Find-Module -Repository MyRepository, Install-Module -Name MyModule -Repository MyRepository ,.. cmdlets for module administration. I'm using this a private Powershell gallery to distribute some Git tools about multiple dev-machines. You could also publish own Powershell modules in this gallery, in the background NuGet is used. So your machine with access to NuGet could store the newest module via Save-Module (maybe via a background job) and re-publish it to your private gallery.
You should also check if the MSOnlinemodule has any RequiredPackages that you also need to copy. You can do this via (where I used PowerShellGet as example):
PS C:\> (Get-Module -ListAvailable | ? Name -eq PowerShellGet ).RequiredModules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.0.0.1 PackageManagement
Maybe this helps.
From a computer that has access you could use the Save-Module cmdlet to save the module to a path, then copy that folder to the machine in question that's blocked. Then you can either place the folder in the $env:PSModulePath, or load it explicitly with the full path to the folder.
On a computer that has access to the PowerShell Gallery you can run:
Find-Module MSOnline|Save-Module -Path $home\Downloads
Then copy the MSOnline folder from your downloads folder on that computer to the target computer, and place it in one of the folders listed in $env:PSModulePath, or when you want to load the module you can do it explicitly by defining the path to the module.
I've created a module manifest .psd1 file and I've used Test-ModuleManifest on it which returns nicely and shows the two CmdLets in the binary C# .dll.
The manifest file is in a folder under c:\Program Files\WindowsPowerShell\Modules but when I run Get-Module -ListAvailable it is not showing.
If I run Get-Module it is not showing.
If I run one of the CmdLets then the module is automatically imported and shows when I next run Get-Module.
What am I misunderstanding?? Why doesn't it show as available?
Update
Just done this again with a script module, psm1 and psd1 on a different machine, and same problem. It doesn't show as available and yet posh-git which seems to be setup in a similar way, does.
Okay, the script module does now show up after I fixed a version inconsistency between the version in the manifest and the subfolder name I'd placed it in.
Came in handy:
Test-ModuleManifest
I am using Visual Studio Team Services (VSTS) hosted build agents in my build process. My builds mostly rely on the 'PowerShell' step that calls a script that I have in git. From within this script, I would like to manage PowerShell modules using PowerShellGet. For example, I would like to be able to install pscx simply by running
Install-Module -Name pscx
Unfortunately, hosted agents use PowerShell 4 and they don't have the PowerShellGet module installed. As a result, the Install-Module function is not available.
Anybody has any suggestion to use the PowerShellGet module on VSTS hosted agent? Note that since I don't have admin rights on this machine, I can't install the msi that installs PowerShellGet for PowerShell 4.
To be able to use PowerShellGet, two PowerShell modules are required:
PowerShellGet
PackageManagement
These are available out of the box with PowerShell 5 or through the msi installer available on the PowerShell Gallery.
Instead of deploying these modules through the msi, you can simply add them to your git repository (ex: in a folder named PsModules). You will be able to get a hand on these modules on a machine that has either PS5 or the msi installed. They are usually in the C:\Program Files\WindowsPowerShell\Modules folder.
Then, add the PsModules folders to your PSModulePath environment variable. Starting from there, it is possible to use PowerShellGet as in the following:
$env:PSModulePath = "$env:BUILD_SOURCESDIRECTORY\PsModules;$env:PSModulePath"
Import-Module PowerShellGet
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope currentuser
Save-Module pscx -path "$env:BUILD_SOURCESDIRECTORY\PsModules"
import-module pscx
Write-Host '************************'
Get-Command -module pscx
Is there a way to use PowerShell to view the contents of the GAC?
Another option is that the PowerShell Community Extensions installs a GAC provider, so you can do this:
dir gac:
If you are on PowerShell V2, be sure to grab the 1.2 Beta.
As stated in the docs:
Starting with the .NET Framework 4, the default location for the global assembly cache is %windir%\Microsoft.NET\assembly. In earlier versions of the .NET Framework, the default location is %windir%\assembly.
You may want to search in the appropriate subdir or even in both of them.
To list entries in the GAC;
gacutil -l
In powershell you could parse the text output of the above.
I don't know of a managed interface to inspect the GAC.
I had the same question. The question became more prominent with .Net 4.0 and there not being a Windows Explorer shell plugin available to view the contents. GacUtil works, but is not flexible enough and takes a lot to install. The PowerShell Community Extensions option is to limited in it's functionality and contains to many other CmdLets that I don't need. Therefore I've written my own PowerShell module to view and change the GAC. It can be found on http://powershellgac.codeplex.com
This project has moved to GitHub. You can now find it on:
https://github.com/LTruijens/powershell-gac
It can also be found in the PowerShell Gallery:
https://www.powershellgallery.com/packages/Gac/1.0.1
# Show the assemblies in the GAC, including the file version
Get-GacAssembly SomeCompany* | Format-Table -View FileVersion
I successfully listed GAC using this code snippet:
New-PSDrive -Name HKCR -PSProvider 'Microsoft.PowerShell.Core\Registry' -Root HKEY_CLASSES_ROOT
Get-ItemProperty -Path 'HKCR:\Installer\Assemblies\Global' | Get-Member -MemberType NoteProperty
Solution taken from here.
You can do it just from a command prompt:
cd C:\Windows\assembly
dir
The GAC has a specific directory structure, and you should not go moving or deleting things in there using the command prompt - rather use windows explorer (gui) or gacutil (cli)
If you want to search for a specific assembly in the GAC.
Also note, since MS has changed the GAC structure you can use the -Recurse option from the root to search all the GAC.
CD C:\Windows\assembly
ls -Recurse | ?{$_.Name -like "*log4net*"}