powershell remote import module error - powershell

I have a problem with this code
Invoke-Command -ComputerName $CSC_SERVER -ScriptBlock {
Import-Module ("C:\Build_v.6.1.0.9\Tools\CommonComponents.BuildCommands.dll")
}
Error:
Could not load file or assembly "file: /// C: \ Build V.6.1.0.9 \ Tools \ CommonComponents.BuildCommands.dll" or one of their dependent components. The assembly created in a later version of the runtime than the current, and can not be loaded.
When I go to the server via RDP and try to load this module everything is OK.
how to fix this problem?
UPD
> Invoke-Command -ComputerName $CSC_SERVER -ScriptBlock {$PSVersionTable}
Name Value
---- -----
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
PSCompatibleVersions {1.0, 2.0}
CLRVersion 2.0.50727.5420
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
And same via local session on remove server
> $PSVersionTable
Name Value
---- -----
PSVersion 2.0
PSCompatibleVersions {1.0, 2.0}
BuildVersion 6.1.7601.17514
CLRVersion 4.0.30319.17929
WSManStackVersion 2.0
PSRemotingProtocolVersion 2.1
SerializationVersion 1.1.0.1
Now I see that difference in CLRVersion. Powershell remoting uses CLR version 2.0. What is the reason for this behavior? And how to change it to version 4.0?

Related

Export-Counter missing from Powershell 7.1

Any idea how to export counters in Powershell 7.1.0? The command is missing with the latest update.
Get-Command -Module Microsoft.PowerShell.Diagnostics
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Get-Counter 7.0.0.0 Microsoft.PowerShell.Diagnostics
Cmdlet Get-WinEvent 7.0.0.0 Microsoft.PowerShell.Diagnostics
Cmdlet New-WinEvent 7.0.0.0 Microsoft.PowerShell.Diagnostics
❯ $PSVersionTable
Name Value
---- -----
PSVersion 7.1.0
PSEdition Core
GitCommitId 7.1.0
OS Microsoft Windows 10.0.19042
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

write-host -NoNewline parameter is ignored with powershell 5.1

Starting with WMF 5.1 the -NoNewLine option for Write-Host is essentially ignored.
Simple example:
PS C:\> Write-Host "no newline test " -NoNewline
Current Behaviour:
no newline test
PS C:\>
Expected Behavior
no newline test PS C:\>
PS version Table is as follows :
Name Value
---- -----
PSVersion 5.1.14409.1012
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1012
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
As per Microsoft docs for powershell 5.1, Next Prompt should come in the same line after output of Write-Host "no newline test" -NoNewline statement.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-host?view=powershell-5.1
Any idea why it is not functioning as expected?

Get-Command not behaving as described

All the examples I see for Get-Command show the results as
CommandType Name Definition
----------- ---- ----------
Whereas I get:
CommandType Name Version Source
----------- ---- ------- ------
I am using Windows 7 with Powershell v5, PSCX, more details below:
PS C:\Users\pollock> $PSVersionTable
Name Value
---- -----
PSVersion 5.0.10586.117
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.117
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Any ideas why?
Thats probably because the examples omit the Source column. However, you can use the Select-Object cmdlet to select the properties you want:
Get-Command | Select-Object CommandType, Name, Definition

Module is not available after being imported

I was using the WASP PowerShell Module, previously it worked correctly but has now stopped working.
Currently I'm unable to import the module as it seems to be empty. Get-Command -Module WASP also returns nothing.
Import-Module -Name .\WASP.dll -Force
Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Co
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script 1.1 PSReadline {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-P
Binary 1.2.0.0 WASP
I've downloaded the module again but it did not help (I remember to unlock file after downloading). I'm using Windows 10.
How do I make the module work again?
Powershell version
Name Value
---- -----
PSVersion 5.0.10586.672
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.672
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Psedit on a item created with the New-Item cmdlet throws exception

When I create a new file using the New-Item cmdlet and want to edit it within PowerShell ISE using psedit I receive the following exception:
Exception calling "Add" with "1" argument(s): "Object reference not set to an instance of an object."
At line:7 char:13
+ $psISE.CurrentPowerShellTab.Files.Add($_.FullName) > $nul ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NullReferenceException
Code:
New-Item readme.txt
psedit readme.txt
PsVersionTable:
Name Value
---- -----
PSVersion 5.0.10586.494
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.494
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Is this a known Bug? Any workaround?
Running the following works without an issue and opens a new tab in the ISE with the readme.txt:
New-Item Readme.txt -ItemType file
psedit Readme.txt
PSVersiontable:
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34209
BuildVersion 6.3.9600.17400
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
It seems like this is a PowerShell V5 bug since its working fine on PowerShell V4 (see the comment from Micky Balladelli). A workaround is to create the file using the Out-File cmdlet:
'' | Out-File readme.txt
psedit readme.txt