Monthly Archive

Categories

PowerShell v6

Install-Module in PowerShell v6.2 RC 1

Further to my last post it appears that Install-Module in PowerShell v6.2 RC1 DOESN’T follow the rules. In an elevated session if the scope parameter ISN’T used it will install to $home\Documents\PowerShell\Modules

 

The default appears to be CurrentUser regardless.

 

You have to use -Scope AllUsers if you want it to install in C:\Program Files\PowerShell\Modules

Install-Module Scope parameter

Be aware of the Scope parameter when using Install-Module. The following rules apply:

Allusers scope installs to $env:ProgramFiles\PowerShell\Modules

CurrentUser scope installs to $home\Documents\PowerShell\Modules

NoScope defined:

- - For an elevated PowerShell session, Scope defaults to AllUsers

- - For non-elevated PowerShell sessions in PowerShellGet versions 2.0.0 and above, the Scope is CurrentUser

- - For non-elevated PowerShell sessions in PowerShellGet versions 1.6.7 and earlier, Scope is undefined, and Install-Module fails

 

PowerShell v6.2 RC 1 uses PowerShellGet 2.0.4 and PowerShell v6.1.3 uses version 1.6.7. You’ll see different behavior depending on PowerShell version so the advice is to use the Scope parameter to ensure the module goes where you intend.

 

I usually want my modules in Program files (Allusers) rather than my documents folder (CurrentUser).

 

The lesson seems to be to use the Scope parameter rather than relying on defaults

PSTempDrive

The release of PowerShell v6.2 release candidate 1 brings more experimental features including PSTempDrive.

 

You can view the currently available experimental features using get-ExperimentalFeature. You’ll find a total of four:

PSCommandNotFoundSuggestion
PSImplicitRemotingBatching
PSTempDrive
PSUseAbbreviationExpansion

 

Install PSTempDrive using

Enable-ExperimentalFeature –Name PSTempDrive

 

Restart PowerShell after enabling the feature.

Get-PSDrive will show a new drive named Temp. The root of the drive is set by the path in your TEMP environmental variable.

 

You can use and access the TEMP drive like any other drive set by PowerShell.

 

The TEMP drive follows the pattern of other drives created from a path on an existing drive using the filesystem provider in that the used and free space figures reflect the situation for the whole volume not the individual drives. The free space is OK like this as theoretically you could consume the whole of the available space on your new drive but the used space should reflect reality. The C: drive used space should be for the whole volume but the TEMP: drive should only show the space used in your TEMP folder etc.

 

If you want to remove the experimental feature – use Disable-ExperimentalFeature and restart PowerShell.

 

Not wholly convinced of the need for this particular feature but it gives marginally easier access to the TEMP folder.

 

Remember that experimental features are just that – experimental – and could be modified or even removed in a later version of PowerShell

PowerShell v6.2 release candidate 1

PowerShell v6.2 release candidate 1 is available - https://github.com/PowerShell/PowerShell/releases

 

The only breaking change is to how Join-String works in a non-pipeline scenario.  That shouldn’t be a big issue as Join-String is new to v6.2.

 

The security fixes from v6.1..3 have been incorporated in the release candidate.

 

Experimental features gets a couple of new options round creating a TEMP:\ drive and suggestions given when a command isn’t found.

PowerShell v6.1.3 install problem

PowerShell v6.1.3 install problem prevented my from changing the working directory.

 

The introduction of the –WorkingDirectory parameter pwsh.exe has caused problems – usually forcing PowerShell to ignore any directives in your profile to set a working folder.

 

In previous versions this was overcome by changing the –WorkingDirectory parameter on the icon. This only worked if I started pwsh.exe as Administrator.

 

I had to uninstall PowerShell v6.1.3 (I done an install over the top of v6.1.2) and then reinstall and then set the –WorkingDirectory parameter.

 

Not the best of experiences.

 

PowerShell v6.2 preview 4 had a better install experience – hopefully the issues from v6.1.3 won’t be copied forward. Between the –WorkingDirectory issue and the issue where an over the top install causes PowerShell to open and immediately close so you have to re-install the recent releases have been less than stellar as far as install and configuration have gone.

PowerShell v6.1.3

PowerShell v6.1.3 has been released - https://github.com/PowerShell/PowerShell/releases

It primarily fixes the security issues from

CVE-2019-0627
CVE-2019-0631
CVE-2019-0632

 

which are to do with User Mode Code Integrity policy bypasses

and

CVE-2019-0657

 

which is to do with domain spoofing

 

I expect the fixes to appear in the next release of v6.2 preview

PowerShell v6 experimental features

The ability to have PowerShell v6 experimental features surfaced in the PowerShell v6.2 previews. In preview 4 there are two experimental features.

 

PSImplicitRemotingBatching - Batch implicit remoting proxy commands to improve performance

 

PSUseAbbreviationExpansion - Allow tab completion of cmdlets and functions by abbreviation

 

The available experimental features can be viewed with Get-ExperimentalFeature

 

Use Enable-ExperimentalFeature and Disable-ExperimentalFeature to enable and disable an experimental feature.

 

Remember that experimental features are just that – experimental. They could well change before getting into a PowerShell release or even be removed. Don’t come to rely on them until you know they’ll make a release

Start-Sleep change

Start-Sleep change in PowerShell v6.2 preview 4

Start-Sleep has had this syntax

Start-Sleep [-Seconds] <int> [<CommonParameters>]

Start-Sleep -Milliseconds <int> [<CommonParameters>]

 

since it was first introduced in PowerShell v1 (I think).

You can define the period as a number of seconds or use the –Milliseconds option if you need a fraction of a second.

 

In PowerShell v6.2 preview 4 this changes to

Start-Sleep [-Seconds] <double> [<CommonParameters>]

Start-Sleep -Milliseconds <int> [<CommonParameters>]

 

so you can use

Start-Sleep -Seconds 3.5

 

If you try the command in Windows PowerShell v5.1 or PowerShell v6.1 it will work but I suspect that the 3.5 is converted to an integer so you don’t get the correct delay.

PowerShell v6.2.0 preview 4

PowerShell v6.2.0 preview 4 is now available from https://github.com/PowerShell/PowerShell/releases

 

After installation over the top of preview 3 I found that the PowerShell console would open and then immediately close when I tried to use it.  This is a known issue with a fix in the pipeline as far as I’m aware.  The workaround is to re-run the installer and select the repair option.

 

The conflict between the Working directory and profile seems to have been resolved with the profile taking precedence.

PowerShell v6.1.2

PowerShell v6.1.2 was recently released - https://github.com/PowerShell/PowerShell/releases

 

There doesn’t seem to be any new functionality or breaking changes. Most of the changes seem to be internal to the project.

 

The issue with PowerShell not starting after installation over the top of an existing version seems to have been resolved.

 

The issue with PowerShell WorkingDirectory parameter and any directory changes in your profile don’t seem to have been fully resolved.