Creating a SPO List With Columns

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.

 

 

Not a share point admin, but below link will help you.

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()

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 https://gallery.technet.microsoft.com/office/How-to-create-a-List-in-a-2ff75523
How to get items from a sharepoint online list using PowerShell

How to get items from a Sharepoint Online list using PowerShell? - Stack Overflow


Then just use the Format-Table cmdlet.

https://docs.microsoft.com/en-us/powershell/scripting/getting-started/cookbooks/using-format-commands-to-change-output-view?view=powershell-6

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 https://www.microsoft.com/en-us/download/details.aspx?id=35588
PowerShell Modules for Managing SharePoint Online https://blogs.technet.microsoft.com/dawiese/2017/02/15/powershell-modules-for-managing-sharepoint-online

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.

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.

https://www.youtube.com/results?search_query=beginning+powershell
https://www.youtube.com/results?search_query=shell+sharepoint+online+cmdlets
https://www.youtube.com/results?search_query=pnp+powershell+for+sharepoint+online+

https://powershell.org/category/books

PowerShell Survival Guide
https://social.technet.microsoft.com/wiki/contents/articles/183.windows-powershell-survival-guide.aspx

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.

Connect-Pn​POnline Module:sharepoint-pnpApplies to: SharePoint Server 2013, SharePoint Server 2016, SharePoint Online https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/connect-pnponline?view=sharepoint-ps

However, the docs further stat that…

PnP PowerShell overview 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. https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps

… and lists the cmdlets that are part of the module.

You ran this…

Get-Module SharePointPnPPowerShell* -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending

… 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.

https://channel9.msdn.com/blogs/OfficeDevPnP/Introduction-to-PnP-PowerShell-Cmdlets

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:

https://www.petri.com/using-patterns-practices-powershell-sharepoint

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.