Export-Counter missing from Powershell 7.1 - powershell

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

Related

Using both desktop Powershell 5.1 and Powershell Core 6.1

I was playing with PS.Core 6.1 in my VS Code - made it the default shell, opened PS debugging sessions with it, opened its console, etc ...
Now I am opening the regular desktop Powershell 5.1 and get this:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Users\me> get-module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 6.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script 2.0.0 PSReadline {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PS...
PS C:\Users\me> $env:PSModulePath -split ';'
C:\Users\me\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\6\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PS C:\Users\me>
This is not good. The PS.Core 6.1 installed its own Microsoft.PowerShell.Utility module which is incompatible with the desktop version.
The PSModulePath environment variable now lists the PS.Core 6 modules alongside the desktop modules, even with higher priority. Even though I do not see it in the Control Panel:
What a mess.
EDIT 1
The mess I observe is when I launch the shells from the shortcuts I have in the taskbar. The desktop one targets C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe and the core one - "C:\Program Files\PowerShell\6\pwsh.exe" -WorkingDirectory ~
EDIT 2
So, somehow, either installation of PS.Core or my experimentation with VS.Code has updated the environment of the parent explorer.exe process. I describe it here - How does PSModulePath environment property get composed?
Could be a bug in the installation of PS.Core, which means it is a one time thing. Or a bug in VS Code, which means I could screw it again.
I think the issue might be setting PowerShell Core 6.1 as your default shell.
If I launch PowerShell 5.1 (powershell.exe) from cmd prompt:
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\>powershell.exe
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.2879
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.2879
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\> Get-Module -ListAvailable Microsoft.PowerShell.Utility
Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Format-List, Format-Custom, Format-Table, Format-Wide...}
I get the expected module version.
If I launch PowerShell Core 6.1 (pwsh.exe) from cmd prompt:
C:\>pwsh.exe
PowerShell 6.1.3
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.3
PSEdition Core
GitCommitId 6.1.3
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS C:\> Get-Module -ListAvailable Microsoft.PowerShell.Utility
Directory: C:\program files\powershell\6\Modules
ModuleType Version Name PSEdition ExportedCommands
---------- ------- ---- --------- ----------------
Manifest 6.1.0.0 Microsoft.PowerShell.Utility Core {Format-List, Format-Custom, Format-Table, Forma...
I get the expected module version.
Now, if I launch PowerShell Core 6.1 from cmd prompt first, then launch PowerShell 5.1 from PowerShell Core 6.1 (i.e. as if you set your default shell to PowerShell Core 6.1):
C:\>pwsh.exe
PowerShell 6.1.3
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.3
PSEdition Core
GitCommitId 6.1.3
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS C:\> Get-Module -ListAvailable Microsoft.PowerShell.Utility
Directory: C:\program files\powershell\6\Modules
ModuleType Version Name PSEdition ExportedCommands
---------- ------- ---- --------- ----------------
Manifest 6.1.0.0 Microsoft.PowerShell.Utility Core {Format-List, Format-Custom, Format-Table, Forma...
PS C:\> powershell.exe
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.2879
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.2879
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\> Get-Module -ListAvailable Microsoft.PowerShell.Utility
Directory: C:\program files\powershell\6\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 6.1.0.0 Microsoft.PowerShell.Utility {Format-List, Format-Custom, Format-Table, Format-Wide...}
Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Format-List, Format-Custom, Format-Table, Format-Wide...}
I get both modules listed. And when I import the module:
PS C:\> Import-Module Microsoft.PowerShell.Utility
PS C:\> Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 6.1.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-ItemPropert...
Manifest 6.1.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl...
Manifest 6.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest 6.1.0.0 Microsoft.WSMan.Management {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, En...
Script 2.0.0 PSReadline {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PS...
The newer version (6.1) is loaded!
I agree that this is unexpected.
The good news is that we can access the old module as well, by specifying the -MaximumVersion:
PS C:\> Import-Module Microsoft.PowerShell.Utility -MaximumVersion 3.1.0.0
PS C:\> Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 6.1.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty...}
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script 2.0.0 PSReadline {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler...}

Export O365 users with licences, company, job title etc

i need to export users with several infos, like upn, licence used, company, city.
in each scripts available on internet get-user is used, but i have always the same error in powershell => get-user is not recognized...
i seached, import-module etc. but always the same error, somebody can help me ?
Context:
. windows 10 up to date
. Powershell run in admin
. PS C:\WINDOWS\system32> $psversiontable
Name Value
---- -----
PSVersion 5.1.17134.228
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.228
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1'
. PS C:\WINDOWS\system32> get-module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 2.0.1.16 AzureAD {Add-AzureADApplicationOwner, Add-AzureADDeviceRegisteredO...
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest 1.1.183.17 MSOnline {Add-MsolAdministrativeUnitMember, Add-MsolForeignGroupToR...
Binary 1.0.0.1 PackageManagement {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...
Script 1.0.0.1 PowerShellGet {Find-Command, Find-DscResource, Find-Module, Find-RoleCap...
Script 1.2 PSReadline {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PS...
Thx a lot, actually I was missing out the part about PS ExchangeOnline...
So the answer is just:
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession
and get-user is working :)
thx again

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

powershell remote import module error

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?