C++ debugger stopped working in VS Code with WMI error - visual-studio-code

After a windows update and visual studio update to 1.75.1, I am unable to use the debugger C++ debugger with the following error:
Error: "pwsh -NoProfile -Command "Get-CimInstance Win32_Process | Select-Object Name,ProcessId,CommandLine | ConvertTo-JSON -Compress"" exited with code: "1".
Get-CimInstance: Invalid class
I see the same error when I try Get-CimInstance Win32_Process in PowerShell.
Tried reinstalling Windows PowerShell, searched for windows updates, switched to older version of Visual Studio Code and tried a clean install. Also tried to check WMI repository and it seems to be consistent.

Related

Powershell Publish-Module to Powershell Gallery fails after creating Nuget Package

I am trying to publish a new version of a Powershell module to the Powershell Gallery by using
Publish-Module -Name "Nuttercode-PRTG" -NuGetApiKey $apiKey -Verbose -RequiredVersion 1.4
The module .psm1 and .psd1 files can be found here.
After dotnet.exe created the package in {myUserDir}\AppData\Local\Temp\{random numbers}\Nuttercode-PRTG it reports:
VERBOSE: finished running C:\Program Files\dotnet\dotnet.exe with exit code 0
VERBOSE: Created Nuget Package
VERBOSE: Successfully created nuget package at
Write-Error: Failed to publish module 'Nuttercode-PRTG': 'Cannot bind argument to parameter 'NupkgPath' because it is an empty string.'.
Afterwards the temp-folder gets deleted. To me this sounds like an internal problem of Publish-Module or dotnet.exe, but I have no idea what is going on or if I am doing something very wrong myself. I also created a new api key just in case but it did not affect the result.
I am using Windows 10 20H2 (Build 19042.1469), Powershell 7.2.2, PowerShellGet 2.2.5, and dotnet.exe 6.0.201. I am able to replicate the problem on another computer using the same command and arguments using Windows 11 21H2 (Build 22000.556), Powershell 7.2.1, PowershellGet 2.2.5, and dotnet.exe 5.0.102.

"Method Not Found" Error while using Get-PnPSiteTemplate

I am trying to extract a site template of our site(based on the Communication site template) and restore it onto a new one. Whenever I run the below command, I am seeing an error as below
Get-PnPSiteTemplate -Out "C:\bin\ONNProd.xml" -Handlers PageContents,Lists,Pages,Theme,Fields -IncludeAllPages
Get-PnPSiteTemplate : Method not found: 'System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1<Boolean> Enumerator.MoveNextAsync()'.
Checking the version of PnP.Powershell using
Get-Module -Name PnP.PowerShell gives me as 1.7.0
Can some one help me what am i missing?
If you are using VSCode, this could be a bug with the Powershell extension as laid out here https://github.com/microsoft/vscode/issues/120026
I had the same issue, but when running the code from Powershell ISE, it is running now
Sounds like there is a bug with the most recent version (v1.7 and possible v1.6) of PNP.PowerShell for this function. I was able to successfully get this to run by installing the 1.5 version.
Run this to install:
Install-Module PNP.PowerShell -RequiredVersion 1.5.0 -AllowClobber

Powershell AzureAD module in Visual Studio Code

I am trying to debug a powershell script in Visual Studio Code but when I try to execute connect-azuread I get this error message:
connect-azuread : The 'connect-azuread' command was found in the module 'AzureAD', but the module could not be loaded. For more information, run 'Import-Module AzureAD'.
When I try to do Import-Module AzureAD, I get this other error:
Import-Module : The current processor architecture is: X86. The module 'C:\Program Files\WindowsPowerShell\Modules\azuread\2.0.2.4\azuread.psd1' requires the following architecture: Amd64.
If I switch the terminal from PowerShell Integrated to powershell it works, but when I start debugging my code it goes back to the integrated one.
Any ideas how to fix this?
In the meantime it looks like I managed to fix this by updating the settings to this:
{
"powershell.powerShellExePath":
"C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "terminal.integrated.shell.windows":
"C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "terminal.explorerKind": "external"
}
The original version was below and it looks like the SysWow64 version is 32 bit
{
"powershell.powerShellExePath": "C:\\WINDOWS\\SysWow64\\WindowsPowerShell\\v1.0\\powershell.exe",
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
}
Remove the (x86) from the powershell.powerShellDefaultVersion setting in VS settings.

Error using posdm.exe from POS for .NET on Windows 10

On Windows 10 running a simple posdm.exe from the command line gives the error:
C:\Program Files (x86)\Microsoft Point Of Service>posdm listsos
POSDM: Error executing WMI query: 'SELECT * from ServiceObject ', res=c0c02402: 0xC0C02402
I am unable to find anything online about this. I have installed Microsoft POS for .NET version 1.12. Is this a compatibility issue?
It looks like this is just the error you receive when you use this old version on Windows 10. Upgrading to version 1.14.1 fixed the error for me. Unfortunately I will still need to test things on 1.12 for compatibility checking so will have to use a virtual machine for that.

How to determine the version of nuget that is currently running from inside init.ps1

Inside a nuget init.ps1 https://docs.nuget.org/create/creating-and-publishing-a-package#automatically-running-powershell-scripts-during-package-installation-and-removal how do i get access to the current running version of nuget so as to do some switching logic on it?
Note I am running inside the Visual Studio context
You can get the NuGet assembly file version and the product version in init.ps1 using the following:
// Returns the file version (e.g. 2.8.60723.765) as a string
$package.GetType().Assembly.GetName().Version.ToString()
// Returns the product version (e.g. 2.8.7) as a string
[System.Diagnostics.FileVersionInfo]::GetVersionInfo($package.GetType().Assembly.Location).ProductVersion
Get-WmiObject -Class Win32_Product | Where-Object {$_.name -like "nuget"}
You will need to know the version of VS too, having 12 and 13 has 2 versions of VS.