This topic contains 7 replies, has 3 voices, and was last updated by
October 10, 2018 at 3:15 pm #113680
I am a relative newbie to Powershell and I looking for basic code to create a SPO list. I am using SharePointPnPPowerShell. I also need to create columns for the list.
My list name is "Assigned Writers" with column names of "File", "Writer", "Due Date", and "Status". Any help is greatly appreciated.
October 10, 2018 at 6:30 pm #113738ParticipantPoints: 65Rank: Member
Not a share point admin, but below link will help you.
October 10, 2018 at 8:24 pm #113756
Thanks for the response. This looks like what I need. However, I am using PnP Powershell and so the Get-SPWeb is not a valid cmdlet. It throws an error "Not recognized as the name of a cmdlet, function, script file, or operable program".
How would the code need to be rewritten to replace "$web = Get-SPWeb -Identity $webUrl" to work with PnP Powershell cmdlets?
$weburl = "http://mysharepoint" $listname = "TestList" $a = "Text1" $b = "Text2" $c = "Text3" Add-PsSnapin Microsoft.SharePoint.PowerShell -erroraction silentlycontinue $web = Get-SPWeb -Identity $webUrl $list = $web.Lists[$listname] $newItem = $list.items.add() $newitem["Title"] = $a $newitem["Custom_Column1"] = $b $newitem["Custom_Column2"] = $c $newitem.update()
October 10, 2018 at 8:37 pm #113765
Just create the list and use the format-table cmdlet, or create a pscustomobject out of your fields and format as needed.
How to create a List in a SharePoint Online Site using PowerShell
How to get items from a sharepoint online list using PowerShell
Then just use the Format-Table cmdlet.
October 10, 2018 at 8:41 pm #113767
As for this...
Get-SPWeb is not a valid cmdlet. It throws an error "Not recognized as the name of a cmdlet, function, script file, or operable program".
For virtually anything dealing with MSOL and PS, you have to download and install the appropriate tools. You must install the SPO module to use the SPO cmdlets. You cannot use the on-prem SP cmdlets to connect to and work on SPO.
SharePoint Online Management Shell
PowerShell Modules for Managing SharePoint Online
October 10, 2018 at 9:21 pm #113774
Thx for the response. I have run this command and subsequently can execute PnP Powershell cmdlets.
Get-Module SharePointPnPPowerShell* -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending
But I am a newbie and as a result, I need more specific instructions on how to either:
1. Rewrite "$web = Get-SPWeb -Identity $webUrl" to use PnP cmdlets OR
2. Execute a command to install/load the correct module to be able to run "$web = Get-SPWeb -Identity $webUrl"
Thanks again for taking the time to provide recommendations.
October 11, 2018 at 12:13 am #113788
Well, I've never had a reason to use Pnp PowerShell for anything.
On-prem I use SP and in SPO, I use the SPO version.
Any needed cmdlet for a script must already be on your system or you have to manually install just as you had to do to leverage the PnP module. There is not magic way to auto do this. If the PnP module does not have the requisite cmdlets, then you need to move to a module that does.
You say you are new to PS, then it's really very important that you get some ramp up on it before you unnecessarily frustrate yourself running into blockers, logic errors or troubleshooting, as you are here. There are lots of beginner to advanced level, no cost training via the MS Viraul Academy, MS TechNet Virtual Labs, and YouTube, as well as a plethora of no cost eBooks on this very site and on MS TechNet.
PowerShell Survival Guide
Looking a that MS Docs papers on the PnP PowerShell topic, just like with the standard SPO module, you have to connect to SPO via PnP with to be able to use the PnP cmdlets.
SharePoint Server 2013, SharePoint Server 2016, SharePoint Online
However, the docs further stat that...
SharePoint Patterns and Practices (PnP) contains a library of PowerShell commands (PnP PowerShell) that allows you to perform complex provisioning and artifact management actions towards SharePoint. The commands use CSOM and can work against both SharePoint Online as SharePoint On-Premises.
… and lists the cmdlets that are part of the module.
You ran this...
… which should show you a result of the module is loaded or not.
What you have not run, is...
Get-Command -Name '*pnp*'
… to see the full command list that is in the module. Whether you did the above or just looked at the MS Docs site link above. You'll instantly see that the cmdlet you are after is not part of the module. In reading the docs, what you are trying to do is what the normal SP/SPO cmdlets are for, not the PnP module, since that is not it's mission.
The base SP/SPO cmdlets are all about management and administration. The PnP ones are a special Dev use case thing.
So, if that is your thing, then you need both the PnP and the standard SPO module on your machine for your script to work as designed.
See this article:
October 15, 2018 at 6:47 pm #114132
Thank you postanote for your detailed response. I got sidetracked on another critical project so my apologies for my slow reply.
I am running Windows 10 and I have the SPO Management Shell installed. I am performing these actions on various SPO sites where I am the site collection admin.
I ran the command
Get-Command -Name '*pnp*'
and can see there is no Get-SPWeb in the list from the PnP module. The Get-SPWeb command (see: https://docs.microsoft.com/en-us/powershell/module/sharepoint-server/get-spweb?view=sharepoint-ps) shows that it is from the SharePoint Server PowerShell module. However, I cannot find anything on how to install this on my Win 10 machine. Is it only available for servers only?
I also ran
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
and received this message: "WARNING: Version '16.0.8029.0' of module 'Microsoft.Online.SharePoint.PowerShell' is already installed".
I either must solve how to install this module so I can execute the Get-SPWeb cmdlet OR find alternate code that only uses PowerShellPnP. Any recommendations are appreciated and thanks again for your detailed responses.
You must be logged in to reply to this topic.