Powershell AzureAD module in Visual Studio Code - powershell

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.

Related

C++ debugger stopped working in VS Code with WMI error

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.

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

Package manager console fails to initialize

Whenever I try to open package manager console in Visual studio 2013 update 3 I get this error :
Cannot load Windows PowerShell snap-in Microsoft.PowerShell.Management because of the following error: > Could not load file or assembly
'file:///C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Microsoft.PowerShell.Commands.Management.dll' or
one of its dependencies. The system cannot find the file specified.
I have uninstalled/Re installed powershell. It didn't change anything.
any ideas?
Thank you.

psake msbuild error

I want to build my solution using psake and msbuild (v3.5) on an x64 pc. When I execute the script I get the following error:
error MSB4019: The imported project "C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
The message is correct, the file is missing but I have installed the 32 bit version of VS 2008 and therefor it is in the folder 'C:\Program Files (x86)...'
Is there any solution to tell msbuild to use the 32 bit version, not the 64 bit version?
You can specify what framework version is used for build. See $framework variable. In your case you need $framework = '3.5×86' at the beginning of the script.