Powershell with Sharepoint module - contradictory Error-Messages - powershell

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:

Related

Azure devops (TFS) on prem download .net core SKD fails with self signed certificate in certificate chain

I am using azure devops on prem (previously called TFS). And I have a problem with build agent. When the agent is trying to download the latest microsoft .net core SDK it fails with self signed certificate in certificate chain error.
Here is the full error:
Starting: Use version 6.0.x of nuget
==============================================================================
Task : Use .NET Core
Description : Acquires a specific version of the .NET Core SDK from the internet or the local cache and adds it to the PATH. Use this task to change the version of .NET Core used in subsequent tasks. Additionally provides proxy support.
Version : 2.184.0
Author : Microsoft Corporation
Help : https://aka.ms/AA4xgy0
==============================================================================
Tool to install: .NET Core sdk version 6.0.x.
Found version 6.0.401 in channel 6.0 for user specified version spec: 6.0.x
Version 6.0.401 was not found in cache.
Getting URL to download .NET Core sdk version: 6.0.401.
Detecting OS platform to find correct download package for the OS.
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "& 'C:\AzureDevops\agent\_work\_tasks\UseDotNet_b0ce7256-7898-45d3-9cb5-176b752bfea6\2.184.0\externals\get-os-platform.ps1'"
Primary:win-x64
Detected platform (Primary): win-x64
Downloading: https://download.visualstudio.microsoft.com/download/pr/aa0b6cf3-c5dc-40ff-8b2f-f2970ca7b9e3/5b4a9999ea41ca5897e01a3e0e1accad/dotnet-sdk-6.0.401-win-x64.zip
##[error]Failed while installing version: 6.0.401 at path: C:\AzureDevops\agent\_work\_tool/dotnet with error: Could not download installation package from this URL: https://download.visualstudio.microsoft.com/download/pr/aa0b6cf3-c5dc-40ff-8b2f-f2970ca7b9e3/5b4a9999ea41ca5897e01a3e0e1accad/dotnet-sdk-6.0.401-win-x64.zip Error: Error: self signed certificate in certificate chain
Finishing: Use version 6.0.x of nuget
I had a look on agent code on github and I think problem is in this method:
I coudn't dig deeper in the projec itself but I think it is using this azure-pipelines-tool-lib/tool
But I coudn't find anything that would help me there either.
Any suggestions or configurations to check?
My workaround so far is to download the sdk manually and place it into cache folder (agent_work_tool\dotnet\sdk) of the agent, but I would have to do that every time microsoft releases new major version.

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

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.

Nuget Package Manager Fails When Calling Get-WindowsOptionalFeature

I'm attempting to use PowerShell to install a Windows Feature (don't ask) as part of a project. In the PowerShell console I can run the command:
Get-WindowsOptionalFeature -Online -FeatureName "IIS-WebServerRole"
and it completes successfully.
When I then try to run this from the PM> prompt in Visual Studio 2015 (running as administrator) it then gives me the following error:
get-windowsoptionalfeature : An attempt was made to load a program with an incorrect format.
At line:1 char:1
+ get-windowsoptionalfeature -online -featurename "IIS-WebServerRole"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-WindowsOptionalFeature], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.GetWindowsOptionalFeatureCommand
Here is my current $PSVersionTable from wihtin Package Manager.
Name Value
---- -----
PSVersion 5.1.14393.206
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.206
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
I can successfully run get-help get-windowsoptionalfeature and it will show syntax for the command.
I also ran the command in a try catch block to get the exception, here is what it returned:
System.Runtime.InteropServices.COMException (0x8007000B): An attempt was made to load a program with an incorrect format.
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
What, if anything, can I do to fix not being able to use Get-WindowsOptionalFeature from the Package Manager console?
So, Here is the thing.. The package manager console is basically running as a 32 bit process and your OS appears to be 64. A similar error is here
Try executing the command from a 32 bit powershell (the one probably under %windir%\System32\WindowsPowerShell\v1.0), you will get the same error you got in visual studio. As user #Wendy mentioned the package manager is intented for working with your nuget packages and not as a powershell executor. I am curious to, why would you like to do it.
If, executing powershell commands from visual studio is your need, you can add powershell script to your solution and execute with some additional steps as mentioned here or just simply invoke it as a process as mentioned here
In the other hand, If you would like to do it as part of a nuget package, try writing your script logic in your install script as mentioned here
According to the introduce for Package Manager Console: https://nuget.codeplex.com/wikipage?title=Package%20Manager%20Console%20Command%20Reference%20(v1.3), the Package Manager Console lets you run PowerShell scripts from within Visual Studio and is the host for the PowerShell-based NuGet commands.
The Package Manager Console just provide the help documentation and descriptions for PowerShell command, so you could not run PowerShell command in Package Manager Console.