"Method Not Found" Error while using Get-PnPSiteTemplate - powershell

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

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.

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.

When running the NuGet pack command I get the error: 'AutoMapper' already has a dependency defined for 'NETStandard.Library'

I'm having an issue packaging my own nuget package, which includes AutoMapper 5.0.2. This is only producing an error within the Visual Studio Team Services (VSTeam) Build servers.
My project is using .NET 4.6.1
Any ideas on how to fix?
Here is the error:
2016-07-08T23:46:44.5801667Z C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.102.0\agent\worker\tools\NuGet.exe pack "C:\a\1\s\Project.csproj" -OutputDirectory "C:\a\1\s\Project\bin\release" -Properties Configuration=release -IncludeReferencedProjects
2016-07-08T23:46:45.0458195Z MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
2016-07-08T23:46:45.0468395Z Attempting to build package from 'Project.csproj'.
2016-07-08T23:46:45.1942694Z Packing files from 'C:\a\1\s\Project\bin\Release'.
2016-07-08T23:46:45.3942642Z ##[error]**'AutoMapper' already has a dependency defined for 'NETStandard.Library'.**
2016-07-08T23:46:45.4142626Z ##[error]System.Exception: Unexpected exit code 1 returned from tool NuGet.exe
2016-07-08T23:46:45.4152639Z ##[error] at Microsoft.TeamFoundation.DistributedTask.Task.Internal.PowerShell.InvokeToolCmdlet.ProcessRecord()
2016-07-08T23:46:45.4152639Z ##[error] at System.Management.Automation.CommandProcessor.ProcessRecord()
I also opened an issue on GitHub: https://github.com/AutoMapper/AutoMapper/issues/1499
You need to install new Nuget version for your visual studio version.
Get it from here
Nuget gallery
I was able to fix/workaround the issue by putting a PowerShell script in to download the latest NuGet. Then I pointed all of the NuGet tasks to this new nuget.exe. Pros: builds are working again, Cons: each build downloads NuGet again, causing unnecessary load on NuGet.org.
Here is my PowerShell:
$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = "$(build.sourcesdirectory)/nuget.exe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
Set-Alias nuget $targetNugetExe -Scope Global -Verbose
nuget
If someone using Team City you also need to use / install newer version of Nuget.

How do you get prerelease packages using powershell's Find-Package?

I am using Find-Package from Powershell 5.0. I need to query for pre-release packages. Is this possible?
I am aware that I can fall back to using nuget.exe list -prerelease if necessary.
It appears that the -AllVersions parameter will include them.
According to the nuget powershell documentation there is the -IncludePreRelease option:
Find-Package [Id] [-Source ] [-First ] [-Skip ] [-AllVersions] [-IncludePrerelease] [-ExactMatch]
Test:
PM> Find-Package Microsoft.AspNet.Identity.EntityFramework -Exact
Microsoft.AspNet.Identity.Entity... {2.2.1}
PM> Find-Package Microsoft.AspNet.Identity.EntityFramework -Exact -IncludePreRelease
Microsoft.AspNet.Identity.Entity... {3.0.0-rc1-final}
In Powershell you have to use the command "-AllowPrereleaseVersions" as documented here:
https://learn.microsoft.com/de-de/powershell/module/packagemanagement/find-package?view=powershell-7.1
Here is the hint on the differences betweeen PackageManager in Visual Studio and in Powershell:
https://learn.microsoft.com/de-de/nuget/reference/ps-reference/ps-ref-find-package
Version 3.0+; this topic describes the command within the Package Manager Console in Visual Studio on Windows. For the generic PowerShell Find-Package command, see the PowerShell PackageManagement reference.

Powershell with Sharepoint module - contradictory Error-Messages

I am trying to run the command "Get-SPWeb" from the SharePoint-Snapin for Powershell.
If I start PS normal (.net Ver.4), this is the error:
"Get-SPWeb: Microsoft SharePoint is not supported with Version 4.0.3.... of the Microsoft .Net Runtime."
Alright, so simply put -Version 2 behind the PS-Shortcut so it starts with Version 2? See what happens:
Error: Import-Module: [...] The Module 'SharePoint' requires a minimum version of '4.0' to execute
If I wouldn´t be mad as hell, I would just laugh about it.
Do you have any idea how to fix this issue?
This is the code by the way (important parts):
Add-PSSnapin Microsoft.SharePoint.PowerShell
$web = Get-SPWeb "http://myaddress.com/myreport"
Edit: Version-Info´s:
The Version-check provides the following:
PSVersion: 2.0
CLRVersion: 2.0. ....
Build: 6.1. ...
And with the normal PS:
PSVersion: 3.0
CLRVersion: 4.0
Build: 6.2
Also, I always start with the x64-version as administrator
Edit2: This is how the errors look: