├── .gitattributes ├── .gitignore ├── Attributes ├── ValidateDirectoryExistsAndValidFileNameAttribute.cs ├── ValidateDirectoryExistsAttribute.cs └── ValidateFileExistsAttribute.cs ├── CmdletContext.cs ├── Cmdlets ├── BaseSPOCmdlet.cs ├── ConnectSPOSite.cs ├── ContentTypes │ ├── AddSPOContentType.cs │ ├── GetSPOContentType.cs │ ├── NewSPOContentType.cs │ └── RemoveSPOContentType.cs ├── DisconnectSPOSite.cs ├── EventReceivers │ └── GetSPOEventReceiver.cs ├── Features │ ├── DisableSPOFeature.cs │ ├── EnableSPOFeature.cs │ └── GetSPOFeature.cs ├── Fields │ ├── AddSPOField.cs │ └── NewSPOField.cs ├── InvokeRestMethod.cs ├── Lists │ ├── DownloadSPOFile.cs │ ├── GetSPOFile.cs │ ├── GetSPOFolder.cs │ ├── GetSPOList.cs │ ├── NewSPOFile.cs │ ├── NewSPOList.cs │ ├── NewSPOListFolder.cs │ ├── NewSPOListItem.cs │ ├── RemoveSPOList.cs │ └── SetSPOList.cs ├── Search │ ├── ExportSPOSearchConfiguration.cs │ └── ImportSPOSearchConfiguration.cs ├── Sites │ ├── GetSPOContextSite.cs │ ├── GetSPOWeb.cs │ ├── NewSPOWeb.cs │ ├── RemoveSPOWeb.cs │ ├── SetSPOWeb.cs │ └── SetSPOWebTheme.cs ├── Solutions │ ├── AddSPOSolution.cs │ ├── InstallSPOSolution.cs │ └── UninstallSPOSolution.cs ├── Taxonomy │ ├── ExportSPOTaxonomy.cs │ ├── ExportTermsHelper.cs │ ├── GetSPOTerm.cs │ ├── GetSPOTermGroup.cs │ ├── GetSPOTermSet.cs │ ├── GetSPOTermStore.cs │ ├── ImportSPOTaxonomy.cs │ ├── ImportTermsHelper.cs │ ├── NewSPOTermGroup.cs │ └── NewSPOTermSet.cs ├── WebParts │ ├── AddListViewWebPart.cs │ ├── AddWebPart.cs │ └── GetWebPart.cs └── WikiPages │ ├── NewSPOWikiPage.cs │ └── SetSPOWikiPageLayout.cs ├── Data ├── ContentTypes │ └── SPOContentType.cs ├── EventReceivers │ └── SPOEventReceiverDefinition.cs ├── Fields │ └── SPOField.cs ├── Lists │ ├── SPOFile.cs │ ├── SPOFolder.cs │ ├── SPOInformationRightsManagementSettings.cs │ ├── SPOList.cs │ ├── SPOListItem.cs │ ├── SPOView.cs │ └── SPOWikiPage.cs ├── Navigation │ ├── SPONavigation.cs │ ├── SPONavigationNode.cs │ └── SPONavigationNodeCollection.cs ├── Principals │ ├── SPOGroup.cs │ ├── SPOPrincipal.cs │ └── SPOUser.cs ├── SPOClientObject.cs ├── SPOClientObjectCollection.cs ├── Sites │ ├── SPOPropertyBag.cs │ ├── SPOSite.cs │ ├── SPOUserCustomAction.cs │ ├── SPOUserCustomActionCollection.cs │ └── SPOWeb.cs ├── Taxonomy │ ├── SPOTaxonomyBase.cs │ ├── SPOTaxonomyItem.cs │ ├── SPOTerm.cs │ ├── SPOTermGroup.cs │ ├── SPOTermLabel.cs │ ├── SPOTermSet.cs │ ├── SPOTermSetItem.cs │ └── SPOTermStore.cs └── WebParts │ ├── SPOWebPart.cs │ └── SPOWebPartDefinition.cs ├── EULA.rtf ├── Enums └── WikiPageLayout.cs ├── Exceptions └── FileExistsException.cs ├── GenerateHelp.ps1 ├── LICENSE.md ├── Lapointe.SharePointOnline.PowerShell.csproj ├── Lapointe.SharePointOnline.PowerShell.dll-help.xml ├── Lapointe.SharePointOnline.PowerShell.ps1xml ├── Lapointe.SharePointOnline.PowerShell.psd1 ├── Lapointe.SharePointOnline.PowerShell.sln ├── PipeBind ├── CmdletPipeBind.cs ├── CredentialPipeBind.cs ├── PropertiesPipeBind.cs ├── SPOContentTypePipeBind.cs ├── SPOFieldPipeBind.cs ├── SPOFilePipeBind.cs ├── SPOFolderPipeBind.cs ├── SPOGroupPipeBind.cs ├── SPOListPipeBind.cs ├── SPOTermGroupPipeBind.cs ├── SPOTermPipeBind.cs ├── SPOTermSetPipeBind.cs ├── SPOTermStorePipeBind.cs ├── SPOUserPipeBind.cs ├── SPOWebPipeBind.cs ├── UrlPipeBind.cs └── XmlDocumentPipeBind.cs ├── Properties └── AssemblyInfo.cs ├── README.md ├── ReferenceAssemblies ├── Lapointe.PowerShell.MamlGenerator.dll ├── Microsoft.Office.Client.Education.dll ├── Microsoft.Office.Client.Policy.dll ├── Microsoft.Office.Client.TranslationServices.dll ├── Microsoft.SharePoint.Client.DocumentManagement.dll ├── Microsoft.SharePoint.Client.Publishing.dll ├── Microsoft.SharePoint.Client.Runtime.dll ├── Microsoft.SharePoint.Client.Search.Applications.dll ├── Microsoft.SharePoint.Client.Search.dll ├── Microsoft.SharePoint.Client.Taxonomy.dll ├── Microsoft.SharePoint.Client.UserProfiles.dll ├── Microsoft.SharePoint.Client.WorkflowServices.dll └── Microsoft.SharePoint.Client.dll ├── SPOSiteContext.cs ├── SPOSiteHelper.cs ├── Utilities └── StreamHelper.cs ├── Validators ├── ValidateDirectoryExistsAndValidFileNameAttribute.cs ├── ValidateDirectoryExistsAttribute.cs └── ValidateFileExistsAttribute.cs ├── app.config └── install.wxs /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | 11 | [Dd]ebug/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | [Bb]in/ 16 | [Oo]bj/ 17 | 18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 19 | !packages/*/build/ 20 | 21 | # MSTest test Results 22 | [Tt]est[Rr]esult*/ 23 | [Bb]uild[Ll]og.* 24 | 25 | *_i.c 26 | *_p.c 27 | *.ilk 28 | *.meta 29 | *.obj 30 | *.pch 31 | *.pdb 32 | *.pgc 33 | *.pgd 34 | *.rsp 35 | *.sbr 36 | *.tlb 37 | *.tli 38 | *.tlh 39 | *.tmp 40 | *.tmp_proj 41 | *.log 42 | *.vspscc 43 | *.vssscc 44 | .builds 45 | *.pidb 46 | *.log 47 | *.scc 48 | 49 | # Visual C++ cache files 50 | ipch/ 51 | *.aps 52 | *.ncb 53 | *.opensdf 54 | *.sdf 55 | *.cachefile 56 | 57 | # Visual Studio profiler 58 | *.psess 59 | *.vsp 60 | *.vspx 61 | 62 | # Guidance Automation Toolkit 63 | *.gpState 64 | 65 | # ReSharper is a .NET coding add-in 66 | _ReSharper*/ 67 | *.[Rr]e[Ss]harper 68 | 69 | # TeamCity is a build add-in 70 | _TeamCity* 71 | 72 | # DotCover is a Code Coverage Tool 73 | *.dotCover 74 | 75 | # NCrunch 76 | *.ncrunch* 77 | .*crunch*.local.xml 78 | 79 | # Installshield output folder 80 | [Ee]xpress/ 81 | 82 | # DocProject is a documentation generator add-in 83 | DocProject/buildhelp/ 84 | DocProject/Help/*.HxT 85 | DocProject/Help/*.HxC 86 | DocProject/Help/*.hhc 87 | DocProject/Help/*.hhk 88 | DocProject/Help/*.hhp 89 | DocProject/Help/Html2 90 | DocProject/Help/html 91 | 92 | # Click-Once directory 93 | publish/ 94 | 95 | # Publish Web Output 96 | *.Publish.xml 97 | 98 | # NuGet Packages Directory 99 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 100 | #packages/ 101 | 102 | # Windows Azure Build Output 103 | csx 104 | *.build.csdef 105 | 106 | # Windows Store app package directory 107 | AppPackages/ 108 | 109 | # Others 110 | sql/ 111 | *.Cache 112 | ClientBin/ 113 | [Ss]tyle[Cc]op.* 114 | ~$* 115 | *~ 116 | *.dbmdl 117 | *.[Pp]ublish.xml 118 | *.pfx 119 | *.publishsettings 120 | 121 | # RIA/Silverlight projects 122 | Generated_Code/ 123 | 124 | # Backup & report files from converting an old project file to a newer 125 | # Visual Studio version. Backup files are not needed, because we have git ;-) 126 | _UpgradeReport_Files/ 127 | Backup*/ 128 | UpgradeLog*.XML 129 | UpgradeLog*.htm 130 | 131 | # SQL Server files 132 | App_Data/*.mdf 133 | App_Data/*.ldf 134 | 135 | 136 | #LightSwitch generated files 137 | GeneratedArtifacts/ 138 | _Pvt_Extensions/ 139 | ModelManifest.xml 140 | 141 | # ========================= 142 | # Windows detritus 143 | # ========================= 144 | 145 | # Windows image file caches 146 | Thumbs.db 147 | ehthumbs.db 148 | 149 | # Folder config file 150 | Desktop.ini 151 | 152 | # Recycle Bin used on file shares 153 | $RECYCLE.BIN/ 154 | 155 | # Mac desktop service store files 156 | .DS_Store 157 | -------------------------------------------------------------------------------- /Attributes/ValidateDirectoryExistsAndValidFileNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Management.Automation; 3 | using System.Management.Automation.Internal; 4 | 5 | namespace Lapointe.SharePointOnline.PowerShell.Attributes 6 | { 7 | 8 | public class ValidateDirectoryExistsAndValidFileNameAttribute : ValidateArgumentsAttribute 9 | { 10 | protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) 11 | { 12 | string str = arguments as string; 13 | if (string.IsNullOrEmpty(str)) 14 | { 15 | throw new PSArgumentNullException(); 16 | } 17 | 18 | FileInfo info = new FileInfo(str); 19 | if (info.Directory.Exists) 20 | { 21 | if (info.Name.EndsWith("\\") || info.Name.EndsWith("/")) 22 | { 23 | throw new PSArgumentException("Filename not specified"); 24 | } 25 | } 26 | else 27 | { 28 | throw new PSArgumentException("Directory not found"); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Attributes/ValidateDirectoryExistsAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Management.Automation; 3 | using System.Management.Automation.Internal; 4 | 5 | namespace Lapointe.SharePointOnline.PowerShell.Attributes 6 | { 7 | 8 | public class ValidateDirectoryExistsAttribute : ValidateArgumentsAttribute 9 | { 10 | protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) 11 | { 12 | string str = arguments as string; 13 | if (string.IsNullOrEmpty(str)) 14 | { 15 | throw new PSArgumentNullException(); 16 | } 17 | 18 | if (!Directory.Exists(str)) 19 | { 20 | throw new PSArgumentException("Directory not found"); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Attributes/ValidateFileExistsAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Management.Automation; 3 | using System.Management.Automation.Internal; 4 | 5 | namespace Lapointe.SharePointOnline.PowerShell.Attributes 6 | { 7 | 8 | public class ValidateFileExistsAttribute : ValidateArgumentsAttribute 9 | { 10 | protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) 11 | { 12 | string str = arguments as string; 13 | if (string.IsNullOrEmpty(str)) 14 | { 15 | throw new PSArgumentNullException(); 16 | } 17 | 18 | if (!File.Exists(str)) 19 | { 20 | throw new PSArgumentException("File not found"); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CmdletContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Management.Automation.Host; 7 | using System.Reflection; 8 | using System.Text; 9 | using Microsoft.SharePoint.Client; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell 12 | { 13 | public sealed class CmdletContext : ClientContext 14 | { 15 | private PSHost m_powerShellHost; 16 | private const string USER_AGENT_STRING_FORMAT = "SharePoint Online PowerShell by Gary Lapointe ({0})"; 17 | 18 | internal CmdletContext(string webFullUrl, PSHost host) : base(webFullUrl) 19 | { 20 | this.Host = host; 21 | } 22 | 23 | internal CmdletContext(Uri webFullUrl, PSHost host) : base(webFullUrl) 24 | { 25 | this.Host = host; 26 | } 27 | 28 | internal static string GetUserAgent() 29 | { 30 | return string.Format(CultureInfo.InvariantCulture, USER_AGENT_STRING_FORMAT, new object[] { ModuleVersion.FullBuildBase }); 31 | } 32 | 33 | internal PSHost Host 34 | { 35 | get 36 | { 37 | return this.m_powerShellHost; 38 | } 39 | private set 40 | { 41 | if (value == null) 42 | { 43 | throw new ArgumentNullException("Host"); 44 | } 45 | this.m_powerShellHost = value; 46 | } 47 | } 48 | 49 | private class ModuleVersion 50 | { 51 | static ModuleVersion() 52 | { 53 | FullBuildVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion; 54 | FullBuildBase = new Version(FullBuildVersion).ToString(3) + ".0"; 55 | } 56 | public static readonly string FullBuildVersion; 57 | public static readonly string FullBuildBase; 58 | } 59 | 60 | 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Cmdlets/BaseSPOCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Specialized; 4 | using System.Linq; 5 | using System.Linq.Expressions; 6 | using System.Management.Automation; 7 | using System.Text; 8 | using System.Threading; 9 | 10 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets 11 | { 12 | public class BaseSPOCmdlet : PSCmdlet 13 | { 14 | private CmdletContext _context; 15 | private HybridDictionary _fields; 16 | 17 | public BaseSPOCmdlet() 18 | { 19 | _fields = new HybridDictionary(); 20 | } 21 | 22 | protected CmdletContext Context 23 | { 24 | get 25 | { 26 | if (_context != null) 27 | { 28 | return _context; 29 | } 30 | if (SPOSiteContext.CurrentSiteContext == null) 31 | { 32 | throw new InvalidOperationException("No connection available. Use Connect-SPOSite before running this CmdLet."); 33 | } 34 | return SPOSiteContext.CurrentSiteContext.Context; 35 | } 36 | set 37 | { 38 | _context = value; 39 | } 40 | } 41 | 42 | protected T GetProp(string fieldName) where T : class 43 | { 44 | return (T)this.Fields[fieldName]; 45 | } 46 | 47 | 48 | protected S GetPropV(string fieldName) where S : struct 49 | { 50 | if (!this.Fields.Contains(fieldName)) 51 | { 52 | throw new InvalidCastException("uninitialized property cannot be unboxed."); 53 | } 54 | return (S)this.Fields[fieldName]; 55 | } 56 | 57 | 58 | protected SwitchParameter GetSwitch(string fieldName) 59 | { 60 | if (!this.Fields.Contains(fieldName)) 61 | { 62 | SwitchParameter parameter = new SwitchParameter(false); 63 | this.Fields[fieldName] = parameter; 64 | } 65 | return (SwitchParameter)this.Fields[fieldName]; 66 | } 67 | 68 | protected void SetProp(string fieldName, object value) 69 | { 70 | if (value != null) 71 | { 72 | if (value.GetType() == typeof(string)) 73 | { 74 | value = ((string)value).Trim(); 75 | } 76 | this.Fields[fieldName] = value; 77 | } 78 | else 79 | { 80 | this.Fields.Remove(fieldName); 81 | } 82 | } 83 | 84 | 85 | 86 | 87 | protected HybridDictionary Fields 88 | { 89 | get 90 | { 91 | return _fields; 92 | } 93 | } 94 | 95 | 96 | 97 | 98 | 99 | 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Cmdlets/ConnectSPOSite.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | 9 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets 10 | { 11 | [Cmdlet("Connect", "SPOSite", SupportsShouldProcess = false)] 12 | [CmdletGroup("General")] 13 | [CmdletDescription("Connects a SharePoint Online user to a SharePoint Online Site Collection. This cmdlet must be run before any other Site Collection scoped SharePoint Online cmdlets can run.", 14 | "The Connect-SPOSite cmdlet connects a SharePoint Online user to the specified SharePoint Online Site Collection.\r\n\r\nOnly a single SharePoint Online site connection is maintained from any single Windows PowerShell session. In other words, this is a per-site collection user connection. Running the Connect-SPOSite cmdlet twice implicitly disconnects the previous connection. The Windows PowerShell session will be set to serve the new SharePoint Online user and site collection specified. If you are connecting to an on-premises version of SharePoint and not SharePoint Online then use the -NetworkCredentials switch parameter to treat the provided credentials as network credentials.")] 15 | [RelatedCmdlets(typeof(DisconnectSPOSite))] 16 | [Example(Code = "PS C:\\> Connect-SPOSite -Url \"https://contoso.sharepoint.com/\" -Credential \"admin@contoso.com\"", 17 | Remarks = "This example connects to the Site Collection at https://contoso.sharepoint.com/.")] 18 | [Example(Code = "PS C:\\> $username = \"admin@contoso.sharepoint.com\"\r\n" + 19 | "PS C:\\> $password = \"password\"\r\n" + 20 | "PS C:\\> $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(ConvertTo-SecureString $password -AsPlainText -Force)\r\n" + 21 | "PS C:\\> Connect-SPOSite -Url \"http://contoso.sharepoint.com/\" -Credential $cred", 22 | Remarks = "This example connects to the Site Collection at https://contoso.sharepoint.com/ given a specific username and password.")] 23 | public class ConnectSPOSite : PSCmdlet 24 | { 25 | [ValidateNotNullOrEmpty, Parameter(Position = 0, ValueFromPipeline = true, Mandatory = true)] 26 | public UrlPipeBind Url { get; set; } 27 | 28 | [Parameter(Position = 1, ValueFromPipeline = true)] 29 | public CredentialPipeBind Credential { get; set; } 30 | 31 | [Parameter(Position = 2, HelpMessage = "If specified then the provided credentials must be network credentials and it is assumed that you are connecting to an on-premises version of SharePoint and not SharePoint Online.")] 32 | public SwitchParameter NetworkCredentials { get; set; } 33 | 34 | protected override void ProcessRecord() 35 | { 36 | base.ProcessRecord(); 37 | Uri url = this.Url.Read(); 38 | PSCredential credentials = (this.Credential != null) ? this.Credential.Read(base.Host) : CredentialPipeBind.PromptForCredentials(base.Host, string.Empty); 39 | if (credentials == null) 40 | { 41 | throw new InvalidOperationException("No credentials were provided for the site."); 42 | } 43 | DisconnectSPOSite.DisconnectCurrentSite(); 44 | SPOSiteContext.CurrentSiteContext = SPOSiteHelper.InstantiateSPOSiteContext(url, credentials, base.Host, NetworkCredentials); 45 | 46 | WriteObject(SPOSiteContext.CurrentSiteContext); 47 | } 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Cmdlets/ContentTypes/AddSPOContentType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Lapointe.SharePointOnline.PowerShell.Data; 9 | using Microsoft.SharePoint.Client; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 12 | using Lapointe.SharePointOnline.PowerShell.Data.ContentTypes; 13 | 14 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.ContentTypes 15 | { 16 | [Cmdlet("Add", "SPOContentType", SupportsShouldProcess = false)] 17 | [CmdletGroup("Content Types")] 18 | [CmdletDescription("Adds a new content type to an existing List.")] 19 | [RelatedCmdlets(typeof(ConnectSPOSite))] 20 | [Example(Code = "PS C:\\> Add-SPOContentType -Web \"/\" -List \"Documents\" -ContentType \"My Content Type\"", 21 | Remarks = "This example adds a content type with the name of My Content Type to the Documents list.")] 22 | public class AddSPOContentType : BaseSPOCmdlet 23 | { 24 | public AddSPOContentType() 25 | { 26 | } 27 | 28 | [ValidateNotNullOrEmpty, 29 | Parameter( 30 | Position = 0, 31 | ValueFromPipeline = true, 32 | Mandatory = true, 33 | HelpMessage = "Specifies the identity of the Site containing the List to create the new Content Type within.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 34 | public SPOWebPipeBind Web { get; set; } 35 | 36 | 37 | [ValidateNotNullOrEmpty, 38 | Parameter( 39 | Position = 1, 40 | ValueFromPipeline = true, 41 | Mandatory = true, 42 | HelpMessage = "Specifies the List to add the Content Type to.\r\n\r\nThe type must be a valid absolute URL, in the form http://contoso.sharepoint.com/site_name/lists/list_name, or an SPOList object, Microsoft.SharePoint.Client.List object, List title, or GUID representing the List ID.")] 43 | public SPOListPipeBind List { get; set; } 44 | 45 | 46 | [ValidateNotNullOrEmpty, 47 | Parameter( 48 | Position = 2, 49 | Mandatory = true, 50 | HelpMessage = "Sets a value that specifies the Content Type that the new Content Type will inherit from. The type must be a valid name, Content Type ID, Microsoft.SharePoint.Client.ContentType object or SPOContentType object.")] 51 | public SPOContentTypePipeBind ContentType { get; set; } 52 | 53 | 54 | protected override void ProcessRecord() 55 | { 56 | base.ProcessRecord(); 57 | var ctx = base.Context; 58 | Web web = ctx.Site.OpenWeb(Web.Read()); 59 | 60 | 61 | 62 | SPOContentType newContentType = null; 63 | SPOList list = List.Read(web, false); 64 | SPOContentType parentContentType = ContentType.Read(web); 65 | if (parentContentType == null) 66 | { 67 | throw new ArgumentException("Unable to locate the specified parent content type."); 68 | } 69 | SPOContentType existingContentType = SPOContentType.GetContentType(ctx, list.List.ContentTypes, parentContentType.Name); 70 | if (existingContentType != null) 71 | { 72 | WriteWarning("The content type \"" + parentContentType.Name + "\" already exists within the List."); 73 | WriteObject(existingContentType); 74 | return; 75 | } 76 | 77 | ContentType ct = list.List.ContentTypes.AddExistingContentType(parentContentType.ContentType); 78 | ctx.ExecuteQuery(); 79 | SPOContentType.LoadContentType(ctx, ct); 80 | newContentType = new SPOContentType(ct); 81 | 82 | WriteObject(newContentType); 83 | } 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Cmdlets/ContentTypes/GetSPOContentType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Microsoft.SharePoint.Client; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 10 | using Lapointe.SharePointOnline.PowerShell.Data.EventReceivers; 11 | using Lapointe.SharePointOnline.PowerShell.Data.ContentTypes; 12 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 13 | 14 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.ContentTypes 15 | { 16 | [Cmdlet("Get", "SPOContentType", SupportsShouldProcess = false)] 17 | [CmdletGroup("Content Types")] 18 | [CmdletDescription("Retrieves the Content Types for the Site or List.")] 19 | [RelatedCmdlets(typeof(ConnectSPOSite))] 20 | [Example(Code = "PS C:\\> Get-SPOContentType -Web \"/\"", 21 | Remarks = "Retrieves all the Content Types for the root Site of the current Site Collection.")] 22 | [Example(Code = "PS C:\\> Get-SPOContentType -Web \"/\" -Identity \"Document\"", 23 | Remarks = "Retrieves the Document Content Types from the root Site of the current Site Collection.")] 24 | public class GetSPOContentType : BaseSPOCmdlet 25 | { 26 | [ValidateNotNullOrEmpty, 27 | Parameter( 28 | ParameterSetName = "List", 29 | Position = 0, 30 | ValueFromPipeline = true, 31 | Mandatory = true, 32 | HelpMessage = "Specifies the identity of the Site containing the List whose Content Types will be retrieved.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.\r\n\r\nIf not specified then the current Site Collection's Event Receiver Definitions will be retrieved."), 33 | Parameter( 34 | ParameterSetName = "Web", 35 | Position = 0, 36 | ValueFromPipeline = true, 37 | Mandatory = true, 38 | HelpMessage = "Specifies the identity of the Site whose Content Types will be retrieved.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.\r\n\r\nIf not specified then the current Site Collection's Event Receiver Definitions will be retrieved.")] 39 | public SPOWebPipeBind Web { get; set; } 40 | 41 | [ValidateNotNullOrEmpty, 42 | Parameter( 43 | ParameterSetName = "List", 44 | Position = 1, 45 | ValueFromPipeline = true, 46 | Mandatory = true, 47 | HelpMessage = "Specifies the identity of the List whose Content Types will be retrieved.\r\n\r\nThe type must be a valid absolute URL, in the form http://contoso.sharepoint.com/site_name/lists/list_name, or an SPOList object, Microsoft.SharePoint.Client.List object, List title, or GUID representing the List ID.")] 48 | public SPOListPipeBind List { get; set; } 49 | 50 | [ValidateNotNullOrEmpty, 51 | Parameter( 52 | Position = 2, 53 | Mandatory = false, 54 | HelpMessage = "The name or ID of the Content Type to retrieve.")] 55 | public string Identity { get; set; } 56 | 57 | protected override void ProcessRecord() 58 | { 59 | base.ProcessRecord(); 60 | var ctx = base.Context; 61 | 62 | string surl = Web.Read(); 63 | Web web = ctx.Site.OpenWeb(surl); 64 | 65 | ContentTypeCollection contentTypes = null; 66 | if (ParameterSetName == "Web") 67 | { 68 | contentTypes = web.ContentTypes; 69 | } 70 | else if (ParameterSetName == "List") 71 | { 72 | SPOList list = List.Read(web, false); 73 | contentTypes = list.List.ContentTypes; 74 | } 75 | ctx.Load(contentTypes); 76 | ctx.ExecuteQuery(); 77 | 78 | foreach (ContentType ct in contentTypes) 79 | { 80 | if (string.IsNullOrEmpty(Identity) || ct.Name.ToLower() == Identity.ToLower() || ct.Id.StringValue.ToLower() == Identity.ToLower()) 81 | { 82 | SPOContentType.LoadContentType(ctx, ct); 83 | WriteObject(new SPOContentType(ct)); 84 | } 85 | } 86 | } 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Cmdlets/ContentTypes/RemoveSPOContentType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Lapointe.SharePointOnline.PowerShell.Data; 9 | using Microsoft.SharePoint.Client; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 12 | using Lapointe.SharePointOnline.PowerShell.Data.ContentTypes; 13 | 14 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.ContentTypes 15 | { 16 | [Cmdlet("Remove", "SPOContentType", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.High)] 17 | [CmdletGroup("Content Types")] 18 | [CmdletDescription("Adds a new content type to an existing List.")] 19 | [RelatedCmdlets(typeof(ConnectSPOSite))] 20 | [Example(Code = "PS C:\\> Remove-SPOContentType -Web \"/\" -List \"Documents\" -ContentType \"My Content Type\"", 21 | Remarks = "This example removes a content type with the name of My Content Type from the Documents list.")] 22 | public class RemoveSPOContentType : BaseSPOCmdlet 23 | { 24 | public RemoveSPOContentType() 25 | { 26 | } 27 | 28 | [ValidateNotNullOrEmpty, 29 | Parameter( 30 | Position = 0, 31 | ValueFromPipeline = true, 32 | Mandatory = true, 33 | HelpMessage = "Specifies the identity of the Site containing the Content Type or List containing the Content Type to remove the Content Type from.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 34 | public SPOWebPipeBind Web { get; set; } 35 | 36 | 37 | [ValidateNotNullOrEmpty, 38 | Parameter( 39 | Position = 1, 40 | ValueFromPipeline = true, 41 | Mandatory = false, 42 | HelpMessage = "Specifies the List to remove the Content Type from.\r\n\r\nThe type must be a valid absolute URL, in the form http://contoso.sharepoint.com/site_name/lists/list_name, or an SPOList object, Microsoft.SharePoint.Client.List object, List title, or GUID representing the List ID.")] 43 | public SPOListPipeBind List { get; set; } 44 | 45 | 46 | [ValidateNotNullOrEmpty, 47 | Parameter( 48 | Position = 2, 49 | Mandatory = true, 50 | HelpMessage = "Sets a value that specifies the Content Type to remove. The type must be a valid name, Content Type ID, Microsoft.SharePoint.Client.ContentType object or SPOContentType object.")] 51 | public SPOContentTypePipeBind ContentType { get; set; } 52 | 53 | 54 | protected override void ProcessRecord() 55 | { 56 | base.ProcessRecord(); 57 | var ctx = base.Context; 58 | Web web = ctx.Site.OpenWeb(Web.Read()); 59 | 60 | SPOContentType contentType = null; 61 | if (List == null) 62 | { 63 | contentType = ContentType.Read(web); 64 | } 65 | else 66 | { 67 | SPOList list = List.Read(web, false); 68 | contentType = ContentType.Read(list.List); 69 | } 70 | 71 | if (contentType == null) 72 | { 73 | throw new ArgumentException("Unable to locate the specified content type."); 74 | } 75 | 76 | if (base.ShouldProcess(contentType.Name, "Remove Content Type")) 77 | { 78 | contentType.Delete(); 79 | } 80 | } 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Cmdlets/DisconnectSPOSite.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | 9 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets 10 | { 11 | [Cmdlet("Disconnect", "SPOSite", SupportsShouldProcess = false)] 12 | [CmdletGroup("General")] 13 | [CmdletDescription("Disconnects from a SharePoint Online site.", 14 | "The Disconnect-SPOSite cmdlet explicitly disconnects a previously created SharePoint Online site connection.\r\n\r\nYou can disconnect the site by running the Disconnect-SPOSite cmdlet or by running the Connect-SPOSite cmdlet to initiate another connection. For more information, see Connect-SPOSite.\r\n\r\nEven after a connection is terminated, operations that were started before the connection is terminated will run to completion. In other words, long-running operations will not be terminated by running the Disconnect-SPOSite cmdlet or the Connect-SPOSite cmdlet.")] 15 | [RelatedCmdlets(typeof(ConnectSPOSite))] 16 | [Example(Code = "PS C:\\> Disconnect-SPOSite", 17 | Remarks = "This example explicitly disconnects a previously created SharePoint Online service connection.")] 18 | public class DisconnectSPOSite : PSCmdlet 19 | { 20 | internal static bool DisconnectCurrentSite() 21 | { 22 | if (SPOSiteContext.CurrentSiteContext != null) 23 | { 24 | if (SPOSiteContext.CurrentSiteContext.Context != null) 25 | SPOSiteContext.CurrentSiteContext.Context.Dispose(); 26 | 27 | SPOSiteContext.CurrentSiteContext = null; 28 | return true; 29 | } 30 | return false; 31 | } 32 | 33 | protected override void ProcessRecord() 34 | { 35 | if (!DisconnectCurrentSite()) 36 | { 37 | throw new InvalidOperationException("There is no service currently connected."); 38 | } 39 | } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Cmdlets/EventReceivers/GetSPOEventReceiver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Microsoft.SharePoint.Client; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 10 | using Lapointe.SharePointOnline.PowerShell.Data.EventReceivers; 11 | 12 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.EventReceivers 13 | { 14 | [Cmdlet("Get", "SPOEventReceiver", SupportsShouldProcess = false)] 15 | [CmdletGroup("Event Receivers")] 16 | [CmdletDescription("Retrieves the Event Receivers for the Site Collection or a specific Site.", 17 | "If the -Web parameter is not provided then the Site Collection scoped Event Receivers are returned; otherwise, the Site scoped Event Receivers for a given Site are returned.")] 18 | [RelatedCmdlets(typeof(ConnectSPOSite))] 19 | [Example(Code = "PS C:\\> Get-SPOEventReceiver", 20 | Remarks = "Retrieves all Site Collection scoped Event Receivers.")] 21 | [Example(Code = "PS C:\\> Get-SPOEventReceiver -Web \"/\"", 22 | Remarks = "Retrieves all Site scoped Event Receivers for the root Site.")] 23 | public class GetSPOEventReceiver : BaseSPOCmdlet 24 | { 25 | [ValidateNotNullOrEmpty, 26 | Parameter( 27 | Position = 0, 28 | ValueFromPipeline = true, 29 | Mandatory = false, 30 | HelpMessage = "Specifies the identity of the Site whose Event Receiver Definitions will be retrieved.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.\r\n\r\nIf not specified then the current Site Collection's Event Receiver Definitions will be retrieved.")] 31 | public SPOWebPipeBind Web { get; set; } 32 | 33 | protected override void ProcessRecord() 34 | { 35 | base.ProcessRecord(); 36 | var ctx = base.Context; 37 | 38 | if (Web == null) 39 | { 40 | var eventReceivers = ctx.Site.EventReceivers; 41 | ctx.Load(eventReceivers); 42 | ctx.ExecuteQuery(); 43 | foreach (EventReceiverDefinition eventReceiver in eventReceivers) 44 | WriteObject(new SPOEventReceiverDefinition(eventReceiver, ctx.Site.EventReceivers)); 45 | } 46 | else 47 | { 48 | string surl = Web.Read(); 49 | Web web = ctx.Site.OpenWeb(surl); 50 | var eventReceivers = web.EventReceivers; 51 | ctx.Load(eventReceivers); 52 | ctx.ExecuteQuery(); 53 | 54 | foreach (EventReceiverDefinition eventReceiver in eventReceivers) 55 | WriteObject(new SPOEventReceiverDefinition(eventReceiver, web.EventReceivers)); 56 | } 57 | } 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Cmdlets/Features/DisableSPOFeature.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Microsoft.SharePoint.Client; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Features 12 | { 13 | [Cmdlet("Disable", "SPOFeature", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.High)] 14 | [CmdletGroup("Features")] 15 | [CmdletDescription("Disables a Feature within the current Site Collection or a specific Site.", 16 | "If the -Web parameter is not provided then a Site Collection scoped Feature will be disabled; otherwise, a Site scoped Feature for a given Site will be disabled.")] 17 | [RelatedCmdlets(typeof(ConnectSPOSite), typeof(EnableSPOFeature))] 18 | [Example(Code = "PS C:\\> Disable-SPOFeature -Identity \"{7AF6EA6F-2079-4310-B964-210A87F0D5A1}\"", 19 | Remarks = "Disables a Site Collection scoped Feature.")] 20 | [Example(Code = "PS C:\\> Disable-SPOFeature -Web \"/\" -Identity \"{7AF6EA6F-2079-4310-B964-210A87F0D5A1}\"", 21 | Remarks = "Disables a Site scoped Feature on the root Site.")] 22 | public class DisableSPOFeature : BaseSPOCmdlet 23 | { 24 | [ValidateNotNullOrEmpty, 25 | Parameter( 26 | Position = 0, 27 | ValueFromPipeline = true, 28 | Mandatory = false, 29 | HelpMessage = "Specifies the identity of the Site where the specified Feature will be deactivated.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 30 | public SPOWebPipeBind Web { get; set; } 31 | 32 | [ValidateNotNullOrEmpty, 33 | Parameter( 34 | Position = 1, 35 | ValueFromPipeline = true, 36 | Mandatory = true)] 37 | public Guid Identity { get; set; } 38 | 39 | [Parameter(Position = 2, Mandatory = false)] 40 | public SwitchParameter Force { get; set; } 41 | 42 | protected override void ProcessRecord() 43 | { 44 | base.ProcessRecord(); 45 | var ctx = base.Context; 46 | 47 | if (!base.ShouldProcess(Identity.ToString(), "Remove Content Type.")) 48 | return; 49 | 50 | if (Web == null) 51 | { 52 | var features = ctx.Site.Features; 53 | ctx.Load(features); 54 | ctx.ExecuteQuery(); 55 | features.Remove(Identity, Force); 56 | ctx.ExecuteQuery(); 57 | } 58 | else 59 | { 60 | string surl = Web.Read(); 61 | Web web = ctx.Site.OpenWeb(surl); 62 | var features = web.Features; 63 | ctx.Load(features); 64 | ctx.ExecuteQuery(); 65 | features.Remove(Identity, Force); 66 | ctx.ExecuteQuery(); 67 | } 68 | } 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Cmdlets/Features/EnableSPOFeature.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Microsoft.SharePoint.Client; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Features 12 | { 13 | [Cmdlet("Enable", "SPOFeature", SupportsShouldProcess = false)] 14 | [CmdletGroup("Features")] 15 | [CmdletDescription("Enables a Feature within the current Site Collection or a specific Site.", 16 | "If the -Web parameter is not provided then a Site Collection scoped Feature will be enabled; otherwise, a Site scoped Feature for a given Site will be enabled.")] 17 | [RelatedCmdlets(typeof(ConnectSPOSite), typeof(DisableSPOFeature))] 18 | [Example(Code = "PS C:\\> Enable-SPOFeature -Identity \"{7AF6EA6F-2079-4310-B964-210A87F0D5A1}\"", 19 | Remarks = "Enables a Site Collection scoped Feature.")] 20 | [Example(Code = "PS C:\\> Enable-SPOFeature -Web \"/\" -Identity \"{7AF6EA6F-2079-4310-B964-210A87F0D5A1}\"", 21 | Remarks = "Enables a Site scoped Feature on the root Site.")] 22 | public class EnableSPOFeature : BaseSPOCmdlet 23 | { 24 | [ValidateNotNullOrEmpty, 25 | Parameter( 26 | Position = 0, 27 | ValueFromPipeline = true, 28 | Mandatory = false, 29 | HelpMessage = "Specifies the identity of the Site where the specified Feature will be activated.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 30 | public SPOWebPipeBind Web { get; set; } 31 | 32 | [ValidateNotNullOrEmpty, 33 | Parameter( 34 | Position = 1, 35 | ValueFromPipeline = true, 36 | Mandatory = true)] 37 | public Guid Identity { get; set; } 38 | 39 | [Parameter(Position = 2, Mandatory = false)] 40 | public SwitchParameter Force { get; set; } 41 | 42 | protected override void ProcessRecord() 43 | { 44 | base.ProcessRecord(); 45 | var ctx = base.Context; 46 | 47 | if (Web == null) 48 | { 49 | var features = ctx.Site.Features; 50 | ctx.Load(features); 51 | ctx.ExecuteQuery(); 52 | features.Add(Identity, Force, FeatureDefinitionScope.None); 53 | ctx.ExecuteQuery(); 54 | } 55 | else 56 | { 57 | string surl = Web.Read(); 58 | Web web = ctx.Site.OpenWeb(surl); 59 | var features = web.Features; 60 | ctx.Load(features); 61 | ctx.ExecuteQuery(); 62 | features.Add(Identity, Force, FeatureDefinitionScope.None); 63 | ctx.ExecuteQuery(); 64 | } 65 | } 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Cmdlets/Features/GetSPOFeature.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Microsoft.SharePoint.Client; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Features 12 | { 13 | [Cmdlet("Get", "SPOFeature", SupportsShouldProcess = false)] 14 | [CmdletGroup("Features")] 15 | [CmdletDescription("Retrieves the Feature definition IDs for the Site Collection or a specific Site.", 16 | "If the -Web parameter is not provided then the Site Collection scoped Feature definition IDs are returned; otherwise, the Site scoped Feature definition IDs for a given Site are returned.")] 17 | [RelatedCmdlets(typeof(ConnectSPOSite))] 18 | [Example(Code = "PS C:\\> Get-SPOFeature", 19 | Remarks = "Retrieves all Site Collection scoped Feature definition IDs.")] 20 | [Example(Code = "PS C:\\> Get-SPOFeature -Web \"/\"", 21 | Remarks = "Retrieves all Site scoped Feature definition IDs for the root Site.")] 22 | public class GetSPOFeature : BaseSPOCmdlet 23 | { 24 | [ValidateNotNullOrEmpty, 25 | Parameter( 26 | Position = 0, 27 | ValueFromPipeline = true, 28 | Mandatory = false, 29 | HelpMessage = "Specifies the identity of the Site whose site-scoped Features will be retrieved.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 30 | public SPOWebPipeBind Web { get; set; } 31 | 32 | 33 | [ValidateNotNullOrEmpty, 34 | Parameter( 35 | Position = 1, 36 | ValueFromPipeline = true, 37 | Mandatory = false)] 38 | public Guid Identity { get; set; } 39 | 40 | protected override void ProcessRecord() 41 | { 42 | base.ProcessRecord(); 43 | var ctx = base.Context; 44 | 45 | if (Web == null) 46 | { 47 | var features = ctx.Site.Features; 48 | ctx.Load(features); 49 | ctx.ExecuteQuery(); 50 | foreach (Feature feature in features) 51 | { 52 | if (Identity == null || Identity == Guid.Empty || Identity == feature.DefinitionId) 53 | WriteObject(feature.DefinitionId); 54 | } 55 | } 56 | else 57 | { 58 | string surl = Web.Read(); 59 | Web web = ctx.Site.OpenWeb(surl); 60 | var features = web.Features; 61 | ctx.Load(features); 62 | ctx.ExecuteQuery(); 63 | 64 | foreach (Feature feature in features) 65 | { 66 | if (Identity == null || Identity == Guid.Empty || Identity == feature.DefinitionId) 67 | WriteObject(feature.DefinitionId); 68 | } 69 | } 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Cmdlets/Fields/AddSPOField.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Lapointe.SharePointOnline.PowerShell.Data; 9 | using Microsoft.SharePoint.Client; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 12 | using Lapointe.SharePointOnline.PowerShell.Data.ContentTypes; 13 | using System.Xml; 14 | using Lapointe.SharePointOnline.PowerShell.Data.Fields; 15 | 16 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Fields 17 | { 18 | [Cmdlet("Add", "SPOField", SupportsShouldProcess = false)] 19 | [CmdletGroup("Fields")] 20 | [CmdletDescription("Adds an existing Field to a List.")] 21 | [RelatedCmdlets(typeof(ConnectSPOSite))] 22 | [Example(Code = "PS C:\\> Add-SPOField -Web \"/\" -List \"Documents\" -Identity \"My Field\" ", 23 | Remarks = "This example adds the field \"My Field\" to the Documents library.")] 24 | public class AddSPOField : BaseSPOCmdlet 25 | { 26 | public AddSPOField() 27 | { 28 | } 29 | 30 | [ValidateNotNullOrEmpty] 31 | [Parameter( 32 | Position = 0, 33 | ValueFromPipeline = true, 34 | Mandatory = true, 35 | HelpMessage = "Specifies the identity of the Site containing the List to create the new Content Type within.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 36 | public SPOWebPipeBind Web { get; set; } 37 | 38 | 39 | [ValidateNotNullOrEmpty] 40 | [Parameter( 41 | Position = 1, 42 | ValueFromPipeline = true, 43 | Mandatory = true, 44 | HelpMessage = "Specifies the List to add the Content Type to.\r\n\r\nThe type must be a valid absolute URL, in the form http://contoso.sharepoint.com/site_name/lists/list_name, or an SPOList object, Microsoft.SharePoint.Client.List object, List title, or GUID representing the List ID.")] 45 | public SPOListPipeBind List { get; set; } 46 | 47 | [ValidateNotNullOrEmpty] 48 | [Alias("Name", "Title"), 49 | Parameter( 50 | ParameterSetName = "List_ExistingField", 51 | Position = 2, 52 | Mandatory = true, 53 | HelpMessage = "Specifies the existing field to add to the list. The type must be a valid GUID, internal field name, or field title.")] 54 | public SPOFieldPipeBind Identity { get; set; } 55 | 56 | 57 | protected override void ProcessRecord() 58 | { 59 | base.ProcessRecord(); 60 | var ctx = base.Context; 61 | Web web = ctx.Site.OpenWeb(Web.Read()); 62 | 63 | SPOField fieldToAdd = Identity.Read(web); 64 | if (fieldToAdd == null) 65 | { 66 | WriteError(new ErrorRecord(new ArgumentOutOfRangeException("The specified field could not be found! The field was not added to the list."), null, ErrorCategory.InvalidData, Identity)); 67 | return; 68 | } 69 | SPOList list = List.Read(web, false); 70 | SPOField existingField = SPOField.GetField(ctx, list.List.Fields, fieldToAdd.InternalName); 71 | if (existingField != null) 72 | { 73 | WriteWarning("The specified field already exists within the list."); 74 | WriteObject(existingField); 75 | return; 76 | } 77 | Field field = list.List.Fields.Add(fieldToAdd.Field); 78 | ctx.Load(field); 79 | ctx.ExecuteQuery(); 80 | WriteObject(new SPOField(field)); 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Cmdlets/Lists/GetSPOFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Microsoft.SharePoint.Client; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Lists 12 | { 13 | [Cmdlet("Get", "SPOFile", SupportsShouldProcess = false)] 14 | [CmdletGroup("Lists")] 15 | [CmdletDescription("Retrieves a specific File from a given Site.", 16 | "Retrieve a specific SPOFile object from a Site given the server relative URL to the file. The Site provided by the -Web parameter must correspond to the Site where the file is located or else an argument out of range exception will be thrown.")] 17 | [RelatedCmdlets(typeof(ConnectSPOSite))] 18 | [Example(Code = "PS C:\\> Get-SPOFile -Web \"/\" -Url \"/Shared Documents/MyFile.docx\"", 19 | Remarks = "Retrieves the file MyFile.docx from the Documents library within the root Site of the current Site Collection.")] 20 | public class GetSPOFile : BaseSPOCmdlet 21 | { 22 | [ValidateNotNullOrEmpty, 23 | Parameter( 24 | Position = 0, 25 | ValueFromPipeline = true, 26 | Mandatory = true, 27 | HelpMessage = "Specifies the identity of the Site containing the File to retrieve.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 28 | public SPOWebPipeBind Web { get; set; } 29 | 30 | [ValidateNotNullOrEmpty, 31 | Alias("Identity", "File"), 32 | Parameter( 33 | Position = 1, 34 | Mandatory = true, 35 | HelpMessage = "The server relative URL to the file to retrieve.")] 36 | public string Url { get; set; } 37 | 38 | protected override void ProcessRecord() 39 | { 40 | base.ProcessRecord(); 41 | var ctx = base.Context; 42 | 43 | SPOWeb web = new SPOWeb(ctx.Site.OpenWeb(Web.Read())); 44 | WriteObject(web.GetFileByServerRelativeUrl(Url)); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Cmdlets/Lists/GetSPOFolder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Microsoft.SharePoint.Client; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Lists 12 | { 13 | [Cmdlet("Get", "SPOFolder", SupportsShouldProcess = false)] 14 | [CmdletGroup("Lists")] 15 | [CmdletDescription("Retrieves a specific Folder from a given Site.", 16 | "Retrieve a specific SPOFolder object from a Site given the server relative URL to the folder. The Site provided by the -Web parameter must correspond to the Site where the folder is located or else an argument out of range exception will be thrown.")] 17 | [RelatedCmdlets(typeof(ConnectSPOSite))] 18 | [Example(Code = "PS C:\\> Get-SPOFolder -Web \"/\" -Url \"/Shared Documents/My Folder\"", 19 | Remarks = "Retrieves the folder \"My Folder\" from the Documents library within the root Site of the current Site Collection.")] 20 | public class GetSPOFolder : BaseSPOCmdlet 21 | { 22 | [ValidateNotNullOrEmpty, 23 | Parameter( 24 | Position = 0, 25 | ValueFromPipeline = true, 26 | Mandatory = true, 27 | HelpMessage = "Specifies the identity of the Site containing the File to retrieve.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 28 | public SPOWebPipeBind Web { get; set; } 29 | 30 | [ValidateNotNullOrEmpty, 31 | Alias("Identity", "Folder"), 32 | Parameter( 33 | Position = 1, 34 | Mandatory = true, 35 | HelpMessage = "The server relative URL to the folder to retrieve.")] 36 | public string Url { get; set; } 37 | 38 | protected override void ProcessRecord() 39 | { 40 | base.ProcessRecord(); 41 | var ctx = base.Context; 42 | 43 | SPOWeb web = new SPOWeb(ctx.Site.OpenWeb(Web.Read())); 44 | WriteObject(web.GetFolderByServerRelativeUrl(Url)); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Cmdlets/Lists/GetSPOList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Microsoft.SharePoint.Client; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 10 | using Lapointe.SharePointOnline.PowerShell.Data.EventReceivers; 11 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 12 | 13 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Lists 14 | { 15 | [Cmdlet("Get", "SPOList", SupportsShouldProcess = false)] 16 | [CmdletGroup("Lists")] 17 | [CmdletDescription("Retrieves the collection of lists or a specific list.", 18 | "If the -List parameter is not provided then all the lists the given Site are returned; otherwise, a single list will be returned matching the identifier provided.")] 19 | [RelatedCmdlets(typeof(ConnectSPOSite))] 20 | [Example(Code = "PS C:\\> Get-SPOList -Web \"/\"", 21 | Remarks = "Retrieves all lists for the root Site.")] 22 | [Example(Code = "PS C:\\> Get-SPOList -Web \"/\" -Identity \"Shared Documents\"", 23 | Remarks = "Retrieves a single list for the given Site.")] 24 | public class GetSPOList : BaseSPOCmdlet 25 | { 26 | [ValidateNotNullOrEmpty, 27 | Parameter( 28 | Position = 0, 29 | ValueFromPipeline = true, 30 | Mandatory = true, 31 | HelpMessage = "Specifies the identity of the Site containing the List to retrieve.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 32 | public SPOWebPipeBind Web { get; set; } 33 | 34 | [ValidateNotNullOrEmpty, 35 | Parameter( 36 | Position = 1, 37 | ValueFromPipeline = true, 38 | Mandatory = false, 39 | HelpMessage = "Specifies the identity of the List to retrieve.\r\n\r\nThe type must be a valid absolute URL, in the form http://contoso.sharepoint.com/site_name/lists/list_name, or an SPOList object, Microsoft.SharePoint.Client.List object, List title, or GUID representing the List ID.")] 40 | public SPOListPipeBind Identity { get; set; } 41 | 42 | [Parameter( 43 | Position = 2, 44 | ValueFromPipeline = false, 45 | Mandatory = false, 46 | HelpMessage = "Retrieve additional details useful for examining a single object.")] 47 | public SwitchParameter Detail { get; set; } 48 | 49 | protected override void ProcessRecord() 50 | { 51 | base.ProcessRecord(); 52 | var ctx = base.Context; 53 | 54 | Web web = ctx.Site.OpenWeb(Web.Read()); 55 | 56 | if (Identity != null) 57 | { 58 | SPOList list = Identity.Read(web, Detail); 59 | WriteObject(list); 60 | return; 61 | } 62 | var lists = web.Lists; 63 | ctx.Load(web); 64 | ctx.Load(lists); 65 | ctx.ExecuteQuery(); 66 | 67 | 68 | foreach (var list in lists) 69 | { 70 | if (Identity == null) 71 | { 72 | SPOList.LoadList(ctx, list, Detail); 73 | WriteObject(new SPOList(list)); 74 | continue; 75 | } 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Cmdlets/Lists/NewSPOFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.Attributes; 8 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 9 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Lists 12 | { 13 | [Cmdlet("New", "SPOFile", SupportsShouldProcess = false, DefaultParameterSetName = "List")] 14 | [CmdletGroup("Lists")] 15 | [CmdletDescription("Creates a new list file within an existing List.")] 16 | [RelatedCmdlets(typeof(ConnectSPOSite), typeof(GetSPOList))] 17 | [Example(Code = "PS C:\\> New-SPOFile -Web \"/\" -List \"My List\" -File \"c:\\myfile.txt\" -FieldValues @{\"Title\"=\"My new file\"}", 18 | Remarks = "This example creates a new file within the List My List under the root Site of the current Site Collection.")] 19 | public class NewSPOFile : BaseSPOCmdlet 20 | { 21 | [ValidateNotNullOrEmpty, 22 | Parameter( 23 | Position = 0, 24 | ValueFromPipeline = true, 25 | Mandatory = true, 26 | HelpMessage = "Specifies the identity of the Site containing the List to add the file to.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 27 | public SPOWebPipeBind Web { get; set; } 28 | 29 | [ValidateNotNullOrEmpty, 30 | Parameter( 31 | ParameterSetName = "List", 32 | Position = 1, 33 | ValueFromPipeline = true, 34 | Mandatory = false, 35 | HelpMessage = "Specifies the List to add the file to.\r\n\r\nThe type must be a valid absolute URL, in the form http://contoso.sharepoint.com/site_name/lists/list_name, or an SPOList object, Microsoft.SharePoint.Client.List object, List title, or GUID representing the List ID.")] 36 | public SPOListPipeBind List { get; set; } 37 | 38 | [ValidateNotNullOrEmpty, 39 | Parameter( 40 | ParameterSetName = "Folder", 41 | Position = 2, 42 | ValueFromPipeline = true, 43 | Mandatory = false, 44 | HelpMessage = "Specifies the Folder to add the file to.\r\n\r\nThe type must be a valid SPOFolder object.")] 45 | public SPOFolder Folder { get; set; } 46 | 47 | [ValidateNotNullOrEmpty, 48 | ValidateFileExists, 49 | Parameter( 50 | Position = 3, 51 | Mandatory = true, 52 | HelpMessage = "Specify the path to the file to add to the list.")] 53 | public string File { get; set; } 54 | 55 | [Parameter(Position = 4, HelpMessage = "Overwrite an existing file if present.")] 56 | public SwitchParameter Overwrite { get; set; } 57 | 58 | [Parameter( 59 | Position = 5, 60 | Mandatory = false, 61 | HelpMessage = "The collection of field values to set where the key is the internal field name. The type must be a hash table where each key represents the name of a field whose value should be set to the corresponding key value (e.g., @{\"Field1\"=\"Value1\";\"Field2\"=\"Value2\"}). Alternatively, provide the path to a file with XML property settings (Value1Value2).")] 62 | public PropertiesPipeBind FieldValues { get; set; } 63 | 64 | protected override void ProcessRecord() 65 | { 66 | base.ProcessRecord(); 67 | var ctx = base.Context; 68 | 69 | Dictionary fieldValues = null; 70 | if (FieldValues != null) 71 | fieldValues = FieldValues.Read(); 72 | 73 | byte[] content = System.IO.File.ReadAllBytes(File); 74 | System.IO.FileInfo file = new System.IO.FileInfo(File); 75 | string leafName = file.Name; 76 | 77 | if (ParameterSetName == "List") 78 | { 79 | var web = ctx.Site.OpenWeb(Web.Read()); 80 | SPOList list = List.Read(web, true); 81 | WriteObject(list.AddFile(content, Overwrite, leafName, fieldValues)); 82 | } 83 | else 84 | { 85 | WriteObject(Folder.AddFile(content, Overwrite, leafName, fieldValues)); 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Cmdlets/Lists/NewSPOListFolder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Microsoft.SharePoint.Client; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 11 | 12 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Lists 13 | { 14 | [Cmdlet("New", "SPOListFolder", SupportsShouldProcess = false)] 15 | [CmdletGroup("Lists")] 16 | [CmdletDescription("Creates a Folder in a list or library.", 17 | "Creates a folder in the specified list. The Site provided by the -Web parameter must correspond to the Site where the folder and List is located or else an argument out of range exception will be thrown.")] 18 | [RelatedCmdlets(typeof(ConnectSPOSite))] 19 | [Example(Code = "PS C:\\> New-SPOListFolder -Web \"/\" -List \"Documents\" -ListRelativeUrlFolderPath \"My Top Level Folder/My Sub-Folder\"", 20 | Remarks = "Creates the folders \"My Top Level Folder/My Sub-Folder\" in the Documents library within the root Site of the current Site Collection.")] 21 | public class NewSPOListFolder : BaseSPOCmdlet 22 | { 23 | [ValidateNotNullOrEmpty, 24 | Parameter( 25 | Position = 0, 26 | ValueFromPipeline = true, 27 | Mandatory = true, 28 | HelpMessage = "Specifies the identity of the Site containing the List to add the item to.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 29 | public SPOWebPipeBind Web { get; set; } 30 | 31 | [ValidateNotNullOrEmpty, 32 | Parameter( 33 | Position = 1, 34 | ValueFromPipeline = true, 35 | Mandatory = false, 36 | HelpMessage = "Specifies the List to add the item to.\r\n\r\nThe type must be a valid absolute URL, in the form http://contoso.sharepoint.com/site_name/lists/list_name, or an SPOList object, Microsoft.SharePoint.Client.List object, List title, or GUID representing the List ID.")] 37 | public SPOListPipeBind List { get; set; } 38 | 39 | [Parameter( 40 | Position = 2, 41 | Mandatory = true, 42 | HelpMessage = "Create the item within a subfolder inside the list. Only include the path relative to the root of the list.")] 43 | public string ListRelativeUrlFolderPath { get; set; } 44 | protected override void ProcessRecord() 45 | { 46 | base.ProcessRecord(); 47 | var ctx = base.Context; 48 | 49 | var web = ctx.Site.OpenWeb(Web.Read()); 50 | SPOList list = List.Read(web, true); 51 | WriteObject(list.GetFolder(ListRelativeUrlFolderPath, true, true)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Cmdlets/Lists/NewSPOListItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 8 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 9 | 10 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Lists 11 | { 12 | [Cmdlet("New", "SPOListItem", SupportsShouldProcess = false)] 13 | [CmdletGroup("Lists")] 14 | [CmdletDescription("Creates a new list item within an existing List.")] 15 | [RelatedCmdlets(typeof(ConnectSPOSite), typeof(GetSPOList))] 16 | [Example(Code = "PS C:\\> New-SPOListItem -Web \"/\" -List \"My List\" -FieldValues @{\"Title\"=\"My new list item\"}", 17 | Remarks = "This example creates a new list item within the List My List under the root Site of the current Site Collection.")] 18 | public class NewSPOListItem : BaseSPOCmdlet 19 | { 20 | [ValidateNotNullOrEmpty, 21 | Parameter( 22 | Position = 0, 23 | ValueFromPipeline = true, 24 | Mandatory = true, 25 | HelpMessage = "Specifies the identity of the Site containing the List to add the item to.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 26 | public SPOWebPipeBind Web { get; set; } 27 | 28 | [ValidateNotNullOrEmpty, 29 | Parameter( 30 | Position = 1, 31 | ValueFromPipeline = true, 32 | Mandatory = false, 33 | HelpMessage = "Specifies the List to add the item to.\r\n\r\nThe type must be a valid absolute URL, in the form http://contoso.sharepoint.com/site_name/lists/list_name, or an SPOList object, Microsoft.SharePoint.Client.List object, List title, or GUID representing the List ID.")] 34 | public SPOListPipeBind List { get; set; } 35 | 36 | [Parameter( 37 | Position = 2, 38 | Mandatory = false, 39 | HelpMessage = "Create the item within a subfolder inside the list. Only include the path relative to the root of the list.")] 40 | public string ListRelativeUrlFolderPath { get; set; } 41 | 42 | [Parameter( 43 | Position = 3, 44 | Mandatory = false, 45 | HelpMessage = "The collection of field values to set where the key is the internal field name. The type must be a hash table where each key represents the name of a field whose value should be set to the corresponding key value (e.g., @{\"Field1\"=\"Value1\";\"Field2\"=\"Value2\"}). Alternatively, provide the path to a file with XML property settings (Value1Value2).")] 46 | public PropertiesPipeBind FieldValues { get; set; } 47 | 48 | protected override void ProcessRecord() 49 | { 50 | base.ProcessRecord(); 51 | var ctx = base.Context; 52 | var web = ctx.Site.OpenWeb(Web.Read()); 53 | SPOList list = List.Read(web, true); 54 | 55 | Dictionary fieldValues = null; 56 | if (FieldValues != null) 57 | fieldValues = FieldValues.Read(); 58 | 59 | WriteObject(list.AddItem(ListRelativeUrlFolderPath, fieldValues)); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Cmdlets/Lists/RemoveSPOList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Lapointe.SharePointOnline.PowerShell.Data; 9 | using Microsoft.SharePoint.Client; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 12 | 13 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Lists 14 | { 15 | [Cmdlet("Remove", "SPOList", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.High)] 16 | [CmdletGroup("Lists")] 17 | [CmdletDescription("Removes a List from the specified Site.")] 18 | [RelatedCmdlets(typeof(ConnectSPOSite), typeof(GetSPOList))] 19 | [Example(Code = "PS C:\\> Remove-SPOWeb -Web \"/childsite\"", 20 | Remarks = "This example removes the childsite Site from the Site Collection.")] 21 | public class RemoveSPOList : BaseSPOCmdlet 22 | { 23 | [ValidateNotNullOrEmpty, 24 | Parameter( 25 | Position = 0, 26 | ValueFromPipeline = true, 27 | Mandatory = true, 28 | HelpMessage = "Specifies the identity of the Site containing the List to delete.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 29 | public SPOWebPipeBind Web { get; set; } 30 | 31 | [ValidateNotNullOrEmpty, 32 | Alias("List"), 33 | Parameter( 34 | Position = 1, 35 | ValueFromPipeline = true, 36 | Mandatory = true, 37 | HelpMessage = "Specifies the identity of the List to delete.\r\n\r\nThe type must be a valid absolute URL, in the form http://contoso.sharepoint.com/site_name/lists/list_name, or an SPOList object, Microsoft.SharePoint.Client.List object, List title, or GUID representing the List ID.")] 38 | public SPOListPipeBind Identity { get; set; } 39 | 40 | [Parameter( 41 | Position = 2, 42 | HelpMessage = "If specified the List will be recycled instead of deleted.")] 43 | public SwitchParameter Recycle { get; set; } 44 | 45 | protected override void ProcessRecord() 46 | { 47 | base.ProcessRecord(); 48 | var ctx = base.Context; 49 | if (!base.ShouldProcess(Identity.ToString(), "Remove List")) 50 | return; 51 | 52 | Web web = ctx.Site.OpenWeb(Web.Read()); 53 | SPOList list = Identity.Read(web, false); 54 | if (list != null) 55 | { 56 | if (Recycle) 57 | list.List.Recycle(); 58 | else 59 | list.List.DeleteObject(); 60 | 61 | list.List.Context.ExecuteQuery(); 62 | } 63 | else 64 | throw new ArgumentException("Unable to locate the specified list."); 65 | } 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Cmdlets/Search/ExportSPOSearchConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Lapointe.SharePointOnline.PowerShell.Data; 9 | using Microsoft.SharePoint.Client; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | using Microsoft.SharePoint.Client.Search.Administration; 12 | using Microsoft.SharePoint.Client.Search.Portability; 13 | using Lapointe.SharePointOnline.PowerShell.Attributes; 14 | 15 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Search 16 | { 17 | [Cmdlet("Export", "SPOSearchConfiguration", SupportsShouldProcess = false)] 18 | [CmdletGroup("Search")] 19 | [CmdletDescription("Exports the search configuration.", "Exports the search configuration from the current Tenant or Site Collection.")] 20 | [RelatedCmdlets(typeof(ConnectSPOSite), typeof(ImportSPOSearchConfiguration))] 21 | [Example(Code = "PS C:\\> Export-SPOSearchConfiguration -Path \"c:\\search.xml\" -ConfigScope SPSite", 22 | Remarks = "This example exports the search configuration for the current Site Collection.")] 23 | public class ExportSPOSearchConfiguration : BaseSPOCmdlet 24 | { 25 | [ValidateDirectoryExistsAndValidFileName, 26 | Parameter( 27 | Position = 0, 28 | Mandatory = true, 29 | HelpMessage = "The file path where the exported search settings will be saved.")] 30 | public string Path { get; set; } 31 | 32 | [Parameter( 33 | Position = 1, 34 | Mandatory = true, 35 | HelpMessage = "The level at which the search settings will be imported.")] 36 | public SearchObjectLevel ConfigScope { get; set; } 37 | 38 | protected override void ProcessRecord() 39 | { 40 | base.ProcessRecord(); 41 | var ctx = base.Context; 42 | 43 | SearchObjectLevel configScope = ConfigScope; 44 | var searchConfigurationPortability = new SearchConfigurationPortability(ctx); 45 | var owner = new SearchObjectOwner(ctx, configScope); 46 | var result = searchConfigurationPortability.ExportSearchConfiguration(owner); 47 | ctx.ExecuteQuery(); 48 | System.IO.File.WriteAllText(Path, result.Value); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Cmdlets/Search/ImportSPOSearchConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Lapointe.SharePointOnline.PowerShell.Data; 9 | using Microsoft.SharePoint.Client; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | using Microsoft.SharePoint.Client.Search.Administration; 12 | using Microsoft.SharePoint.Client.Search.Portability; 13 | 14 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Search 15 | { 16 | [Cmdlet("Import", "SPOSearchConfiguration", SupportsShouldProcess = false)] 17 | [CmdletGroup("Search")] 18 | [CmdletDescription("Retrieves one or more Sites within the current Site Collection.", "Retrieves a single Site given the server relative URL, GUID, or existing SPOWeb object. If a Site identifier is not provided then all Sites are provided.")] 19 | [RelatedCmdlets(typeof(ConnectSPOSite))] 20 | [Example(Code = "PS C:\\> Import-SPOSearchConfiguration -InputObject \"c:\\search.xml\" -ConfigScope SPSite", 21 | Remarks = "This example imports a search configuration to the current Site Collection.")] 22 | public class ImportSPOSearchConfiguration : BaseSPOCmdlet 23 | { 24 | [ValidateNotNullOrEmpty, 25 | Alias("Path"), 26 | Parameter( 27 | ValueFromPipeline = true, 28 | Position = 0, 29 | Mandatory = true, 30 | HelpMessage = "The path to the file containing the search settings to import. The value can be the path a file, an XmlDocument object, or an XML string.")] 31 | public XmlDocumentPipeBind InputObject { get; set; } 32 | 33 | [ValidateNotNullOrEmpty, 34 | Parameter( 35 | Position = 1, 36 | Mandatory = true, 37 | HelpMessage = "The level at which the search settings will be imported.")] 38 | public SearchObjectLevel ConfigScope { get; set; } 39 | 40 | protected override void ProcessRecord() 41 | { 42 | base.ProcessRecord(); 43 | var ctx = base.Context; 44 | 45 | SearchObjectLevel configScope = ConfigScope; 46 | var searchConfigurationPortability = new SearchConfigurationPortability(ctx); 47 | var owner = new SearchObjectOwner(ctx, configScope); 48 | var searchConfigXml = InputObject.Read(); 49 | searchConfigurationPortability.ImportSearchConfiguration(owner, searchConfigXml.OuterXml); 50 | ctx.ExecuteQuery(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Cmdlets/Sites/GetSPOContextSite.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Lapointe.SharePointOnline.PowerShell.Data; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Sites 12 | { 13 | [Cmdlet("Get", "SPOContextSite", SupportsShouldProcess = false)] 14 | [CmdletGroup("Sites")] 15 | [CmdletDescription("Retrieves the details for the currently connected Site Collection.")] 16 | [RelatedCmdlets(typeof(ConnectSPOSite))] 17 | [Example(Code = "PS C:\\> Get-SPOContextSite", 18 | Remarks = "This example retrieves the core details for the currently connected site.")] 19 | [Example(Code = "PS C:\\> Get-SPOContextSite -Detail", 20 | Remarks = "This example retrieves the core details along with additional information such as upgrade information, event receivers, owner, etc.")] 21 | public class GetSPOContextSite : BaseSPOCmdlet 22 | { 23 | [Parameter( 24 | Position = 0, 25 | ValueFromPipeline = false, 26 | Mandatory = false, 27 | HelpMessage = "Retrieve additional details useful for examining a single object.")] 28 | public SwitchParameter Detail { get; set; } 29 | 30 | protected override void ProcessRecord() 31 | { 32 | base.ProcessRecord(); 33 | var ctx = base.Context; 34 | 35 | WriteObject(SPOSiteContext.CurrentSiteContext.GetSite(Detail)); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Cmdlets/Sites/GetSPOWeb.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Lapointe.SharePointOnline.PowerShell.Data; 9 | using Microsoft.SharePoint.Client; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | 12 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Sites 13 | { 14 | [Cmdlet("Get", "SPOWeb", SupportsShouldProcess = false)] 15 | [CmdletGroup("Sites")] 16 | [CmdletDescription("Retrieves one or more Sites within the current Site Collection.", "Retrieves a single Site given the server relative URL, GUID, or existing SPOWeb object. If a Site identifier is not provided then all Sites are provided.")] 17 | [RelatedCmdlets(typeof(ConnectSPOSite))] 18 | [Example(Code = "PS C:\\> Get-SPOWeb \"/childsite\"", 19 | Remarks = "This example retrieves the core details for the childsite sub-site of the current Site Collection.")] 20 | [Example(Code = "PS C:\\> Get-SPOWeb \"/\" -Detail", 21 | Remarks = "This example retrieves the core details along with additional information for the root site of the current Site Collection.")] 22 | [Example(Code = "PS C:\\> Get-SPOWeb -Detail", 23 | Remarks = "This example retrieves the core details along with additional information for all Sites within the current Site Collection.")] 24 | public class GetSPOWeb : BaseSPOCmdlet 25 | { 26 | [ValidateNotNullOrEmpty, 27 | Alias("Web"), 28 | Parameter( 29 | Position = 0, 30 | ValueFromPipeline = true, 31 | Mandatory = false, 32 | HelpMessage = "Specifies the identity of the Site to retrieve.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 33 | public SPOWebPipeBind Identity { get; set; } 34 | 35 | [Parameter( 36 | Position = 1, 37 | ValueFromPipeline = false, 38 | Mandatory = false, 39 | HelpMessage = "Retrieve additional details useful for examining a single object.")] 40 | public SwitchParameter Detail { get; set; } 41 | 42 | [Parameter( 43 | Position = 2, 44 | ValueFromPipeline = false, 45 | Mandatory = false, 46 | HelpMessage = "When returning multiple items (-Identity is not provided), include app webs in the resultset.")] 47 | public SwitchParameter IncludeAppWebs { get; set; } 48 | 49 | protected override void ProcessRecord() 50 | { 51 | base.ProcessRecord(); 52 | var ctx = base.Context; 53 | 54 | if (Identity == null) 55 | { 56 | Web rootWeb = ctx.Site.RootWeb; 57 | SPOWeb.LoadWeb(ctx, rootWeb, Detail); 58 | WriteObject(new SPOWeb(rootWeb)); 59 | IterateWebs(ctx, rootWeb, Detail); 60 | } 61 | else 62 | { 63 | string surl = Identity.Read(); 64 | Web web = ctx.Site.OpenWeb(surl); 65 | SPOWeb.LoadWeb(ctx, web, Detail); 66 | 67 | WriteObject(new SPOWeb(web)); 68 | } 69 | } 70 | 71 | private void IterateWebs(CmdletContext ctx, Web parentWeb, bool detailed) 72 | { 73 | var childWebs = parentWeb.Webs; 74 | ctx.Load(childWebs); 75 | ctx.ExecuteQuery(); 76 | foreach (Web childWeb in childWebs) 77 | { 78 | SPOWeb.LoadWeb(ctx, childWeb, detailed); 79 | SPOWeb web = new SPOWeb(childWeb); 80 | if (web.WebTemplate != "APP" || (web.WebTemplate == "APP" && IncludeAppWebs)) 81 | WriteObject(web); 82 | IterateWebs(ctx, childWeb, detailed); 83 | } 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Cmdlets/Sites/RemoveSPOWeb.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Lapointe.SharePointOnline.PowerShell.Data; 9 | using Microsoft.SharePoint.Client; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | 12 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Sites 13 | { 14 | [Cmdlet("Remove", "SPOWeb", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.High)] 15 | [CmdletGroup("Sites")] 16 | [CmdletDescription("Removes a Site from the current Site Collection.")] 17 | [RelatedCmdlets(typeof(ConnectSPOSite), typeof(GetSPOWeb))] 18 | [Example(Code = "PS C:\\> Remove-SPOWeb -Web \"/childsite\"", 19 | Remarks = "This example removes the childsite Site from the Site Collection.")] 20 | public class RemoveSPOWeb : BaseSPOCmdlet 21 | { 22 | [ValidateNotNullOrEmpty, 23 | Alias("Web"), 24 | Parameter( 25 | Position = 0, 26 | ValueFromPipeline = true, 27 | Mandatory = true, 28 | HelpMessage = "Specifies the identity of the Site to delete.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 29 | public SPOWebPipeBind Identity { get; set; } 30 | 31 | [Parameter( 32 | Position = 1, 33 | Mandatory = false, 34 | HelpMessage = "If the Site contains child Sites then recursively delete all child Sites.")] 35 | public SwitchParameter Recurse { get; set; } 36 | 37 | protected override void ProcessRecord() 38 | { 39 | base.ProcessRecord(); 40 | var ctx = base.Context; 41 | string surl = Identity.Read(); 42 | if (surl == "/") 43 | throw new InvalidOperationException("You cannot delete the root Site of a Site Collection."); 44 | 45 | if (!base.ShouldProcess(Identity.ToString(), "Remove Web")) 46 | return; 47 | 48 | Web web = ctx.Site.OpenWeb(surl); 49 | if (Recurse) 50 | { 51 | Delete(web); 52 | } 53 | else 54 | { 55 | web.DeleteObject(); 56 | web.Context.ExecuteQuery(); 57 | } 58 | } 59 | 60 | private void Delete(Web web) 61 | { 62 | if (!base.ShouldProcess(Identity.ToString())) 63 | return; 64 | 65 | var ctx = base.Context; 66 | if (!web.IsObjectPropertyInstantiated("Webs")) 67 | { 68 | ctx.Load(web.Webs); 69 | ctx.ExecuteQuery(); 70 | } 71 | if (web.Webs.Count > 0) 72 | { 73 | var toDelete = new List(); 74 | 75 | foreach (Web childWeb in web.Webs) 76 | { 77 | toDelete.Add(childWeb); 78 | } 79 | 80 | foreach (Web childWeb in toDelete) 81 | { 82 | Delete(childWeb); 83 | } 84 | if (web.Webs.Count == 0) 85 | { 86 | try { WriteVerbose("Deleting " + web.Url); } catch { } 87 | web.DeleteObject(); 88 | web.Context.ExecuteQuery(); 89 | } 90 | } 91 | else 92 | { 93 | try { WriteVerbose("Deleting " + web.Url); } catch { } 94 | web.DeleteObject(); 95 | web.Context.ExecuteQuery(); 96 | } 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Cmdlets/Sites/SetSPOWebTheme.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 8 | using Lapointe.SharePointOnline.PowerShell.Data; 9 | using Microsoft.SharePoint.Client; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | 12 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Sites 13 | { 14 | [Cmdlet("Set", "SPOWebTheme", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] 15 | [CmdletGroup("Sites")] 16 | [CmdletDescription("Applies a theme with the specified components to the specified Site.")] 17 | [RelatedCmdlets(typeof(ConnectSPOSite), typeof(GetSPOWeb))] 18 | [Example(Code = "PS C:\\> Set-SPOWebTheme -Web \"/\" -ColorPaletteUrl \"/_catalogs/theme/15/palette001.spcolor\"", 19 | Remarks = "This example sets the theme of the root Site of the current Site Collection.")] 20 | public class SetSPOWebTheme : BaseSPOCmdlet 21 | { 22 | [ValidateNotNullOrEmpty, 23 | Alias("Web"), 24 | Parameter( 25 | Position = 0, 26 | ValueFromPipeline = true, 27 | Mandatory = true, 28 | HelpMessage = "Specifies the identity of the Site to apply the theme to.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 29 | public SPOWebPipeBind Identity { get; set; } 30 | 31 | [ValidateNotNullOrEmpty, 32 | Parameter( 33 | Position = 1, 34 | Mandatory = true, 35 | HelpMessage = "The server relative URL to the color palette file. For example: \"/_catalogs/theme/15/palette001.spcolor\".")] 36 | public string ColorPaletteUrl { get; set; } 37 | 38 | [Parameter( 39 | Position = 2, 40 | Mandatory = false, 41 | HelpMessage = "The server relative URL to the font file. For example: \"/_catalogs/theme/15/fontscheme001.spfont\".")] 42 | public string FontSchemeUrl { get; set; } 43 | 44 | [Parameter( 45 | Position = 3, 46 | Mandatory = false, 47 | HelpMessage = "The server relative URL to the background image file. For example: \"/Images/bg.png\".")] 48 | public string BackgroundImageUrl { get; set; } 49 | 50 | [Parameter( 51 | Position = 4, 52 | Mandatory = false, 53 | HelpMessage = "If specified, store the generated theme files in the root Site, otherwise store them in this Site.")] 54 | public bool ShareGenerated { get; set; } 55 | 56 | protected override void ProcessRecord() 57 | { 58 | base.ProcessRecord(); 59 | var ctx = base.Context; 60 | string surl = Identity.Read(); 61 | 62 | if (!base.ShouldProcess(Identity.ToString())) 63 | return; 64 | 65 | SPOWeb web = new SPOWeb(ctx.Site.OpenWeb(surl)); 66 | web.ApplyTheme(ColorPaletteUrl, FontSchemeUrl, BackgroundImageUrl, ShareGenerated); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Cmdlets/Solutions/AddSPOSolution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Management.Automation; 6 | using System.Text; 7 | using Lapointe.PowerShell.MamlGenerator.Attributes; 8 | using Lapointe.SharePointOnline.PowerShell.Attributes; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 12 | 13 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Solutions 14 | { 15 | [Cmdlet("Add", "SPOSolution", SupportsShouldProcess = false)] 16 | [CmdletGroup("Solutions")] 17 | [CmdletDescription("Add a WSP to the Solution Gallery of a Site Collection.")] 18 | [RelatedCmdlets(typeof(ConnectSPOSite))] 19 | [Example(Code = "PS C:\\> Add-SPOSolution -LiteralPath \"c:\\customtemplate.wsp\"", 20 | Remarks = "This example uploads a custom Sandbox Solution to the Solution Gallery of the current Site Collection.")] 21 | public class AddSPOSolution : BaseSPOCmdlet 22 | { 23 | [ValidateNotNullOrEmpty, 24 | ValidateFileExists, 25 | Parameter( 26 | Position = 1, 27 | Mandatory = true, 28 | HelpMessage = "Specify the path to the solution package (WSP) to add to the Solution Gallery.")] 29 | public string LiteralPath { get; set; } 30 | 31 | [Parameter(Position = 2, HelpMessage = "Overwrite an existing file if present.")] 32 | public SwitchParameter Overwrite { get; set; } 33 | 34 | protected override void ProcessRecord() 35 | { 36 | base.ProcessRecord(); 37 | var ctx = base.Context; 38 | 39 | ctx.Load(ctx.Site, s => s.ServerRelativeUrl); 40 | ctx.ExecuteQuery(); 41 | 42 | FileInfo file = new FileInfo(LiteralPath); 43 | string leafName = file.Name; 44 | string url = ctx.Site.ServerRelativeUrl.TrimEnd('/') + "/_catalogs/solutions/" + leafName; 45 | using (FileStream stream = new FileStream(LiteralPath, FileMode.Open)) 46 | { 47 | Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, 48 | url, stream, Overwrite); 49 | } 50 | SPOWeb web = new SPOWeb(ctx.Site.RootWeb); 51 | WriteObject(web.GetFileByServerRelativeUrl(url)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Cmdlets/Solutions/InstallSPOSolution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Management.Automation; 6 | using System.Text; 7 | using Lapointe.PowerShell.MamlGenerator.Attributes; 8 | using Lapointe.SharePointOnline.PowerShell.Attributes; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 12 | using Microsoft.SharePoint.Client.Publishing; 13 | 14 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Solutions 15 | { 16 | [Cmdlet("Install", "SPOSolution", SupportsShouldProcess = false)] 17 | [CmdletGroup("Solutions")] 18 | [CmdletDescription("Add a WSP to the Solution Gallery of a Site Collection.")] 19 | [RelatedCmdlets(typeof(ConnectSPOSite))] 20 | [Example(Code = "PS C:\\> Install-SPOSolution -Identity \"customtemplate.wsp\"", 21 | Remarks = "This example activates a custom Sandbox Solution in the Solution Gallery of the current Site Collection. The WSP will be copied to customtemplate.wsp-v1.0 and this copied version will be activated.")] 22 | public class InstallSPOSolution : BaseSPOCmdlet 23 | { 24 | public InstallSPOSolution() { MajorVersion = 1; } 25 | 26 | [ValidateNotNullOrEmpty, 27 | Alias("PackageName", "Name"), 28 | Parameter( 29 | Position = 1, 30 | Mandatory = true, 31 | HelpMessage = "Specify the name of the solution package (WSP) to activate.")] 32 | public string Identity { get; set; } 33 | 34 | [Parameter(Position = 2, HelpMessage = "Sets the major version of the WSP. The default value is 1.")] 35 | public int MajorVersion { get; set; } 36 | 37 | [Parameter(Position = 3, HelpMessage = "Sets the minor version of the WSP. The default value is 0.")] 38 | public int MinorVersion { get; set; } 39 | 40 | protected override void ProcessRecord() 41 | { 42 | base.ProcessRecord(); 43 | var ctx = base.Context; 44 | 45 | ctx.Load(ctx.Site, s => s.ServerRelativeUrl); 46 | ctx.ExecuteQuery(); 47 | 48 | DesignPackageInfo dpi = new DesignPackageInfo(); 49 | dpi.PackageGuid = Guid.Empty; 50 | dpi.MajorVersion = MajorVersion; 51 | dpi.MinorVersion = MinorVersion; 52 | dpi.PackageName = Identity; 53 | 54 | string url = ctx.Site.ServerRelativeUrl.TrimEnd('/') + "/_catalogs/solutions/" + Identity; 55 | DesignPackage.Install(ctx, ctx.Site, dpi, url); 56 | ctx.ExecuteQuery(); 57 | 58 | 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Cmdlets/Solutions/UninstallSPOSolution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Management.Automation; 6 | using System.Text; 7 | using Lapointe.PowerShell.MamlGenerator.Attributes; 8 | using Lapointe.SharePointOnline.PowerShell.Attributes; 9 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 10 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 11 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 12 | using Microsoft.SharePoint.Client.Publishing; 13 | 14 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Solutions 15 | { 16 | // Only works on public facing o365 sites so comment out for now. 17 | /* 18 | [Cmdlet("Uninstall", "SPOSolution", SupportsShouldProcess = false)] 19 | [CmdletGroup("Solutions")] 20 | [CmdletDescription("Add a WSP to the Solution Gallery of a Site Collection.")] 21 | [RelatedCmdlets(typeof(ConnectSPOSite))] 22 | [Example(Code = "PS C:\\> Uninstall-SPOSolution -Identity \"customtemplate.wsp\"", 23 | Remarks = "This example deactivates a custom Sandbox Solution in the Solution Gallery of the current Site Collection.")] 24 | public class UninstallSPOSolution : BaseSPOCmdlet 25 | { 26 | public UninstallSPOSolution() { MajorVersion = 1; } 27 | 28 | [ValidateNotNullOrEmpty, 29 | Alias("PackageName", "Name"), 30 | Parameter( 31 | Position = 1, 32 | Mandatory = true, 33 | HelpMessage = "Specify the name of the solution package (WSP) to deactivate.")] 34 | public string Identity { get; set; } 35 | 36 | [Parameter(Position = 2, HelpMessage = "Sets the major version of the WSP to deactivate. The default value is 1.")] 37 | public int MajorVersion { get; set; } 38 | 39 | [Parameter(Position = 3, HelpMessage = "Sets the minor version of the WSP to deactivate. The default value is 0.")] 40 | public int MinorVersion { get; set; } 41 | 42 | protected override void ProcessRecord() 43 | { 44 | base.ProcessRecord(); 45 | var ctx = base.Context; 46 | 47 | DesignPackageInfo dpi = new DesignPackageInfo(); 48 | dpi.PackageGuid = Guid.Empty; 49 | dpi.MajorVersion = MajorVersion; 50 | dpi.MinorVersion = MinorVersion; 51 | dpi.PackageName = Identity; 52 | 53 | DesignPackage.UnInstall(ctx, ctx.Site, dpi); 54 | ctx.ExecuteQuery(); 55 | 56 | 57 | } 58 | } 59 | * */ 60 | } 61 | -------------------------------------------------------------------------------- /Cmdlets/Taxonomy/GetSPOTermGroup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.Data.Taxonomy; 8 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 9 | using Microsoft.SharePoint.Client.Taxonomy; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Taxonomy 12 | { 13 | [Cmdlet("Get", "SPOTermGroup", SupportsShouldProcess = false)] 14 | [CmdletGroup("Managed Metadata")] 15 | [CmdletDescription("Retrieves a Term Group object.")] 16 | [RelatedCmdlets(typeof(ExportSPOTaxonomy))] 17 | [Example(Code = "PS C:\\> Get-SPOTermGroup -Identity \"My Group\"", 18 | Remarks = "This example retrieves a single term group.")] 19 | public class GetSPOTermGroup : BaseSPOCmdlet 20 | { 21 | [Alias("Group")] 22 | [Parameter(Mandatory = false, 23 | ValueFromPipeline = true, 24 | ValueFromPipelineByPropertyName = true, 25 | Position = 0, 26 | HelpMessage = "The taxonomy group to retrieve. The type must be a valid TermGroup object, SPOTermGroup object, name, or GUID.")] 27 | public SPOTermGroupPipeBind Identity { get; set; } 28 | 29 | protected override void ProcessRecord() 30 | { 31 | base.ProcessRecord(); 32 | var ctx = base.Context; 33 | 34 | if (Identity != null) 35 | { 36 | var group = new SPOTermGroup(Identity.Read()); 37 | WriteObject(group); 38 | } 39 | else 40 | { 41 | TaxonomySession ts = TaxonomySession.GetTaxonomySession(ctx); 42 | var termStores = ts.TermStores; 43 | ctx.Load(termStores); 44 | ctx.ExecuteQuery(); 45 | 46 | foreach (TermStore termStore in termStores) 47 | { 48 | var groups = termStore.Groups; 49 | ctx.Load(groups); 50 | ctx.ExecuteQuery(); 51 | foreach (var group in groups) 52 | { 53 | WriteObject(new SPOTermGroup(group)); 54 | } 55 | } 56 | } 57 | } 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Cmdlets/Taxonomy/GetSPOTermSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.Data.Taxonomy; 8 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 9 | using Microsoft.SharePoint.Client.Taxonomy; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Taxonomy 12 | { 13 | [Cmdlet("Get", "SPOTermSet", SupportsShouldProcess = false)] 14 | [CmdletGroup("Managed Metadata")] 15 | [CmdletDescription("Retrieves a Term Set object.")] 16 | [RelatedCmdlets(typeof(ExportSPOTaxonomy))] 17 | [Example(Code = "PS C:\\> Get-SPOTermSet -Identity ([guid]\"6067b6a8-9866-40db-962d-84097f22619a\")", 18 | Remarks = "This example retrieves a single term set.")] 19 | public class GetSPOTermSet : BaseSPOCmdlet 20 | { 21 | [Alias("TermSet")] 22 | [Parameter(Mandatory = false, 23 | ValueFromPipeline = true, 24 | ValueFromPipelineByPropertyName = true, 25 | Position = 0, 26 | HelpMessage = "The TermSet to retrieve. The type must be a valid TermSet object, SPOTermSet object, or GUID.")] 27 | public SPOTermSetPipeBind Identity { get; set; } 28 | 29 | protected override void ProcessRecord() 30 | { 31 | base.ProcessRecord(); 32 | var ctx = base.Context; 33 | 34 | if (Identity != null) 35 | { 36 | var termSet = new SPOTermSet(Identity.Read()); 37 | WriteObject(termSet); 38 | } 39 | else 40 | { 41 | TaxonomySession ts = TaxonomySession.GetTaxonomySession(ctx); 42 | var termStores = ts.TermStores; 43 | ctx.Load(termStores); 44 | ctx.ExecuteQuery(); 45 | 46 | foreach (TermStore termStore in termStores) 47 | { 48 | var groups = termStore.Groups; 49 | ctx.Load(groups); 50 | ctx.ExecuteQuery(); 51 | foreach (var group in groups) 52 | { 53 | var termSets = group.TermSets; 54 | ctx.Load(termSets); 55 | ctx.ExecuteQuery(); 56 | foreach (var termSet in termSets) 57 | { 58 | WriteObject(new SPOTermSet(termSet)); 59 | } 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Cmdlets/Taxonomy/GetSPOTermStore.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.Data.Taxonomy; 8 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 9 | using Microsoft.SharePoint.Client.Taxonomy; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Taxonomy 12 | { 13 | [Cmdlet("Get", "SPOTermStore", SupportsShouldProcess = false)] 14 | [CmdletGroup("Managed Metadata")] 15 | [CmdletDescription("Retrieves a Term Store object.")] 16 | [RelatedCmdlets(typeof(ExportSPOTaxonomy))] 17 | [Example(Code = "PS C:\\> Get-SPOTermStore -Identity \"My Group\"", 18 | Remarks = "This example retrieves a single term group.")] 19 | public class GetSPOTermStore : BaseSPOCmdlet 20 | { 21 | [Alias("TermStore")] 22 | [Parameter(Mandatory = false, 23 | ValueFromPipeline = true, 24 | ValueFromPipelineByPropertyName = true, 25 | Position = 0, 26 | HelpMessage = "The taxonomy term store to retrieve. The type must be a valid TermStore object, name, GUID, or index location.")] 27 | public SPOTermStorePipeBind Identity { get; set; } 28 | 29 | protected override void ProcessRecord() 30 | { 31 | base.ProcessRecord(); 32 | var ctx = base.Context; 33 | 34 | if (Identity != null) 35 | { 36 | var termStore = new SPOTermStore(Identity.Read()); 37 | WriteObject(termStore); 38 | } 39 | else 40 | { 41 | TaxonomySession ts = TaxonomySession.GetTaxonomySession(ctx); 42 | var termStores = ts.TermStores; 43 | ctx.Load(termStores); 44 | ctx.ExecuteQuery(); 45 | 46 | foreach (TermStore termStore in termStores) 47 | { 48 | ctx.Load(termStore, ts1 => ts1.ContentTypePublishingHub); 49 | ctx.ExecuteQuery(); 50 | WriteObject(new SPOTermStore(termStore)); 51 | } 52 | } 53 | } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Cmdlets/Taxonomy/NewSPOTermGroup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.Data.Taxonomy; 8 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 9 | using Microsoft.SharePoint.Client; 10 | using Microsoft.SharePoint.Client.Taxonomy; 11 | 12 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Taxonomy 13 | { 14 | [Cmdlet("New", "SPOTermGroup", SupportsShouldProcess = false)] 15 | [CmdletGroup("Managed Metadata")] 16 | [CmdletDescription("Creates a Term Group object.")] 17 | [RelatedCmdlets(typeof(ExportSPOTaxonomy))] 18 | [Example(Code = "PS C:\\> New-SPOTermGroup -TermStore 0 -Name \"My Group\"", 19 | Remarks = "This example creates a single term group.")] 20 | public class NewSPOTermGroup : BaseSPOCmdlet 21 | { 22 | public NewSPOTermGroup() 23 | { 24 | Id = Guid.NewGuid(); 25 | } 26 | 27 | [Parameter(Mandatory = true, 28 | ValueFromPipeline = true, 29 | ValueFromPipelineByPropertyName = true, 30 | Position = 0, 31 | HelpMessage = "The TermStore to add the Term Group to. The type must be a valid TermStore object, name, GUID, or index location.")] 32 | public SPOTermStorePipeBind TermStore { get; set; } 33 | 34 | [Parameter(Mandatory = true, Position = 1, HelpMessage = "The name of the term group to create.")] 35 | public string Name { get; set; } 36 | 37 | [Parameter(Mandatory = false, Position = 2, HelpMessage = "The Id of the term group to create.")] 38 | public Guid Id { get; set; } 39 | 40 | [Parameter(Mandatory = false, Position = 3, HelpMessage = "The description of the term group to create.")] 41 | public string Description { get; set; } 42 | 43 | protected override void ProcessRecord() 44 | { 45 | base.ProcessRecord(); 46 | var ctx = base.Context; 47 | 48 | var termStore = new SPOTermStore(TermStore.Read()); 49 | WriteObject(termStore.CreateGroup(Name, Id, Description)); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Cmdlets/Taxonomy/NewSPOTermSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.Data.Taxonomy; 8 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 9 | using Microsoft.SharePoint.Client; 10 | using Microsoft.SharePoint.Client.Taxonomy; 11 | 12 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Taxonomy 13 | { 14 | [Cmdlet("New", "SPOTermSet", SupportsShouldProcess = false)] 15 | [CmdletGroup("Managed Metadata")] 16 | [CmdletDescription("Creates a Term Set object.")] 17 | [RelatedCmdlets(typeof(ExportSPOTaxonomy))] 18 | [Example(Code = "PS C:\\> New-SPOTermSet -Group \"My Group\" -Name \"My Term Set\"", 19 | Remarks = "This example creates a single term set.")] 20 | public class NewSPOTermSet : BaseSPOCmdlet 21 | { 22 | public NewSPOTermSet() 23 | { 24 | Id = Guid.NewGuid(); 25 | LCID = 0; 26 | } 27 | 28 | [Parameter(Mandatory = true, 29 | ValueFromPipeline = true, 30 | ValueFromPipelineByPropertyName = true, 31 | Position = 0, 32 | HelpMessage = "The Term Group to add the Term Set to. The type must be a valid TermGroup object, SPOTermGroup object, name, or GUID.")] 33 | public SPOTermGroupPipeBind Group { get; set; } 34 | 35 | [Parameter(Mandatory = true, Position = 1, HelpMessage = "The name of the term set to create.")] 36 | public string Name { get; set; } 37 | 38 | [Parameter(Mandatory = false, Position = 2, HelpMessage = "The Id of the term set to create.")] 39 | public Guid Id { get; set; } 40 | 41 | [Parameter(Mandatory = false, Position = 3, HelpMessage = "The description of the term set to create.")] 42 | public string Description { get; set; } 43 | 44 | [Parameter(Mandatory = false, Position = 4, HelpMessage = "The contact for the Term Set object.")] 45 | public string Contact { get; set; } 46 | 47 | [Parameter(Mandatory = false, Position = 5, HelpMessage = "The custom sort order of the Term Set object.")] 48 | public string CustomSortOrder { get; set; } 49 | 50 | [Parameter(Mandatory = false, Position = 6, HelpMessage = "If specified, the Term Set object should appear in the tagging user interface.")] 51 | public SwitchParameter IsAvailableForTagging { get; set; } 52 | 53 | [Parameter(Mandatory = false, Position = 7, HelpMessage = "The user who is responsible for the current TermSet.")] 54 | public string Owner { get; set; } 55 | 56 | [Parameter(Mandatory = false, Position = 8, HelpMessage = "If specified, the Term Set can be updated by all users; otherwise, just by the specified constributors for the Group object.")] 57 | public SwitchParameter IsOpenForTermCreation { get; set; } 58 | 59 | [Alias("Locale", "Language")] 60 | [Parameter(Mandatory = false, Position = 9, HelpMessage = "The language code identifier (LCID).")] 61 | public int LCID { get; set; } 62 | 63 | protected override void ProcessRecord() 64 | { 65 | base.ProcessRecord(); 66 | var ctx = base.Context; 67 | 68 | var group = new SPOTermGroup(Group.Read()); 69 | WriteObject(group.CreateTermSet(Name, Id, LCID, Contact, Description, CustomSortOrder, IsAvailableForTagging, Owner, IsOpenForTermCreation)); 70 | } 71 | 72 | private int GetWorkingLanguage(TaxonomySession ts) 73 | { 74 | var ctx = base.Context; 75 | ctx.Load(ts.TermStores); 76 | ctx.ExecuteQuery(); 77 | 78 | TermStore termStore = ts.TermStores[0]; 79 | ctx.Load(termStore, t => t.WorkingLanguage); 80 | ctx.ExecuteQuery(); 81 | return termStore.WorkingLanguage; 82 | } 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Cmdlets/WebParts/GetWebPart.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.Attributes; 8 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 9 | using Lapointe.SharePointOnline.PowerShell.Enums; 10 | using Lapointe.SharePointOnline.PowerShell.Exceptions; 11 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 12 | using Lapointe.SharePointOnline.PowerShell.Cmdlets.Lists; 13 | 14 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.WebParts 15 | { 16 | [Cmdlet("Get", "SPOWebPart", SupportsShouldProcess = false, DefaultParameterSetName = "WikiPage")] 17 | [CmdletGroup("Web Parts")] 18 | [CmdletDescription("Gets a web part or list of web parts from a web part page or wiki page.")] 19 | [RelatedCmdlets(typeof(ConnectSPOSite), typeof(GetSPOFile))] 20 | [Example(Code = "PS C:\\> Add-SPOWebPart -Web \"/\" -File \"/default.aspx\" -WebPart \"c:\\announcements.webpart\" -Title \"Announcements\" -Zone \"MiddleColumn\" -ZoneIndex 1", 21 | Remarks = "This example adds an announcements web part to the default.aspx web part page located in the root web of the root site collection.")] 22 | [Example(Code = "PS C:\\> Add-SPOWebPart -Web \"/\" -File \"/sitepages/home.aspx\" -WebPart \"c:\\announcements.webpart\" -Row 1 -Column 1 -AddSpace", 23 | Remarks = "This example adds an announcements web part to the home.aspx wiki page located in the root web of the root site collection.")] 24 | public class GetWebPart : BaseSPOCmdlet 25 | { 26 | [ValidateNotNullOrEmpty, 27 | Parameter( 28 | Position = 0, 29 | ValueFromPipeline = true, 30 | Mandatory = true, 31 | HelpMessage = "Specifies the identity of the Site containing the file to get the web part from.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 32 | public SPOWebPipeBind Web { get; set; } 33 | 34 | [ValidateNotNullOrEmpty, 35 | Parameter( 36 | Position = 1, 37 | ValueFromPipeline = true, 38 | Mandatory = false, 39 | HelpMessage = "Specifies the file to get the web part from.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name/list_name/file_name, or an SPOFile or SPOWikiPage object, or Microsoft.SharePoint.Client.File object.")] 40 | public SPOFilePipeBind File { get; set; } 41 | 42 | [ValidateNotNullOrEmpty, 43 | Parameter( 44 | ParameterSetName = "WebPartPage", 45 | Position = 3, 46 | Mandatory = false, 47 | HelpMessage = "The title of the web part to add.")] 48 | public string Title { get; set; } 49 | 50 | protected override void ProcessRecord() 51 | { 52 | base.ProcessRecord(); 53 | var ctx = base.Context; 54 | 55 | var web = ctx.Site.OpenWeb(Web.Read()); 56 | SPOFile file = File.Read(web); 57 | var wpd = file.GetWebPartDefinitions(); 58 | if (string.IsNullOrEmpty(Title)) 59 | WriteObject(wpd); 60 | else 61 | WriteObject(wpd.Where(w => w.WebPart.Title == Title)); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Cmdlets/WikiPages/NewSPOWikiPage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.Attributes; 8 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 9 | using Lapointe.SharePointOnline.PowerShell.Enums; 10 | using Lapointe.SharePointOnline.PowerShell.Exceptions; 11 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 12 | 13 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Lists 14 | { 15 | [Cmdlet("New", "SPOWikiPage", SupportsShouldProcess = false, DefaultParameterSetName = "List")] 16 | [CmdletGroup("Wiki Pages")] 17 | [CmdletDescription("Creates a new wiki page within an existing List.")] 18 | [RelatedCmdlets(typeof(ConnectSPOSite), typeof(GetSPOList))] 19 | [Example(Code = "PS C:\\> New-SPOWikiPage -Web \"/\" -List \"Site Pages\" -WikiPageName \"MyWikiPage.aspx\"", 20 | Remarks = "This example creates a new wiki page within the Site Pages list under the root Site of the root Site Collection.")] 21 | public class NewSPOWikiPage : BaseSPOCmdlet 22 | { 23 | public NewSPOWikiPage() 24 | { 25 | WikiPageLayout = Enums.WikiPageLayout.ThreeColumnsHeaderFooter; 26 | } 27 | 28 | [ValidateNotNullOrEmpty, 29 | Parameter( 30 | Position = 0, 31 | ValueFromPipeline = true, 32 | Mandatory = true, 33 | HelpMessage = "Specifies the identity of the Site containing the List to add the file to.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 34 | public SPOWebPipeBind Web { get; set; } 35 | 36 | [ValidateNotNullOrEmpty, 37 | Parameter( 38 | ParameterSetName = "List", 39 | Position = 1, 40 | ValueFromPipeline = true, 41 | Mandatory = false, 42 | HelpMessage = "Specifies the List to add the file to.\r\n\r\nThe type must be a valid absolute URL, in the form http://contoso.sharepoint.com/site_name/lists/list_name, or an SPOList object, Microsoft.SharePoint.Client.List object, List title, or GUID representing the List ID.")] 43 | public SPOListPipeBind List { get; set; } 44 | 45 | [ValidateNotNullOrEmpty, 46 | Parameter( 47 | ParameterSetName = "Folder", 48 | Position = 2, 49 | ValueFromPipeline = true, 50 | Mandatory = false, 51 | HelpMessage = "Specifies the Folder to add the file to.\r\n\r\nThe type must be a valid SPOFolder object.")] 52 | public SPOFolder Folder { get; set; } 53 | 54 | [ValidateNotNullOrEmpty, 55 | Parameter( 56 | Position = 3, 57 | Mandatory = true, 58 | HelpMessage = "The name of the wiki page to create.")] 59 | public string WikiPageName { get; set; } 60 | 61 | [Parameter(Position = 4, Mandatory = false, HelpMessage = "The page layout to set the wiki page to. The default value is \"ThreeColumnsHeaderFooter\".")] 62 | public WikiPageLayout WikiPageLayout { get; set; } 63 | 64 | protected override void ProcessRecord() 65 | { 66 | base.ProcessRecord(); 67 | var ctx = base.Context; 68 | 69 | SPOWikiPage page = null; 70 | try 71 | { 72 | if (ParameterSetName == "List") 73 | { 74 | var web = ctx.Site.OpenWeb(Web.Read()); 75 | SPOList list = List.Read(web, true); 76 | page = SPOWikiPage.AddWikiPage(list, WikiPageName, true); 77 | } 78 | else 79 | { 80 | page = SPOWikiPage.AddWikiPage(Folder, WikiPageName, true); 81 | } 82 | } 83 | catch (FileExistsException) 84 | { 85 | throw new Exception("The specified wiki page already exists and will not be overwritten."); 86 | } 87 | if (page != null) 88 | page.AddLayoutToWikiPage(WikiPageLayout); 89 | 90 | WriteObject(page); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Cmdlets/WikiPages/SetSPOWikiPageLayout.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using Lapointe.PowerShell.MamlGenerator.Attributes; 7 | using Lapointe.SharePointOnline.PowerShell.Attributes; 8 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 9 | using Lapointe.SharePointOnline.PowerShell.Enums; 10 | using Lapointe.SharePointOnline.PowerShell.Exceptions; 11 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 12 | 13 | namespace Lapointe.SharePointOnline.PowerShell.Cmdlets.Lists 14 | { 15 | [Cmdlet("Set", "SPOWikiPageLayout", SupportsShouldProcess = false, DefaultParameterSetName = "List")] 16 | [CmdletGroup("Wiki Pages")] 17 | [CmdletDescription("Sets the layout for a wiki page within an existing List.")] 18 | [RelatedCmdlets(typeof(ConnectSPOSite), typeof(GetSPOList))] 19 | [Example(Code = "PS C:\\> Set-SPOWikiPageLayout -Web \"/\" -List \"Site Pages\" -WikiPageName \"MyWikiPage.aspx\" -WikiPageLayout \"OneColumnSideBar\"", 20 | Remarks = "This example sets the layout of an existing wiki page within the Site Pages list under the root Site of the root Site Collection.")] 21 | public class SetSPOWikiPageLayout : BaseSPOCmdlet 22 | { 23 | [ValidateNotNullOrEmpty, 24 | Parameter( 25 | Position = 0, 26 | ValueFromPipeline = true, 27 | Mandatory = true, 28 | HelpMessage = "Specifies the identity of the Site containing the file to update.\r\n\r\nThe type must be a valid server relative URL, in the form /site_name, or an SPOWeb object, Microsoft.SharePoint.Client.Web object, or GUID representing the Site ID.")] 29 | public SPOWebPipeBind Web { get; set; } 30 | 31 | [ValidateNotNullOrEmpty, 32 | Parameter( 33 | ParameterSetName = "List", 34 | Position = 1, 35 | ValueFromPipeline = true, 36 | Mandatory = false, 37 | HelpMessage = "Specifies the List containing the file to update.\r\n\r\nThe type must be a valid absolute URL, in the form http://contoso.sharepoint.com/site_name/lists/list_name, or an SPOList object, Microsoft.SharePoint.Client.List object, List title, or GUID representing the List ID.")] 38 | public SPOListPipeBind List { get; set; } 39 | 40 | [ValidateNotNullOrEmpty, 41 | Parameter( 42 | ParameterSetName = "Folder", 43 | Position = 2, 44 | ValueFromPipeline = true, 45 | Mandatory = false, 46 | HelpMessage = "Specifies the Folder containing the file to update.\r\n\r\nThe type must be a valid SPOFolder object.")] 47 | public SPOFolder Folder { get; set; } 48 | 49 | [ValidateNotNullOrEmpty, 50 | Parameter( 51 | Position = 3, 52 | Mandatory = true, 53 | HelpMessage = "The name of the wiki page to update.")] 54 | public string WikiPageName { get; set; } 55 | 56 | [Parameter( 57 | Position = 4, 58 | Mandatory = true, 59 | HelpMessage = "The page layout to set the wiki page to.")] 60 | public WikiPageLayout WikiPageLayout { get; set; } 61 | 62 | protected override void ProcessRecord() 63 | { 64 | base.ProcessRecord(); 65 | var ctx = base.Context; 66 | 67 | SPOFile page = null; 68 | if (ParameterSetName == "List") 69 | { 70 | var web = ctx.Site.OpenWeb(Web.Read()); 71 | SPOList list = List.Read(web, true); 72 | page = list.GetRootFolder(true).GetFile(WikiPageName); 73 | } 74 | else 75 | { 76 | page = Folder.GetFile(WikiPageName); 77 | } 78 | if (page != null) 79 | { 80 | SPOWikiPage wikiPage = new SPOWikiPage(page.File); 81 | wikiPage.SetWikiPageLayout(WikiPageLayout); 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Data/EventReceivers/SPOEventReceiverDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.SharePoint.Client; 6 | 7 | namespace Lapointe.SharePointOnline.PowerShell.Data.EventReceivers 8 | { 9 | public class SPOEventReceiverDefinition : SPOClientObject 10 | { 11 | private EventReceiverDefinition _erd = null; 12 | private EventReceiverDefinitionCollection _parentCollection = null; 13 | 14 | public SPOEventReceiverDefinition(EventReceiverDefinition erd, EventReceiverDefinitionCollection parentCollection) 15 | { 16 | _erd = erd; 17 | _parentCollection = parentCollection; 18 | } 19 | 20 | public EventReceiverDefinition EventReceiverDefinition { get { return _erd; } } 21 | 22 | public EventReceiverType EventType 23 | { 24 | get 25 | { 26 | if (_erd.IsPropertyAvailable("EventType")) 27 | return _erd.EventType; 28 | return EventReceiverType.ContextEvent; 29 | } 30 | } 31 | 32 | public string ReceiverAssembly 33 | { 34 | get 35 | { 36 | if (_erd.IsPropertyAvailable("ReceiverAssembly")) 37 | return _erd.ReceiverAssembly; 38 | return null; 39 | } 40 | } 41 | 42 | public string ReceiverClass 43 | { 44 | get 45 | { 46 | if (_erd.IsPropertyAvailable("ReceiverClass")) 47 | return _erd.ReceiverClass; 48 | return null; 49 | } 50 | } 51 | 52 | public Guid ReceiverId 53 | { 54 | get 55 | { 56 | if (_erd.IsPropertyAvailable("ReceiverId")) 57 | return _erd.ReceiverId; 58 | return Guid.Empty; 59 | } 60 | } 61 | 62 | public string ReceiverName 63 | { 64 | get 65 | { 66 | if (_erd.IsPropertyAvailable("ReceiverName")) 67 | return _erd.ReceiverName; 68 | return null; 69 | } 70 | } 71 | 72 | public string ReceiverUrl 73 | { 74 | get 75 | { 76 | if (_erd.IsPropertyAvailable("ReceiverUrl")) 77 | return _erd.ReceiverUrl; 78 | return null; 79 | } 80 | } 81 | 82 | public int SequenceNumber 83 | { 84 | get 85 | { 86 | if (_erd.IsPropertyAvailable("SequenceNumber")) 87 | return _erd.SequenceNumber; 88 | return 0; 89 | } 90 | } 91 | 92 | public EventReceiverSynchronization Synchronization 93 | { 94 | get 95 | { 96 | if (_erd.IsPropertyAvailable("Synchronization")) 97 | return _erd.Synchronization; 98 | return EventReceiverSynchronization.DefaultSynchronization; 99 | } 100 | } 101 | 102 | public void Delete() 103 | { 104 | _erd.DeleteObject(); 105 | _parentCollection.Context.ExecuteQuery(); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Data/Navigation/SPONavigation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.Data.Navigation 7 | { 8 | public class SPONavigation : SPOClientObject 9 | { 10 | Microsoft.SharePoint.Client.Navigation _navigation = null; 11 | SPONavigationNodeCollection _quickLaunch = null; 12 | SPONavigationNodeCollection _topNavigationBar = null; 13 | public SPONavigation(Microsoft.SharePoint.Client.Navigation navigation) 14 | { 15 | _navigation = navigation; 16 | } 17 | public Microsoft.SharePoint.Client.Navigation Navigation { get { return _navigation; } } 18 | 19 | public SPONavigationNodeCollection QuickLaunch 20 | { 21 | get 22 | { 23 | if (_quickLaunch != null) 24 | return _quickLaunch; 25 | if (_navigation.IsObjectPropertyInstantiated("QuickLaunch")) 26 | { 27 | _quickLaunch = new SPONavigationNodeCollection(_navigation.QuickLaunch); 28 | return _quickLaunch; 29 | } 30 | return null; 31 | } 32 | } 33 | 34 | public SPONavigationNodeCollection TopNavigationBar 35 | { 36 | get 37 | { 38 | if (_topNavigationBar != null) 39 | return _topNavigationBar; 40 | if (_navigation.IsObjectPropertyInstantiated("TopNavigationBar")) 41 | { 42 | _topNavigationBar = new SPONavigationNodeCollection(_navigation.TopNavigationBar); 43 | return _topNavigationBar; 44 | } 45 | return null; 46 | } 47 | } 48 | public bool UseShared { get; set; } 49 | 50 | public SPONavigationNode GetNodeById(int id) 51 | { 52 | return new SPONavigationNode(_navigation.GetNodeById(id)); 53 | } 54 | 55 | 56 | internal static void LoadNavigation(CmdletContext ctx, Microsoft.SharePoint.Client.Navigation navigation) 57 | { 58 | ctx.Load(navigation, n => n.QuickLaunch, n => n.TopNavigationBar, n => n.UseShared); 59 | ctx.ExecuteQuery(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Data/Navigation/SPONavigationNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.Data.Navigation 7 | { 8 | public class SPONavigationNode : SPOClientObject 9 | { 10 | Microsoft.SharePoint.Client.NavigationNode _navigationNode = null; 11 | private bool _hasChanges = false; 12 | SPONavigationNodeCollection _children = null; 13 | 14 | public SPONavigationNode(Microsoft.SharePoint.Client.NavigationNode navigationNode) 15 | { 16 | _navigationNode = navigationNode; 17 | } 18 | 19 | public Microsoft.SharePoint.Client.NavigationNode NavigationNode { get { return _navigationNode; } } 20 | 21 | public SPONavigationNodeCollection GetChildren() 22 | { 23 | if (_children != null) 24 | return _children; 25 | if (!_navigationNode.IsObjectPropertyInstantiated("Children")) 26 | { 27 | _navigationNode.Context.Load(_navigationNode.Children); 28 | _navigationNode.Context.ExecuteQuery(); 29 | } 30 | _children = new SPONavigationNodeCollection(_navigationNode.Children); 31 | return _children; 32 | } 33 | 34 | public int Id 35 | { 36 | get 37 | { 38 | if (_navigationNode.IsPropertyAvailable("Id")) 39 | return _navigationNode.Id; 40 | return 0; 41 | } 42 | } 43 | public bool IsDocLib 44 | { 45 | get 46 | { 47 | if (_navigationNode.IsPropertyAvailable("IsDocLib")) 48 | return _navigationNode.IsDocLib; 49 | return false; 50 | } 51 | } 52 | 53 | public bool IsExternal 54 | { 55 | get 56 | { 57 | if (_navigationNode.IsPropertyAvailable("IsExternal")) 58 | return _navigationNode.IsExternal; 59 | return false; 60 | } 61 | } 62 | public bool IsVisible 63 | { 64 | get 65 | { 66 | if (_navigationNode.IsPropertyAvailable("IsVisible")) 67 | return _navigationNode.IsVisible; 68 | return false; 69 | } 70 | set 71 | { 72 | _navigationNode.IsVisible = value; 73 | _hasChanges = true; 74 | } 75 | } 76 | 77 | 78 | public string Title 79 | { 80 | get 81 | { 82 | if (_navigationNode.IsPropertyAvailable("Title")) 83 | return _navigationNode.Title; 84 | return null; 85 | } 86 | set 87 | { 88 | _navigationNode.Title = value; 89 | _hasChanges = true; 90 | } 91 | } 92 | 93 | public string Url 94 | { 95 | get 96 | { 97 | if (_navigationNode.IsPropertyAvailable("Url")) 98 | return _navigationNode.Url; 99 | return null; 100 | } 101 | set 102 | { 103 | _navigationNode.Url = value; 104 | _hasChanges = true; 105 | } 106 | } 107 | 108 | 109 | 110 | public void Delete() 111 | { 112 | _navigationNode.DeleteObject(); 113 | _navigationNode.Context.ExecuteQuery(); 114 | if (ParentCollection != null && ParentCollection is SPONavigationNodeCollection) 115 | ((SPONavigationNodeCollection)ParentCollection).Remove(this); 116 | } 117 | public void Update() 118 | { 119 | if (_hasChanges) 120 | { 121 | _navigationNode.Update(); 122 | _navigationNode.Context.Load(_navigationNode); 123 | _navigationNode.Context.ExecuteQuery(); 124 | 125 | _hasChanges = false; 126 | } 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /Data/Navigation/SPONavigationNodeCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.Data.Navigation 7 | { 8 | public class SPONavigationNodeCollection : SPOClientObjectCollection 9 | { 10 | Microsoft.SharePoint.Client.NavigationNodeCollection _navigationNodeCollection = null; 11 | 12 | public SPONavigationNodeCollection(Microsoft.SharePoint.Client.NavigationNodeCollection navigationNodeCollection) 13 | { 14 | _navigationNodeCollection = navigationNodeCollection; 15 | foreach (var node in _navigationNodeCollection) 16 | { 17 | AddChild(new SPONavigationNode(node)); 18 | } 19 | } 20 | 21 | public Microsoft.SharePoint.Client.NavigationNodeCollection NavigationNodeCollection { get { return _navigationNodeCollection; } } 22 | 23 | public SPONavigationNode Add(Microsoft.SharePoint.Client.NavigationNodeCreationInformation parameters) 24 | { 25 | var node = new SPONavigationNode(_navigationNodeCollection.Add(parameters)); 26 | _navigationNodeCollection.Context.Load(node.NavigationNode); 27 | _navigationNodeCollection.Context.ExecuteQuery(); 28 | AddChild(node); 29 | return node; 30 | } 31 | public SPONavigationNode Add(bool asLastNode, bool isExternal, SPONavigationNode previousNode, string title, string url) 32 | { 33 | var node = new Microsoft.SharePoint.Client.NavigationNodeCreationInformation(); 34 | node.AsLastNode = asLastNode; 35 | node.IsExternal = isExternal; 36 | if (previousNode != null) 37 | node.PreviousNode = previousNode.NavigationNode; 38 | node.Title = title; 39 | node.Url = url; 40 | return Add(node); 41 | } 42 | 43 | internal void Remove(SPONavigationNode node) 44 | { 45 | Data.Remove(node); 46 | } 47 | 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Data/Principals/SPOPrincipal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.SharePoint.Client; 6 | using Microsoft.SharePoint.Client.Utilities; 7 | 8 | namespace Lapointe.SharePointOnline.PowerShell.Data.Principals 9 | { 10 | public class SPOPrincipal : SPOClientObject 11 | { 12 | private Principal _principal = null; 13 | private bool _hasChanges = false; 14 | 15 | public SPOPrincipal(Principal principal) 16 | { 17 | _principal = principal; 18 | } 19 | 20 | public Principal Principal { get { return _principal; } } 21 | 22 | public int Id 23 | { 24 | get 25 | { 26 | if (_principal.IsPropertyAvailable("Id")) 27 | return _principal.Id; 28 | return 0; 29 | } 30 | } 31 | 32 | public bool IsHiddenInUI 33 | { 34 | get 35 | { 36 | if (_principal.IsPropertyAvailable("IsHiddenInUI")) 37 | return _principal.IsHiddenInUI; 38 | return false; 39 | } 40 | } 41 | 42 | public string LoginName 43 | { 44 | get 45 | { 46 | if (_principal.IsPropertyAvailable("LoginName")) 47 | return _principal.LoginName; 48 | return null; 49 | } 50 | } 51 | 52 | public PrincipalType PrincipalType 53 | { 54 | get 55 | { 56 | if (_principal.IsPropertyAvailable("PrincipalType")) 57 | return _principal.PrincipalType; 58 | return Microsoft.SharePoint.Client.Utilities.PrincipalType.None; 59 | } 60 | } 61 | 62 | public string Title 63 | { 64 | get 65 | { 66 | if (_principal.IsPropertyAvailable("Title")) 67 | return _principal.Title; 68 | return null; 69 | } 70 | set 71 | { 72 | _principal.Title = value; 73 | _hasChanges = true; 74 | } 75 | } 76 | 77 | public virtual void Update() 78 | { 79 | if (_hasChanges) 80 | { 81 | _principal.Context.ExecuteQuery(); 82 | _hasChanges = true; 83 | } 84 | } 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Data/Principals/SPOUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.SharePoint.Client; 6 | using Microsoft.SharePoint.Client.Utilities; 7 | 8 | namespace Lapointe.SharePointOnline.PowerShell.Data.Principals 9 | { 10 | public class SPOUser : SPOPrincipal 11 | { 12 | private User _user = null; 13 | private bool _hasChanges = false; 14 | 15 | public SPOUser(User user) : base(user) 16 | { 17 | _user = user; 18 | } 19 | 20 | public User User { get { return _user; } } 21 | 22 | public string Email 23 | { 24 | get 25 | { 26 | if (_user.IsPropertyAvailable("Email")) 27 | return _user.Email; 28 | return null; 29 | } 30 | set 31 | { 32 | _user.Email = value; 33 | _hasChanges = true; 34 | } 35 | } 36 | 37 | public bool IsSiteAdmin 38 | { 39 | get 40 | { 41 | if (_user.IsPropertyAvailable("IsSiteAdmin")) 42 | return _user.IsSiteAdmin; 43 | return false; 44 | } 45 | set 46 | { 47 | _user.IsSiteAdmin = value; 48 | _hasChanges = true; 49 | } 50 | } 51 | 52 | public UserIdInfo UserId 53 | { 54 | get 55 | { 56 | if (_user.IsPropertyAvailable("UserId")) 57 | return _user.UserId; 58 | return null; 59 | } 60 | } 61 | 62 | public override void Update() 63 | { 64 | base.Update(); 65 | if (_hasChanges) 66 | { 67 | _user.Update(); 68 | _user.Context.ExecuteQuery(); 69 | _hasChanges = false; 70 | } 71 | } 72 | 73 | 74 | private List _groups = null; 75 | public List GetGroups() 76 | { 77 | if (_groups != null) return _groups; 78 | 79 | GroupCollection gc = _user.Groups; 80 | if (!_user.IsObjectPropertyInstantiated("Groups") || !_user.Groups.AreItemsAvailable) 81 | { 82 | _user.Context.Load(gc); 83 | _user.Context.ExecuteQuery(); 84 | } 85 | _groups = new List(); 86 | foreach (Group g in gc) 87 | { 88 | _groups.Add(new SPOGroup(g)); 89 | } 90 | return _groups; 91 | } 92 | 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Data/SPOClientObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.Data 7 | { 8 | public abstract class SPOClientObject 9 | { 10 | private SPOClientObjectCollection _parentCollection; 11 | 12 | internal SPOClientObjectCollection ParentCollection 13 | { 14 | get 15 | { 16 | return _parentCollection; 17 | } 18 | set 19 | { 20 | _parentCollection = value; 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Data/SPOClientObjectCollection.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.SharePoint.Client; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Lapointe.SharePointOnline.PowerShell.Data 9 | { 10 | public abstract class SPOClientObjectCollection : SPOClientObject, IEnumerable 11 | { 12 | private List m_data; 13 | 14 | protected SPOClientObjectCollection() 15 | { 16 | } 17 | 18 | protected void AddChild(SPOClientObject obj) 19 | { 20 | this.Data.Add(obj); 21 | if (obj.ParentCollection == null) 22 | { 23 | obj.ParentCollection = this; 24 | } 25 | } 26 | 27 | protected object GetItemAtIndex(int i) 28 | { 29 | return this.Data[i]; 30 | } 31 | 32 | IEnumerator IEnumerable.GetEnumerator() 33 | { 34 | int count = this.Data.Count; 35 | int i = 0; 36 | while (true) 37 | { 38 | if (i >= this.Data.Count) 39 | { 40 | yield break; 41 | } 42 | if (count != this.Data.Count) 43 | { 44 | throw new InvalidOperationException(Resources.GetString("CollectionModified")); 45 | } 46 | yield return this.GetItemAtIndex(i); 47 | i++; 48 | } 49 | } 50 | 51 | 52 | public virtual int Count 53 | { 54 | get 55 | { 56 | return this.Data.Count; 57 | } 58 | } 59 | 60 | protected List Data 61 | { 62 | get 63 | { 64 | if (this.m_data == null) 65 | { 66 | this.m_data = new List(); 67 | } 68 | return this.m_data; 69 | } 70 | } 71 | } 72 | 73 | 74 | public abstract class SPOClientObjectCollection : SPOClientObjectCollection, IEnumerable, IEnumerable 75 | { 76 | public SPOClientObjectCollection() 77 | { 78 | } 79 | 80 | public IEnumerator GetEnumerator() 81 | { 82 | int count = this.Count; 83 | int i = 0; 84 | while (true) 85 | { 86 | if (i >= this.Count) 87 | { 88 | yield break; 89 | } 90 | if (count != this.Count) 91 | { 92 | throw new InvalidOperationException(Resources.GetString("CollectionModified")); 93 | } 94 | yield return (T) this.GetItemAtIndex(i); 95 | i++; 96 | } 97 | } 98 | 99 | public Type ElementType 100 | { 101 | get 102 | { 103 | return typeof(T); 104 | } 105 | } 106 | 107 | public System.Linq.Expressions.Expression Expression 108 | { 109 | get 110 | { 111 | return System.Linq.Expressions.Expression.Constant(this); 112 | } 113 | } 114 | 115 | public T this[int index] 116 | { 117 | get 118 | { 119 | return (T) base.GetItemAtIndex(index); 120 | } 121 | } 122 | 123 | } 124 | } 125 | 126 | -------------------------------------------------------------------------------- /Data/Sites/SPOPropertyBag.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 6 | using Lapointe.SharePointOnline.PowerShell.Data.WebParts; 7 | using Microsoft.SharePoint.Client; 8 | 9 | namespace Lapointe.SharePointOnline.PowerShell.Data.Sites 10 | { 11 | public class SPOPropertyBag : SPOClientObject 12 | { 13 | private SPOWeb _web = null; 14 | private SPOFolder _folder = null; 15 | private SPOWebPart _webPart = null; 16 | private PropertyValues _pb = null; 17 | private bool _hasChanges = false; 18 | 19 | public SPOPropertyBag(SPOFolder folder, PropertyValues properties) 20 | { 21 | _folder = folder; 22 | _pb = properties; 23 | } 24 | public SPOPropertyBag(SPOWeb web, PropertyValues properties) 25 | { 26 | _web = web; 27 | _pb = properties; 28 | } 29 | public SPOPropertyBag(SPOWebPart webPart, PropertyValues properties) 30 | { 31 | _webPart = webPart; 32 | _pb = properties; 33 | } 34 | 35 | public Dictionary FieldValues 36 | { 37 | get 38 | { 39 | return _pb.FieldValues; 40 | } 41 | } 42 | 43 | public object this[string fieldName] 44 | { 45 | get 46 | { 47 | return _pb[fieldName]; 48 | } 49 | set 50 | { 51 | _pb[fieldName] = value; 52 | _hasChanges = true; 53 | } 54 | } 55 | 56 | public void SetFieldValue(string fieldName, object value) 57 | { 58 | _pb[fieldName] = value; 59 | _hasChanges = true; 60 | } 61 | 62 | public void Update() 63 | { 64 | if (_hasChanges) 65 | { 66 | if (_web != null) 67 | _web.Web.Update(); 68 | if (_folder != null) 69 | _folder.Folder.Update(); 70 | if (_webPart != null) 71 | { 72 | _webPart.Update(); 73 | _hasChanges = false; 74 | return; 75 | } 76 | 77 | _pb.Context.ExecuteQuery(); 78 | _hasChanges = false; 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Data/Sites/SPOUserCustomActionCollection.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.SharePoint.Client; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Lapointe.SharePointOnline.PowerShell.Data.Sites 9 | { 10 | public class SPOUserCustomActionCollection : SPOClientObjectCollection 11 | { 12 | private UserCustomActionCollection _userCustomActionCollection; 13 | 14 | public SPOUserCustomActionCollection(UserCustomActionCollection userCustomActionCollection) 15 | { 16 | _userCustomActionCollection = userCustomActionCollection; 17 | foreach (var uca in userCustomActionCollection) 18 | { 19 | AddChild(new SPOUserCustomAction(uca)); 20 | } 21 | } 22 | 23 | public UserCustomActionCollection UserCustomActionCollection { get { return _userCustomActionCollection; } } 24 | 25 | 26 | public SPOUserCustomAction Add() 27 | { 28 | var uca = new SPOUserCustomAction(_userCustomActionCollection.Add()); 29 | AddChild(uca); 30 | return uca; 31 | } 32 | 33 | internal void Remove(SPOUserCustomAction uca) 34 | { 35 | Data.Remove(uca); 36 | } 37 | 38 | public void Clear() 39 | { 40 | _userCustomActionCollection.Clear(); 41 | _userCustomActionCollection.Context.ExecuteQuery(); 42 | Data.Clear(); 43 | } 44 | 45 | public SPOUserCustomAction GetById(Guid id) 46 | { 47 | var uca = _userCustomActionCollection.GetById(id); 48 | _userCustomActionCollection.Context.ExecuteQuery(); 49 | return new SPOUserCustomAction(uca); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Data/Taxonomy/SPOTaxonomyBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.SharePoint.Client.Taxonomy; 6 | 7 | namespace Lapointe.SharePointOnline.PowerShell.Data.Taxonomy 8 | { 9 | public abstract class SPOTaxonomyBase : SPOClientObject 10 | { 11 | protected Dictionary _original = new Dictionary(); 12 | protected Dictionary _changes = new Dictionary(); 13 | 14 | protected T GetProp(string fieldName) where T : class 15 | { 16 | if (_changes.ContainsKey(fieldName)) 17 | return (T)_changes[fieldName]; 18 | if (_original.ContainsKey(fieldName)) 19 | return (T)_original[fieldName]; 20 | 21 | return null; 22 | } 23 | 24 | 25 | protected S GetPropV(string fieldName) where S : struct 26 | { 27 | if (!_changes.ContainsKey(fieldName) && !_original.ContainsKey(fieldName)) 28 | { 29 | throw new InvalidCastException("Uninitialized property cannot be unboxed."); 30 | } 31 | 32 | if (_changes.ContainsKey(fieldName)) 33 | return (S)_changes[fieldName]; 34 | else 35 | return (S)_original[fieldName]; 36 | } 37 | 38 | protected void SetProp(string fieldName, object value, bool isChange) 39 | { 40 | Dictionary collection = null; 41 | if (isChange) 42 | collection = _changes; 43 | else 44 | collection = _original; 45 | 46 | if (collection.ContainsKey(fieldName)) 47 | collection[fieldName] = value; 48 | else 49 | collection.Add(fieldName, value); 50 | 51 | if (!isChange && _changes.ContainsKey(fieldName)) 52 | _changes.Remove(fieldName); 53 | } 54 | 55 | protected bool HasChange(string fieldName) 56 | { 57 | return _changes.ContainsKey(fieldName); 58 | } 59 | protected bool HasChanges() 60 | { 61 | return _changes.Count > 0; 62 | } 63 | protected void ClearChanges() 64 | { 65 | _changes.Clear(); 66 | } 67 | 68 | protected int _workingLanguage = 0; 69 | protected int GetWorkingLanguage(TermStore termStore) 70 | { 71 | if (_workingLanguage > 0) return _workingLanguage; 72 | if (!termStore.IsPropertyAvailable("WorkingLanguage")) 73 | { 74 | termStore.Context.Load(termStore, l => l.WorkingLanguage); 75 | termStore.Context.ExecuteQuery(); 76 | } 77 | _workingLanguage = termStore.WorkingLanguage; 78 | return _workingLanguage; 79 | } 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Data/Taxonomy/SPOTaxonomyItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.SharePoint.Client.Taxonomy; 6 | 7 | namespace Lapointe.SharePointOnline.PowerShell.Data.Taxonomy 8 | { 9 | public abstract class SPOTaxonomyItem : SPOTaxonomyBase 10 | { 11 | private TaxonomyItem _item = null; 12 | 13 | public SPOTaxonomyItem(TaxonomyItem item) 14 | { 15 | _item = item; 16 | 17 | if (_item.IsPropertyAvailable("Name")) 18 | SetProp("Name", _item.Name, false); 19 | } 20 | 21 | public string Name 22 | { 23 | get 24 | { 25 | return GetProp("Name"); 26 | } 27 | set 28 | { 29 | SetProp("Name", value, true); 30 | } 31 | } 32 | 33 | public DateTime CreatedDate 34 | { 35 | get 36 | { 37 | if (_item.IsPropertyAvailable("CreatedDate")) 38 | return _item.CreatedDate; 39 | return DateTime.MinValue; 40 | } 41 | } 42 | 43 | public Guid Id 44 | { 45 | get 46 | { 47 | if (_item.IsPropertyAvailable("Id")) 48 | return _item.Id; 49 | return Guid.Empty; 50 | } 51 | } 52 | 53 | public DateTime LastModifiedDate 54 | { 55 | get 56 | { 57 | if (_item.IsPropertyAvailable("LastModifiedDate")) 58 | return _item.LastModifiedDate; 59 | return DateTime.MinValue; 60 | } 61 | } 62 | 63 | private SPOTermStore _termStore = null; 64 | public SPOTermStore GetTermStore() 65 | { 66 | if (_termStore != null) return _termStore; 67 | 68 | var termStore = _item.TermStore; 69 | if (!_item.IsObjectPropertyInstantiated("TermStore")) 70 | { 71 | _item.Context.Load(termStore); 72 | _item.Context.ExecuteQuery(); 73 | } 74 | _termStore = new SPOTermStore(termStore); 75 | return _termStore; 76 | } 77 | 78 | 79 | public virtual void Refresh() 80 | { 81 | if (_item.IsPropertyAvailable("Name")) 82 | SetProp("Name", _item.Name, false); 83 | } 84 | 85 | public virtual void Update() 86 | { 87 | if (HasChanges()) 88 | { 89 | if (HasChange("Name")) 90 | _item.Name = Name; 91 | } 92 | } 93 | 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Data/Taxonomy/SPOTermLabel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.SharePoint.Client.Taxonomy; 6 | 7 | namespace Lapointe.SharePointOnline.PowerShell.Data.Taxonomy 8 | { 9 | public class SPOTermLabel : SPOTaxonomyBase 10 | { 11 | private Label _label = null; 12 | private SPOTerm _term = null; 13 | 14 | public SPOTermLabel(Label label, SPOTerm term) 15 | { 16 | _label = label; 17 | _term = term; 18 | 19 | if (_label.IsPropertyAvailable("Value")) 20 | SetProp("Value", _label.Value, false); 21 | } 22 | 23 | public Label Label { get { return _label; } } 24 | 25 | public string Value 26 | { 27 | get 28 | { 29 | return GetProp("Value"); 30 | } 31 | set 32 | { 33 | SetProp("Value", value, true); 34 | } 35 | } 36 | 37 | public bool IsDefaultForLanguage 38 | { 39 | get 40 | { 41 | if (_label.IsPropertyAvailable("IsDefaultForLanguage")) 42 | return _label.IsDefaultForLanguage; 43 | return false; 44 | } 45 | } 46 | 47 | public int Language 48 | { 49 | get 50 | { 51 | if (_label.IsPropertyAvailable("Language")) 52 | return _label.Language; 53 | return 0; 54 | } 55 | } 56 | 57 | public SPOTerm Term { get { return _term; } } 58 | 59 | public void Delete() 60 | { 61 | _label.DeleteObject(); 62 | _label.Context.ExecuteQuery(); 63 | } 64 | 65 | public void SetAsDefaultForLanguage() 66 | { 67 | _label.SetAsDefaultForLanguage(); 68 | _label.Context.ExecuteQuery(); 69 | Refresh(); 70 | } 71 | 72 | public void Refresh() 73 | { 74 | _label.RefreshLoad(); 75 | _label.Context.ExecuteQuery(); 76 | 77 | if (_label.IsPropertyAvailable("Value")) 78 | SetProp("Value", _label.Value, false); 79 | } 80 | 81 | public void Update() 82 | { 83 | if (HasChanges()) 84 | { 85 | if (HasChange("Value")) 86 | _label.Value = Value; 87 | _label.Context.ExecuteQuery(); 88 | Refresh(); 89 | } 90 | } 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Data/Taxonomy/SPOTermSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.SharePoint.Client.Taxonomy; 6 | 7 | namespace Lapointe.SharePointOnline.PowerShell.Data.Taxonomy 8 | { 9 | public class SPOTermSet : SPOTermSetItem 10 | { 11 | private TermSet _termSet = null; 12 | 13 | public SPOTermSet(TermSet termSet) : base(termSet) 14 | { 15 | _termSet = termSet; 16 | 17 | if (_termSet.IsPropertyAvailable("Description")) 18 | SetProp("Description", _termSet.Description, false); 19 | if (_termSet.IsPropertyAvailable("Contact")) 20 | SetProp("Contact", _termSet.Contact, false); 21 | if (_termSet.IsPropertyAvailable("IsOpenForTermCreation")) 22 | SetProp("IsOpenForTermCreation", _termSet.IsOpenForTermCreation, false); 23 | } 24 | 25 | public TermSet TermSet { get { return _termSet; } } 26 | 27 | public string Contact 28 | { 29 | get 30 | { 31 | return GetProp("Contact"); 32 | } 33 | set 34 | { 35 | SetProp("Contact", value, true); 36 | } 37 | } 38 | 39 | public string Description 40 | { 41 | get 42 | { 43 | return GetProp("Description"); 44 | } 45 | set 46 | { 47 | SetProp("Description", value, true); 48 | } 49 | } 50 | 51 | public bool IsOpenForTermCreation 52 | { 53 | get 54 | { 55 | return GetPropV("IsOpenForTermCreation"); 56 | } 57 | set 58 | { 59 | SetProp("IsOpenForTermCreation", value, true); 60 | } 61 | } 62 | 63 | private SPOTermGroup _termGroup = null; 64 | public SPOTermGroup GetGroup() 65 | { 66 | if (_termGroup != null) return _termGroup; 67 | 68 | TermGroup group = _termSet.Group; 69 | _termSet.Context.Load(group); 70 | _termSet.Context.ExecuteQuery(); 71 | _termGroup = new SPOTermGroup(group); 72 | return _termGroup; 73 | } 74 | 75 | public IEnumerable Stakeholders 76 | { 77 | get { return _termSet.Stakeholders; } 78 | } 79 | 80 | public void AddStakeholder(string stakeholder) 81 | { 82 | _termSet.AddStakeholder(stakeholder); 83 | _termSet.Context.ExecuteQuery(); 84 | } 85 | public void DeleteStakeholder(string stakeholder) 86 | { 87 | _termSet.DeleteStakeholder(stakeholder); 88 | _termSet.Context.ExecuteQuery(); 89 | } 90 | 91 | public override void Refresh() 92 | { 93 | _termSet.RefreshLoad(); 94 | _termSet.Context.ExecuteQuery(); 95 | base.Refresh(); 96 | 97 | if (_termSet.IsPropertyAvailable("Description")) 98 | SetProp("Description", _termSet.Description, false); 99 | if (_termSet.IsPropertyAvailable("Contact")) 100 | SetProp("Contact", _termSet.Contact, false); 101 | if (_termSet.IsPropertyAvailable("IsOpenForTermCreation")) 102 | SetProp("IsOpenForTermCreation", _termSet.IsOpenForTermCreation, false); 103 | } 104 | 105 | public override void Update() 106 | { 107 | if (HasChanges()) 108 | { 109 | base.Update(); 110 | 111 | if (HasChange("Contact")) 112 | _termSet.Contact = Contact; 113 | 114 | if (HasChange("Description")) 115 | _termSet.Description = Description; 116 | 117 | if (HasChange("IsOpenForTermCreation")) 118 | _termSet.IsOpenForTermCreation = IsOpenForTermCreation; 119 | 120 | _termSet.Context.ExecuteQuery(); 121 | Refresh(); 122 | } 123 | } 124 | 125 | 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /Data/WebParts/SPOWebPart.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 6 | using Microsoft.SharePoint.Client.WebParts; 7 | 8 | namespace Lapointe.SharePointOnline.PowerShell.Data.WebParts 9 | { 10 | public class SPOWebPart : SPOClientObject 11 | { 12 | private WebPart _webPart = null; 13 | private SPOWebPartDefinition _webPartDefinition = null; 14 | private bool _hasChanges = false; 15 | 16 | public SPOWebPart(WebPart webPart, SPOWebPartDefinition webPartDefinition) 17 | { 18 | _webPart = webPart; 19 | _webPartDefinition = webPartDefinition; 20 | } 21 | 22 | public WebPart WebPart { get { return _webPart; } } 23 | 24 | public void Update() 25 | { 26 | if (_hasChanges) 27 | { 28 | _webPartDefinition.SaveWebPartChanges(); 29 | _hasChanges = false; 30 | } 31 | } 32 | 33 | public bool Hidden 34 | { 35 | get 36 | { 37 | if (_webPart.IsPropertyAvailable("Hidden")) 38 | return _webPart.Hidden; 39 | return false; 40 | } 41 | set 42 | { 43 | _webPart.Hidden = value; 44 | _hasChanges = true; 45 | } 46 | } 47 | 48 | public bool IsClosed 49 | { 50 | get 51 | { 52 | if (_webPart.IsPropertyAvailable("IsClosed")) 53 | return _webPart.IsClosed; 54 | return false; 55 | } 56 | } 57 | 58 | private SPOPropertyBag _properties = null; 59 | public SPOPropertyBag Properties 60 | { 61 | get 62 | { 63 | if (_properties == null && _webPart.IsObjectPropertyInstantiated("Properties")) 64 | _properties = new SPOPropertyBag(this, _webPart.Properties); 65 | return _properties; 66 | } 67 | } 68 | 69 | public string Subtitle 70 | { 71 | get 72 | { 73 | if (_webPart.IsPropertyAvailable("Subtitle")) 74 | return _webPart.Subtitle; 75 | return null; 76 | } 77 | } 78 | 79 | public string Title 80 | { 81 | get 82 | { 83 | if (_webPart.IsPropertyAvailable("Title")) 84 | return _webPart.Title; 85 | return null; 86 | } 87 | set 88 | { 89 | _webPart.Title = value; 90 | _hasChanges = true; 91 | } 92 | } 93 | 94 | public string TitleUrl 95 | { 96 | get 97 | { 98 | if (_webPart.IsPropertyAvailable("TitleUrl")) 99 | return _webPart.TitleUrl; 100 | return null; 101 | } 102 | set 103 | { 104 | _webPart.TitleUrl = value; 105 | _hasChanges = true; 106 | } 107 | } 108 | 109 | public int ZoneIndex 110 | { 111 | get 112 | { 113 | if (_webPart.IsPropertyAvailable("ZoneIndex")) 114 | return _webPart.ZoneIndex; 115 | return 0; 116 | } 117 | } 118 | 119 | 120 | 121 | internal static void LoadWebPart(CmdletContext ctx, WebPart webPart) 122 | { 123 | ctx.Load(webPart, 124 | wp => wp.Hidden, 125 | wp => wp.IsClosed, 126 | wp => wp.Properties, 127 | wp => wp.Subtitle, 128 | wp => wp.Title, 129 | wp => wp.TitleUrl, 130 | wp => wp.ZoneIndex); 131 | ctx.ExecuteQuery(); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /Data/WebParts/SPOWebPartDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.SharePoint.Client.WebParts; 6 | 7 | namespace Lapointe.SharePointOnline.PowerShell.Data.WebParts 8 | { 9 | public class SPOWebPartDefinition : SPOClientObject 10 | { 11 | private WebPartDefinition _webPartDefinition = null; 12 | 13 | public SPOWebPartDefinition(WebPartDefinition webPartDefinition) 14 | { 15 | _webPartDefinition = webPartDefinition; 16 | 17 | } 18 | 19 | public WebPartDefinition WebPartDefinition { get { return _webPartDefinition; } } 20 | 21 | public Guid Id 22 | { 23 | get 24 | { 25 | if (_webPartDefinition.IsPropertyAvailable("Id")) 26 | return _webPartDefinition.Id; 27 | return Guid.Empty; 28 | } 29 | } 30 | 31 | 32 | public void CloseWebPart() 33 | { 34 | _webPartDefinition.CloseWebPart(); 35 | _webPartDefinition.SaveWebPartChanges(); 36 | _webPartDefinition.Context.ExecuteQuery(); 37 | } 38 | 39 | public void DeleteWebPart() 40 | { 41 | _webPartDefinition.DeleteWebPart(); 42 | _webPartDefinition.Context.ExecuteQuery(); 43 | } 44 | 45 | public void MoveWebPartTo(string zoneID, int zoneIndex) 46 | { 47 | _webPartDefinition.MoveWebPartTo(zoneID, zoneIndex); 48 | _webPartDefinition.SaveWebPartChanges(); 49 | _webPartDefinition.Context.ExecuteQuery(); 50 | } 51 | 52 | public void OpenWebPart() 53 | { 54 | _webPartDefinition.OpenWebPart(); 55 | _webPartDefinition.SaveWebPartChanges(); 56 | _webPartDefinition.Context.ExecuteQuery(); 57 | } 58 | 59 | internal void SaveWebPartChanges() 60 | { 61 | _webPartDefinition.SaveWebPartChanges(); 62 | _webPartDefinition.Context.ExecuteQuery(); 63 | } 64 | 65 | private SPOWebPart _webPart = null; 66 | public SPOWebPart WebPart 67 | { 68 | get 69 | { 70 | if (_webPart != null) return _webPart; 71 | 72 | var webPart = _webPartDefinition.WebPart; 73 | SPOWebPart.LoadWebPart(SPOSiteContext.CurrentSiteContext.Context, webPart); 74 | _webPart = new SPOWebPart(webPart, this); 75 | return _webPart; 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Enums/WikiPageLayout.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.Enums 7 | { 8 | /// 9 | /// Out of the box wiki page layouts enumeration 10 | /// 11 | public enum WikiPageLayout 12 | { 13 | OneColumn = 0, 14 | OneColumnSideBar = 1, 15 | TwoColumns = 2, 16 | TwoColumnsHeader = 3, 17 | TwoColumnsHeaderFooter = 4, 18 | ThreeColumns = 5, 19 | ThreeColumnsHeader = 6, 20 | ThreeColumnsHeaderFooter = 7 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Exceptions/FileExistsException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.Exceptions 7 | { 8 | public class FileExistsException : Exception 9 | { 10 | public FileExistsException(string message) : base(message) { } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /GenerateHelp.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | [string] $TargetDir = $(throw "TargetDir is required!"), 3 | [string] $ConfigurationName = $(throw "ConfigurationName is required!") 4 | ) 5 | $path = Split-Path -parent $MyInvocation.MyCommand.Definition 6 | $helpAsm = "$($TargetDir)\..\..\ReferenceAssemblies\Lapointe.PowerShell.MamlGenerator.dll" 7 | $cmdletAsm = "$($TargetDir)\Lapointe.SharePointOnline.PowerShell.dll" 8 | Write-Host "Help generation work path: $path" 9 | Write-Host "Help generation maml assembly path: $helpAsm" 10 | Write-Host "Help generation cmdlet assembly path: $cmdletAsm" 11 | 12 | #Start-Process "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\gacutil.exe" -ArgumentList "/uf","Lapointe.PowerShell.MamlGenerator" 13 | #Start-Process "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\gacutil.exe" -ArgumentList "/uf","Lapointe.SharePointOnline.PowerShell" 14 | 15 | Write-Host "Loading help assembly..." 16 | [System.Reflection.Assembly]::LoadFrom($helpAsm) 17 | Write-Host "Loading cmdlet assembly..." 18 | $asm = [System.Reflection.Assembly]::LoadFrom($cmdletAsm) 19 | $asm 20 | Write-Host "Generating help..." 21 | [Lapointe.PowerShell.MamlGenerator.CmdletHelpGenerator]::GenerateHelp($asm, "$path", $true) 22 | 23 | if ($ConfigurationName -eq "Release") { 24 | & "C:\Program Files (x86)\WiX Toolset v3.8\bin\candle.exe" -v -out "$TargetDir\install.wixobj" "$TargetDir\install.wxs" 25 | & "C:\Program Files (x86)\WiX Toolset v3.8\bin\light.exe" -ext WixUIExtension -out "$TargetDir\Lapointe.SharePointOnline.PowerShell.msi" "$TargetDir\install.wixobj" 26 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software. 2 | 3 | 1. Definitions 4 | The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law. 5 | A "contribution" is the original software, or any additions or changes to the software. 6 | A "contributor" is any person that distributes its contribution under this license. 7 | "Licensed patents" are a contributor's patent claims that read directly on its contribution. 8 | 9 | 2. Grant of Rights 10 | (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. 11 | 12 | (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. 13 | 14 | 3. Conditions and Limitations 15 | (A) Reciprocal Grants- For any file you distribute that contains code from the software (in source code or binary format), you must provide recipients the source code to that file along with a copy of this license, which license will govern that file. You may license other files that are entirely your own work and do not contain code from the software under any terms you choose. 16 | (B) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. 17 | (C) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. 18 | (D) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. 19 | (E) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. 20 | (F) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. 21 | (G) You may not sell or offer for sale any portion of the software in source or binary form. 22 | -------------------------------------------------------------------------------- /Lapointe.SharePointOnline.PowerShell.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'Lapointe.SharePointOnline.PowerShell' 3 | # 4 | # Generated by: Gary Lapointe 5 | # 6 | # Generated on: 1/4/2014 7 | # 8 | @{ 9 | 10 | # Script module or binary module file associated with this manifest 11 | ModuleToProcess = 'Lapointe.SharePointOnline.PowerShell.dll' 12 | 13 | # Version number of this module. 14 | ModuleVersion = '1.3.0.0' 15 | 16 | # ID used to uniquely identify this module 17 | GUID = 'e0962691-21b0-4a83-a720-7e90dd43c0f8' 18 | 19 | # Author of this module 20 | Author = 'Gary Lapointe' 21 | 22 | # Company or vendor of this module 23 | CompanyName = 'Falchion Consulting, LLC' 24 | 25 | # Copyright statement for this module 26 | Copyright = '(c) Falchion Consulting. All rights reserved.' 27 | 28 | # Description of the functionality provided by this module 29 | Description = 'A Microsoft SharePoint Online Services Module for Windows PowerShell developed by Gary Lapointe.' 30 | 31 | # Minimum version of the Windows PowerShell engine required by this module 32 | PowerShellVersion = '3.0' 33 | 34 | # Name of the Windows PowerShell host required by this module 35 | PowerShellHostName = '' 36 | 37 | # Minimum version of the Windows PowerShell host required by this module 38 | PowerShellHostVersion = '' 39 | 40 | # Minimum version of the .NET Framework required by this module 41 | DotNetFrameworkVersion = '' 42 | 43 | # Minimum version of the common language runtime (CLR) required by this module 44 | CLRVersion = '4.0' 45 | 46 | # Processor architecture (None, X86, Amd64, IA64) required by this module 47 | ProcessorArchitecture = 'AMD64' 48 | 49 | # Modules that must be imported into the global environment prior to importing this module 50 | RequiredModules = @() 51 | 52 | # Assemblies that must be loaded prior to importing this module 53 | RequiredAssemblies = @() 54 | 55 | # Script files (.ps1) that are run in the caller's environment prior to importing this module 56 | ScriptsToProcess = @() 57 | 58 | # Type files (.ps1xml) to be loaded when importing this module 59 | TypesToProcess = @() 60 | 61 | # Format files (.ps1xml) to be loaded when importing this module 62 | FormatsToProcess = @('Lapointe.SharePointOnline.PowerShell.ps1xml') 63 | 64 | # Modules to import as nested modules of the module specified in ModuleToProcess 65 | NestedModules = @() 66 | 67 | # Functions to export from this module 68 | FunctionsToExport = '*' 69 | 70 | # Cmdlets to export from this module 71 | CmdletsToExport = '*' 72 | 73 | # Variables to export from this module 74 | VariablesToExport = '*' 75 | 76 | # Aliases to export from this module 77 | AliasesToExport = '*' 78 | 79 | # List of all modules packaged with this module 80 | ModuleList = @() 81 | 82 | # List of all files packaged with this module 83 | FileList = @() 84 | 85 | # Private data to pass to the module specified in ModuleToProcess 86 | PrivateData = '' 87 | 88 | # HelpInfo URI of this module 89 | #HelpInfoURI = '' 90 | 91 | } 92 | 93 | -------------------------------------------------------------------------------- /Lapointe.SharePointOnline.PowerShell.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30723.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lapointe.SharePointOnline.PowerShell", "Lapointe.SharePointOnline.PowerShell.csproj", "{5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | DebugFoundation|Any CPU = DebugFoundation|Any CPU 12 | DebugMOSS|Any CPU = DebugMOSS|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | ReleaseFoundation|Any CPU = ReleaseFoundation|Any CPU 15 | ReleaseMOSS|Any CPU = ReleaseMOSS|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.DebugFoundation|Any CPU.ActiveCfg = Debug|Any CPU 21 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.DebugFoundation|Any CPU.Build.0 = Debug|Any CPU 22 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.DebugMOSS|Any CPU.ActiveCfg = Debug|Any CPU 23 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.DebugMOSS|Any CPU.Build.0 = Debug|Any CPU 24 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.ReleaseFoundation|Any CPU.ActiveCfg = Release|Any CPU 27 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.ReleaseFoundation|Any CPU.Build.0 = Release|Any CPU 28 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.ReleaseMOSS|Any CPU.ActiveCfg = Release|Any CPU 29 | {5F11E4D5-CDDB-47E9-AB82-69C26C2EEE33}.ReleaseMOSS|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /PipeBind/CmdletPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 7 | { 8 | public abstract class CmdletPipeBind where CmdletObject: class 9 | { 10 | protected CmdletPipeBind() 11 | { 12 | } 13 | 14 | protected CmdletPipeBind(CmdletObject inputObject) 15 | { 16 | if (inputObject == null) 17 | { 18 | throw new ArgumentNullException("inputObject"); 19 | } 20 | this.Discover(inputObject); 21 | } 22 | 23 | public static void CheckUrlSchema(string name, Uri uri) 24 | { 25 | if (uri == null) 26 | { 27 | throw new ArgumentNullException("uri"); 28 | } 29 | if ((uri.Scheme != Uri.UriSchemeHttp) && (uri.Scheme != Uri.UriSchemeHttps)) 30 | { 31 | throw new ArgumentException(name); 32 | } 33 | } 34 | 35 | protected abstract void Discover(CmdletObject instance); 36 | public abstract CmdletObject Read(); 37 | public static void ValidateNotNull(string name, object value) 38 | { 39 | if (value == null) 40 | { 41 | throw new ArgumentNullException(name); 42 | } 43 | } 44 | 45 | public static void ValidateString(string name, string value) 46 | { 47 | CmdletPipeBind.ValidateNotNull(name, value); 48 | if (value.Trim().Length == 0) 49 | { 50 | throw new ArgumentException(name); 51 | } 52 | } 53 | 54 | public static void ValidateUri(string name, Uri uri) 55 | { 56 | CmdletPipeBind.CheckUrlSchema(name, uri); 57 | } 58 | 59 | public static void ValidateUrl(string name, string url) 60 | { 61 | Uri uri; 62 | CmdletPipeBind.ValidateString(name, url); 63 | try 64 | { 65 | uri = new Uri(url); 66 | } 67 | catch (UriFormatException) 68 | { 69 | throw new ArgumentException(name); 70 | } 71 | CmdletPipeBind.CheckUrlSchema(name, uri); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /PipeBind/CredentialPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Management.Automation.Host; 6 | using System.Text; 7 | 8 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 9 | { 10 | public class CredentialPipeBind : CmdletPipeBind 11 | { 12 | private PSCredential m_credential; 13 | private string m_userName; 14 | 15 | public CredentialPipeBind(PSCredential inputObject) : base(inputObject) 16 | { 17 | } 18 | 19 | public CredentialPipeBind(string inputObject) 20 | { 21 | this.m_userName = inputObject; 22 | } 23 | 24 | protected override void Discover(PSCredential instance) 25 | { 26 | if (instance != null) 27 | { 28 | this.m_userName = instance.UserName; 29 | this.m_credential = instance; 30 | } 31 | else 32 | { 33 | this.m_userName = null; 34 | this.m_credential = null; 35 | } 36 | } 37 | 38 | public static bool IsCredentialValid(PSCredential credential, PSHost host) 39 | { 40 | if (host == null) 41 | { 42 | throw new ArgumentNullException("host"); 43 | } 44 | if ((credential == null) || ((credential.Password != null) && (credential.Password.Length != 0))) 45 | { 46 | return true; 47 | } 48 | host.UI.WriteWarningLine("Password cannot be empty."); 49 | return false; 50 | } 51 | 52 | public static PSCredential PromptForCredentials(PSHost host, string userName) 53 | { 54 | if (host == null) 55 | { 56 | throw new ArgumentNullException("host"); 57 | } 58 | PSCredential credential = null; 59 | do 60 | { 61 | credential = host.UI.PromptForCredential("SharePoint Online PowerShell", "Enter your credentials.", (credential == null) ? userName : credential.UserName, string.Empty); 62 | } 63 | while (!IsCredentialValid(credential, host)); 64 | return credential; 65 | } 66 | 67 | public override PSCredential Read() 68 | { 69 | if (this.m_credential == null) 70 | { 71 | throw new InvalidOperationException("Can't read credentials without a PSHost."); 72 | } 73 | return this.m_credential; 74 | } 75 | 76 | public PSCredential Read(PSHost host) 77 | { 78 | if ((this.m_credential == null) || !IsCredentialValid(this.m_credential, host)) 79 | { 80 | this.m_credential = PromptForCredentials(host, this.m_userName); 81 | } 82 | return this.m_credential; 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /PipeBind/PropertiesPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Xml; 6 | 7 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 8 | { 9 | public sealed class PropertiesPipeBind : CmdletPipeBind> 10 | { 11 | private string _xml; 12 | private Dictionary _properties; 13 | 14 | public PropertiesPipeBind(Dictionary instance) : base(instance) 15 | { 16 | _properties = instance; 17 | } 18 | public PropertiesPipeBind(Hashtable instance) 19 | { 20 | Hashtable hash = instance.Clone() as Hashtable; 21 | _properties = new Dictionary(); 22 | foreach (var key in hash.Keys) 23 | { 24 | string keyValue = key.ToString(); 25 | _properties.Add(keyValue, hash[key]); 26 | } 27 | } 28 | public PropertiesPipeBind(XmlDocument instance) 29 | { 30 | _xml = instance.OuterXml; 31 | } 32 | 33 | public PropertiesPipeBind(string inputString) 34 | { 35 | XmlDocument xml = new XmlDocument(); 36 | try 37 | { 38 | if (File.Exists(inputString)) 39 | { 40 | xml.Load(inputString); 41 | } 42 | else 43 | { 44 | xml.LoadXml(inputString); 45 | } 46 | } 47 | catch 48 | { 49 | throw new Exception("The input string is not a valid XML file."); 50 | } 51 | _xml = xml.OuterXml; 52 | } 53 | 54 | 55 | 56 | protected override void Discover(Dictionary instance) 57 | { 58 | _properties = instance; 59 | } 60 | 61 | public override Dictionary Read() 62 | { 63 | if (_properties != null) 64 | return _properties; 65 | 66 | Dictionary props = new Dictionary(); 67 | XmlDocument xmlDoc = new XmlDocument(); 68 | xmlDoc.LoadXml(_xml); 69 | if (xmlDoc.DocumentElement == null) 70 | return props; 71 | 72 | foreach (XmlElement propElement in xmlDoc.DocumentElement.ChildNodes) 73 | { 74 | props.Add(propElement.Attributes["Name"].Value, propElement.InnerText.Trim()); 75 | } 76 | return props; 77 | } 78 | 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /PipeBind/SPOContentTypePipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Lapointe.SharePointOnline.PowerShell.Data.ContentTypes; 6 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 7 | using Microsoft.SharePoint.Client; 8 | 9 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 10 | { 11 | public sealed class SPOContentTypePipeBind 12 | { 13 | private string _name; 14 | private string _contentTypeId; 15 | private SPOContentType _spoContentType; 16 | private ContentType _contentType; 17 | 18 | public SPOContentTypePipeBind(SPOContentType spoContentType) 19 | { 20 | if ((spoContentType == null)) 21 | { 22 | throw new ArgumentNullException("The Content Type must be specified."); 23 | } 24 | _spoContentType = spoContentType; 25 | _contentType = spoContentType.ContentType; 26 | _name = spoContentType.Name; 27 | _contentTypeId = spoContentType.Id.StringValue; 28 | } 29 | public SPOContentTypePipeBind(ContentType contentType) 30 | { 31 | if ((contentType == null)) 32 | { 33 | throw new ArgumentNullException("The Content Type must be specified."); 34 | } 35 | _spoContentType = new SPOContentType(contentType); 36 | _contentType = contentType; 37 | _name = contentType.Name; 38 | _contentTypeId = contentType.Id.StringValue; 39 | } 40 | public SPOContentTypePipeBind(string name) 41 | { 42 | if (name.ToLower().StartsWith("0x0")) 43 | _contentTypeId = name; 44 | else 45 | _name = name; 46 | } 47 | public SPOContentTypePipeBind(ContentTypeId contentTypeId) 48 | { 49 | _contentTypeId = contentTypeId.StringValue; 50 | } 51 | 52 | public SPOContentType Read(Web web) 53 | { 54 | return Read(web.AvailableContentTypes); 55 | } 56 | public SPOContentType Read(List list) 57 | { 58 | return Read(list.ContentTypes); 59 | } 60 | 61 | private SPOContentType Read(ContentTypeCollection contentTypes) 62 | { 63 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 64 | ContentType contentType = null; 65 | if (_contentTypeId != null) 66 | { 67 | contentType = contentTypes.GetById(_contentTypeId); 68 | } 69 | else if (!string.IsNullOrEmpty(_name)) 70 | { 71 | ctx.Load(contentTypes); 72 | ctx.ExecuteQuery(); 73 | 74 | foreach (ContentType ct in contentTypes) 75 | { 76 | if (ct.Name.ToLower() == _name.ToLower()) 77 | { 78 | contentType = ct; 79 | break; 80 | } 81 | } 82 | 83 | } 84 | if (contentType != null) 85 | { 86 | SPOContentType.LoadContentType(ctx, contentType); 87 | if (contentType.ServerObjectIsNull.Value) 88 | return null; 89 | 90 | return new SPOContentType(contentType); 91 | } 92 | 93 | return null; 94 | } 95 | public void Refresh() 96 | { 97 | if (_spoContentType != null) 98 | _spoContentType.Refresh(); 99 | else if (_contentType != null) 100 | new SPOContentType(_contentType).Refresh(); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /PipeBind/SPOFieldPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Lapointe.SharePointOnline.PowerShell.Data.Fields; 6 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 7 | using Microsoft.SharePoint.Client; 8 | 9 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 10 | { 11 | public sealed class SPOFieldPipeBind 12 | { 13 | private Guid _fieldId; 14 | private string _fieldNameOrTitle; 15 | private Field _field = null; 16 | 17 | public SPOFieldPipeBind(SPOField spoField) 18 | { 19 | if ((spoField == null) || spoField.Id == Guid.Empty) 20 | { 21 | throw new ArgumentNullException("The Field ID must be specified."); 22 | } 23 | _fieldId = spoField.Id; 24 | _field = spoField.Field; 25 | } 26 | public SPOFieldPipeBind(Field field) 27 | { 28 | if ((field == null) || field.Id == Guid.Empty) 29 | { 30 | throw new ArgumentNullException("The Field ID must be specified."); 31 | } 32 | _fieldId = field.Id; 33 | _field = field; 34 | } 35 | public SPOFieldPipeBind(Guid fieldId) 36 | { 37 | _fieldId = fieldId; 38 | } 39 | 40 | public SPOFieldPipeBind(string fieldNameOrTitle) 41 | { 42 | _fieldNameOrTitle = fieldNameOrTitle; 43 | } 44 | 45 | public string FieldNameOrTitle 46 | { 47 | get { return _fieldNameOrTitle; } 48 | } 49 | 50 | public Guid FieldId 51 | { 52 | get { return _fieldId; } 53 | } 54 | 55 | public SPOField Read(Web web) 56 | { 57 | return Read(web.AvailableFields); 58 | } 59 | public SPOField Read(List list) 60 | { 61 | return Read(list.Fields); 62 | } 63 | 64 | private SPOField Read(FieldCollection fields) 65 | { 66 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 67 | Field field = null; 68 | if (this.FieldId != Guid.Empty) 69 | { 70 | field = fields.GetById(this.FieldId); 71 | } 72 | else if (!string.IsNullOrEmpty(this.FieldNameOrTitle)) 73 | { 74 | field = fields.GetByInternalNameOrTitle(this.FieldNameOrTitle); 75 | } 76 | if (field != null) 77 | { 78 | _field = field; 79 | ctx.Load(field); 80 | ctx.ExecuteQuery(); 81 | 82 | if (field.ServerObjectIsNull.Value) 83 | return null; 84 | 85 | return new SPOField(_field); 86 | } 87 | return null; 88 | } 89 | public override string ToString() 90 | { 91 | if (this.FieldId != Guid.Empty) 92 | return this.FieldId.ToString(); 93 | else if (!string.IsNullOrEmpty(this.FieldNameOrTitle)) 94 | return this.FieldNameOrTitle; 95 | return "Field"; 96 | } 97 | public void Refresh() 98 | { 99 | if (_field != null) 100 | new SPOField(_field).Refresh(); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /PipeBind/SPOFilePipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 6 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 7 | using Microsoft.SharePoint.Client; 8 | 9 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 10 | { 11 | public sealed class SPOFilePipeBind 12 | { 13 | private string _serverRelativeUrl; 14 | 15 | public SPOFilePipeBind(Microsoft.SharePoint.Client.File file) 16 | { 17 | if (!file.IsPropertyAvailable("ServerRelativeUrl")) 18 | { 19 | file.Context.Load(file, f => f.ServerRelativeUrl); 20 | file.Context.ExecuteQuery(); 21 | } 22 | _serverRelativeUrl = file.ServerRelativeUrl; 23 | } 24 | 25 | public SPOFilePipeBind(SPOFile file) 26 | { 27 | _serverRelativeUrl = file.ServerRelativeUrl; 28 | } 29 | 30 | public SPOFilePipeBind(SPOWikiPage wikiPage) : this((SPOFile)wikiPage) { } 31 | 32 | public SPOFilePipeBind(string serverRelativeUrl) 33 | { 34 | _serverRelativeUrl = serverRelativeUrl; 35 | } 36 | 37 | public SPOFile Read(Web web) 38 | { 39 | SPOWeb spoWeb = new SPOWeb(web); 40 | return Read(spoWeb); 41 | } 42 | 43 | public SPOFile Read(SPOWeb spoWeb) 44 | { 45 | if (string.IsNullOrEmpty(_serverRelativeUrl)) 46 | throw new ArgumentNullException("The server relative URL was not provided."); 47 | 48 | return spoWeb.GetFileByServerRelativeUrl(_serverRelativeUrl); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /PipeBind/SPOFolderPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Lapointe.SharePointOnline.PowerShell.Data.Lists; 6 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 7 | using Microsoft.SharePoint.Client; 8 | 9 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 10 | { 11 | public sealed class SPOFolderPipeBind 12 | { 13 | private string _serverRelativeUrl; 14 | 15 | public SPOFolderPipeBind(Microsoft.SharePoint.Client.Folder folder) 16 | { 17 | if (!folder.IsPropertyAvailable("ServerRelativeUrl")) 18 | { 19 | folder.Context.Load(folder, f => f.ServerRelativeUrl); 20 | folder.Context.ExecuteQuery(); 21 | } 22 | _serverRelativeUrl = folder.ServerRelativeUrl; 23 | } 24 | 25 | public SPOFolderPipeBind(SPOFolder folder) 26 | { 27 | _serverRelativeUrl = folder.ServerRelativeUrl; 28 | } 29 | 30 | public SPOFolderPipeBind(string serverRelativeUrl) 31 | { 32 | _serverRelativeUrl = serverRelativeUrl; 33 | } 34 | 35 | public SPOFolder Read(Web web) 36 | { 37 | SPOWeb spoWeb = new SPOWeb(web); 38 | return Read(spoWeb); 39 | } 40 | 41 | public SPOFolder Read(SPOWeb spoWeb) 42 | { 43 | if (string.IsNullOrEmpty(_serverRelativeUrl)) 44 | throw new ArgumentNullException("The server relative URL was not provided."); 45 | 46 | return spoWeb.GetFolderByServerRelativeUrl(_serverRelativeUrl); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /PipeBind/SPOGroupPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Lapointe.SharePointOnline.PowerShell.Data.Principals; 6 | using Microsoft.SharePoint.Client; 7 | 8 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 9 | { 10 | public class SPOGroupPipeBind 11 | { 12 | private SPOGroup _group = null; 13 | 14 | public SPOGroupPipeBind(Group group) 15 | { 16 | _group = new SPOGroup(group); 17 | } 18 | 19 | public SPOGroupPipeBind(SPOGroup group) 20 | { 21 | _group = group; 22 | } 23 | 24 | public SPOGroupPipeBind(int id) 25 | { 26 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 27 | var group = ctx.Site.RootWeb.SiteGroups.GetById(id); 28 | ctx.Load(group); 29 | ctx.ExecuteQuery(); 30 | _group = new SPOGroup(group); 31 | } 32 | 33 | public SPOGroupPipeBind(string name) 34 | { 35 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 36 | var group = ctx.Site.RootWeb.SiteGroups.GetByName(name); 37 | ctx.Load(group); 38 | ctx.ExecuteQuery(); 39 | _group = new SPOGroup(group); 40 | } 41 | 42 | public SPOGroup Read() 43 | { 44 | return _group; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /PipeBind/SPOTermGroupPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Lapointe.SharePointOnline.PowerShell.Data.Taxonomy; 3 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 4 | using Microsoft.SharePoint.Client.Taxonomy; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 7 | { 8 | public sealed class SPOTermGroupPipeBind : CmdletPipeBind 9 | { 10 | private string _name = null; 11 | private Guid _groupId = Guid.Empty; 12 | 13 | public SPOTermGroupPipeBind(SPOTermGroup group) 14 | { 15 | _groupId = group.Id; 16 | } 17 | 18 | public SPOTermGroupPipeBind(TermGroup group) 19 | { 20 | _groupId = group.Id; 21 | } 22 | 23 | public SPOTermGroupPipeBind(Guid groupId) 24 | { 25 | _groupId = groupId; 26 | } 27 | public SPOTermGroupPipeBind(string name) 28 | { 29 | _name = name; 30 | } 31 | 32 | protected override void Discover(TermGroup instance) 33 | { 34 | _groupId = instance.Id; 35 | } 36 | 37 | 38 | 39 | public override TermGroup Read() 40 | { 41 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 42 | TaxonomySession ts = TaxonomySession.GetTaxonomySession(ctx); 43 | var termStores = ts.TermStores; 44 | ctx.Load(termStores); 45 | ctx.ExecuteQuery(); 46 | 47 | foreach (TermStore termStore in termStores) 48 | { 49 | TermGroup group = null; 50 | if (!string.IsNullOrEmpty(_name)) 51 | group = termStore.Groups.GetByName(_name); 52 | else 53 | group = termStore.Groups.GetById(_groupId); 54 | ctx.Load(group); 55 | ctx.ExecuteQuery(); 56 | if (group != null && !group.ServerObjectIsNull.Value) 57 | return group; 58 | } 59 | return null; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /PipeBind/SPOTermPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Lapointe.SharePointOnline.PowerShell.Data.Taxonomy; 3 | using Microsoft.SharePoint.Client.Taxonomy; 4 | 5 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 6 | { 7 | public sealed class SPOTermPipeBind : CmdletPipeBind 8 | { 9 | private Guid _termId; 10 | 11 | public SPOTermPipeBind(Term term) 12 | { 13 | _termId = term.Id; 14 | } 15 | public SPOTermPipeBind(SPOTerm term) 16 | { 17 | _termId = term.Id; 18 | } 19 | public SPOTermPipeBind(Guid termId) 20 | { 21 | _termId = termId; 22 | } 23 | 24 | protected override void Discover(Term instance) 25 | { 26 | _termId = instance.Id; 27 | } 28 | 29 | public override Term Read() 30 | { 31 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 32 | TaxonomySession ts = TaxonomySession.GetTaxonomySession(ctx); 33 | var term = ts.GetTerm(_termId); 34 | ctx.Load(term); 35 | ctx.ExecuteQuery(); 36 | return term; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /PipeBind/SPOTermSetPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Lapointe.SharePointOnline.PowerShell.Data.Taxonomy; 3 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 4 | using Microsoft.SharePoint.Client.Taxonomy; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 7 | { 8 | public sealed class SPOTermSetPipeBind : CmdletPipeBind 9 | { 10 | private Guid _termSetId; 11 | 12 | public SPOTermSetPipeBind(TermSet termSet) 13 | { 14 | _termSetId = termSet.Id; 15 | } 16 | public SPOTermSetPipeBind(SPOTermSet termSet) 17 | { 18 | _termSetId = termSet.Id; 19 | } 20 | public SPOTermSetPipeBind(Guid termSetId) 21 | { 22 | _termSetId = termSetId; 23 | } 24 | 25 | protected override void Discover(TermSet instance) 26 | { 27 | _termSetId = instance.Id; 28 | } 29 | 30 | public override TermSet Read() 31 | { 32 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 33 | TaxonomySession ts = TaxonomySession.GetTaxonomySession(ctx); 34 | var termStores = ts.TermStores; 35 | ctx.Load(termStores); 36 | ctx.ExecuteQuery(); 37 | 38 | foreach (TermStore termStore in termStores) 39 | { 40 | TermSet termSet = termStore.GetTermSet(_termSetId); 41 | ctx.Load(termSet); 42 | ctx.ExecuteQuery(); 43 | if (termSet != null && !termSet.ServerObjectIsNull.Value) 44 | return termSet; 45 | } 46 | return null; 47 | 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /PipeBind/SPOTermStorePipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Lapointe.SharePointOnline.PowerShell.Data.Taxonomy; 3 | using Lapointe.SharePointOnline.PowerShell.PipeBind; 4 | using Microsoft.SharePoint.Client.Taxonomy; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 7 | { 8 | public sealed class SPOTermStorePipeBind : CmdletPipeBind 9 | { 10 | private Guid _termStoreId; 11 | private TermStore _termStore = null; 12 | 13 | public SPOTermStorePipeBind(TermStore termStore) 14 | { 15 | _termStoreId = termStore.Id; 16 | } 17 | public SPOTermStorePipeBind(SPOTermStore termStore) 18 | { 19 | _termStoreId = termStore.Id; 20 | } 21 | public SPOTermStorePipeBind(string name) 22 | { 23 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 24 | TaxonomySession ts = TaxonomySession.GetTaxonomySession(ctx); 25 | _termStore = ts.TermStores.GetByName(name); 26 | ctx.Load(_termStore); 27 | ctx.Load(_termStore, ts1 => ts1.ContentTypePublishingHub); 28 | ctx.ExecuteQuery(); 29 | _termStoreId = _termStore.Id; 30 | } 31 | public SPOTermStorePipeBind(Guid termStoreId) 32 | { 33 | _termStoreId = termStoreId; 34 | } 35 | public SPOTermStorePipeBind(int index) 36 | { 37 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 38 | TaxonomySession ts = TaxonomySession.GetTaxonomySession(ctx); 39 | ctx.Load(ts.TermStores); 40 | ctx.ExecuteQuery(); 41 | 42 | _termStore = ts.TermStores[0]; 43 | ctx.Load(_termStore); 44 | ctx.Load(_termStore, ts1 => ts1.ContentTypePublishingHub); 45 | ctx.ExecuteQuery(); 46 | _termStoreId = _termStore.Id; 47 | } 48 | 49 | protected override void Discover(TermStore instance) 50 | { 51 | _termStoreId = instance.Id; 52 | } 53 | 54 | public override TermStore Read() 55 | { 56 | if (_termStore != null) 57 | return _termStore; 58 | 59 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 60 | TaxonomySession ts = TaxonomySession.GetTaxonomySession(ctx); 61 | var termStore = ts.TermStores.GetById(_termStoreId); 62 | ctx.Load(termStore); 63 | ctx.Load(termStore, ts1 => ts1.ContentTypePublishingHub); 64 | ctx.ExecuteQuery(); 65 | return termStore; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /PipeBind/SPOUserPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Lapointe.SharePointOnline.PowerShell.Data.Principals; 6 | using Microsoft.SharePoint.Client; 7 | 8 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 9 | { 10 | public class SPOUserPipeBind 11 | { 12 | private SPOUser _user = null; 13 | 14 | public SPOUserPipeBind(User user) 15 | { 16 | _user = new SPOUser(user); 17 | } 18 | 19 | public SPOUserPipeBind(SPOUser user) 20 | { 21 | _user = user; 22 | } 23 | 24 | public SPOUserPipeBind(int id) 25 | { 26 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 27 | var user = ctx.Site.RootWeb.SiteUsers.GetById(id); 28 | ctx.Load(user); 29 | ctx.ExecuteQuery(); 30 | _user = new SPOUser(user); 31 | } 32 | 33 | public SPOUserPipeBind(string email) 34 | { 35 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 36 | var user = ctx.Site.RootWeb.SiteUsers.GetByEmail(email); 37 | ctx.Load(user); 38 | ctx.ExecuteQuery(); 39 | _user = new SPOUser(user); 40 | } 41 | 42 | public SPOUser Read() 43 | { 44 | return _user; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /PipeBind/SPOWebPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 6 | using Microsoft.SharePoint.Client; 7 | 8 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 9 | { 10 | public class SPOWebPipeBind : CmdletPipeBind 11 | { 12 | private string _surl = null; 13 | private Web _web = null; 14 | 15 | public SPOWebPipeBind(Guid inputObject) 16 | { 17 | var ctx = SPOSiteContext.CurrentSiteContext.Context; 18 | _web = ctx.Site.OpenWebById(inputObject); 19 | ctx.Load(_web, w => w.ServerRelativeUrl, w => w.HasUniqueRoleAssignments); 20 | ctx.ExecuteQuery(); 21 | _surl = _web.ServerRelativeUrl; 22 | } 23 | public SPOWebPipeBind(string inputObject) : base(inputObject) 24 | { 25 | _surl = inputObject; 26 | } 27 | public SPOWebPipeBind(Uri inputObject) 28 | { 29 | _surl = inputObject.PathAndQuery; 30 | } 31 | public SPOWebPipeBind(SPOWeb inputObject) 32 | { 33 | _web = inputObject.Web; 34 | _surl = inputObject.ServerRelativeUrl; 35 | } 36 | public SPOWebPipeBind(Web inputObject) 37 | { 38 | _web = inputObject; 39 | if (!inputObject.IsPropertyAvailable("ServerRelativeUrl")) 40 | { 41 | inputObject.Context.Load(inputObject, w => w.ServerRelativeUrl); 42 | inputObject.Context.ExecuteQuery(); 43 | } 44 | _surl = inputObject.ServerRelativeUrl; 45 | } 46 | 47 | protected override void Discover(string instance) 48 | { 49 | _surl = instance; 50 | } 51 | 52 | public override string Read() 53 | { 54 | return _surl; 55 | } 56 | 57 | public override string ToString() 58 | { 59 | return _surl; 60 | } 61 | internal void Refresh() 62 | { 63 | if (_web != null) 64 | new SPOWeb(_web).Refresh(); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /PipeBind/UrlPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 7 | { 8 | public class UrlPipeBind : CmdletPipeBind 9 | { 10 | private Uri m_url; 11 | 12 | public UrlPipeBind(string inputObject) : base(new Uri(inputObject)) 13 | { 14 | } 15 | 16 | public UrlPipeBind(Uri inputObject) : base(inputObject) 17 | { 18 | } 19 | 20 | protected override void Discover(Uri instance) 21 | { 22 | this.m_url = instance; 23 | } 24 | 25 | public override Uri Read() 26 | { 27 | return this.m_url; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /PipeBind/XmlDocumentPipeBind.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Xml; 7 | 8 | namespace Lapointe.SharePointOnline.PowerShell.PipeBind 9 | { 10 | public class XmlDocumentPipeBind : CmdletPipeBind 11 | { 12 | private string _xml; 13 | 14 | public XmlDocumentPipeBind(XmlDocument instance) 15 | : base(instance) 16 | { 17 | _xml = instance.OuterXml; 18 | } 19 | 20 | public XmlDocumentPipeBind(string inputString) 21 | { 22 | XmlDocument xml = new XmlDocument(); 23 | try 24 | { 25 | if (File.Exists(inputString)) 26 | { 27 | xml.Load(inputString); 28 | } 29 | else 30 | { 31 | xml.LoadXml(inputString); 32 | } 33 | } 34 | catch 35 | { 36 | throw new ArgumentException("The input string is not a valid XML file."); 37 | } 38 | _xml = xml.OuterXml; 39 | } 40 | 41 | 42 | 43 | protected override void Discover(XmlDocument instance) 44 | { 45 | _xml = instance.OuterXml; 46 | } 47 | 48 | public override XmlDocument Read() 49 | { 50 | XmlDocument xml = new XmlDocument(); 51 | xml.LoadXml(_xml); 52 | return xml; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Lapointe.SharePointOnline.PowerShell")] 9 | [assembly: AssemblyDescription("\r\n > For more information on this cmdlet and others:\r\n > http://blog.falchionconsulting.com/\r\n > Use of this cmdlet is at your own risk.\r\n > Gary Lapointe assumes no liability.")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Falchion Consulting, LLC")] 12 | [assembly: AssemblyProduct("Lapointe.SharePointOnline.PowerShell")] 13 | [assembly: AssemblyCopyright("Copyright 2016 Falchion Consulting, LLC")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e0962691-21b0-4a83-a720-7e90dd43c0f8")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.3.1.0")] 36 | [assembly: AssemblyFileVersion("1.3.1.0")] 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PowerShell-SPOCmdlets 2 | A Microsoft SharePoint Online Services Module for Windows PowerShell developed by Gary Lapointe. 3 | -------------------------------------------------------------------------------- /ReferenceAssemblies/Lapointe.PowerShell.MamlGenerator.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Lapointe.PowerShell.MamlGenerator.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.Office.Client.Education.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.Office.Client.Education.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.Office.Client.Policy.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.Office.Client.Policy.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.Office.Client.TranslationServices.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.Office.Client.TranslationServices.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.SharePoint.Client.DocumentManagement.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.SharePoint.Client.DocumentManagement.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.SharePoint.Client.Publishing.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.SharePoint.Client.Publishing.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.SharePoint.Client.Runtime.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.SharePoint.Client.Runtime.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.SharePoint.Client.Search.Applications.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.SharePoint.Client.Search.Applications.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.SharePoint.Client.Search.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.SharePoint.Client.Search.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.SharePoint.Client.Taxonomy.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.SharePoint.Client.Taxonomy.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.SharePoint.Client.UserProfiles.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.SharePoint.Client.UserProfiles.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.SharePoint.Client.WorkflowServices.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.SharePoint.Client.WorkflowServices.dll -------------------------------------------------------------------------------- /ReferenceAssemblies/Microsoft.SharePoint.Client.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glapointe/PowerShell-SPOCmdlets/2c1aff807930be3e21f40765272d1db36ce6f346/ReferenceAssemblies/Microsoft.SharePoint.Client.dll -------------------------------------------------------------------------------- /SPOSiteContext.cs: -------------------------------------------------------------------------------- 1 | using Lapointe.SharePointOnline.PowerShell.Data.Sites; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Lapointe.SharePointOnline.PowerShell 8 | { 9 | public class SPOSiteContext 10 | { 11 | private static SPOSiteContext _currentSiteContext = null; 12 | private SPOSite _site = null; 13 | private SPOSite _detailedSite = null; 14 | 15 | public SPOSiteContext(CmdletContext context) 16 | { 17 | if (context == null) 18 | { 19 | throw new ArgumentNullException("context"); 20 | } 21 | this.Context = context; 22 | } 23 | 24 | public CmdletContext Context { get; protected set; } 25 | 26 | internal static SPOSiteContext CurrentSiteContext { 27 | get { return _currentSiteContext; } 28 | set { _currentSiteContext = value; } 29 | } 30 | 31 | public string Url 32 | { 33 | get 34 | { 35 | return this.Context.Url; 36 | } 37 | } 38 | 39 | public SPOSite GetSite(bool detailed) 40 | { 41 | if (_detailedSite != null) return _detailedSite; 42 | if (_site != null && !detailed) return _site; 43 | 44 | var site = Context.Site; 45 | SPOSite.LoadSite(Context, site, detailed); 46 | 47 | return new SPOSite(site); 48 | } 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /SPOSiteHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Management.Automation.Host; 6 | using System.Text; 7 | using Microsoft.SharePoint.Client; 8 | using Microsoft.Win32; 9 | using System.Net; 10 | 11 | namespace Lapointe.SharePointOnline.PowerShell 12 | { 13 | internal class SPOSiteHelper 14 | { 15 | internal static string HEADER_SHAREPOINT_VERSION = "MicrosoftSharePointTeamServices"; 16 | 17 | internal static SPOSiteContext InstantiateSPOSiteContext(Uri url, PSCredential credentials, PSHost host) 18 | { 19 | return InstantiateSPOSiteContext(url, credentials, host, false); 20 | } 21 | internal static SPOSiteContext InstantiateSPOSiteContext(Uri url, PSCredential credentials, PSHost host, bool isNetworkCredentials) 22 | { 23 | if (!IsValidServerVersion(url)) 24 | { 25 | throw new InvalidOperationException("Could not connect to SharePoint Online: unsupported version of service."); 26 | } 27 | CmdletContext context = new CmdletContext(url.AbsoluteUri, host); 28 | if (isNetworkCredentials) 29 | { 30 | context.AuthenticationMode = ClientAuthenticationMode.Default; 31 | context.Credentials = credentials.GetNetworkCredential(); 32 | } 33 | else 34 | { 35 | context.Credentials = new SharePointOnlineCredentials(credentials.UserName, credentials.Password); 36 | } 37 | 38 | if (context.HasPendingRequest) 39 | context.ExecuteQuery(); 40 | return new SPOSiteContext(context); 41 | } 42 | 43 | internal static bool IsValidServerVersion(Uri url) 44 | { 45 | using (WebClient client = new WebClient()) 46 | { 47 | client.Headers[HttpRequestHeader.UserAgent] = CmdletContext.GetUserAgent(); 48 | string str = null; 49 | try 50 | { 51 | client.DownloadData(url); 52 | str = client.ResponseHeaders[HEADER_SHAREPOINT_VERSION]; 53 | } 54 | catch (WebException exception) 55 | { 56 | if ((exception != null) && (exception.Response != null)) 57 | { 58 | str = exception.Response.Headers[HEADER_SHAREPOINT_VERSION]; 59 | } 60 | } 61 | if (str == null) 62 | { 63 | throw new InvalidOperationException("Could not connect to SharePoint Online."); 64 | } 65 | if (!string.IsNullOrEmpty(str)) 66 | { 67 | Version version; 68 | string str2 = str.Split(new char[] { ',' })[0]; 69 | if (Version.TryParse(str2, out version)) 70 | { 71 | return (version.Major >= 15); 72 | } 73 | } 74 | } 75 | return false; 76 | } 77 | 78 | public static void ValidateUri(string name, Uri uri) 79 | { 80 | if ((string.IsNullOrEmpty(name) || (uri == null)) || ((uri.Scheme != Uri.UriSchemeHttp) && (uri.Scheme != Uri.UriSchemeHttps))) 81 | { 82 | throw new ArgumentException(name); 83 | } 84 | } 85 | 86 | public static void ValidateUrl(string name, string url) 87 | { 88 | Uri uri; 89 | if (string.IsNullOrEmpty(url)) 90 | { 91 | throw new ArgumentException(name); 92 | } 93 | try 94 | { 95 | uri = new Uri(url); 96 | } 97 | catch (UriFormatException) 98 | { 99 | throw new ArgumentException(name); 100 | } 101 | ValidateUri(name, uri); 102 | } 103 | 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Validators/ValidateDirectoryExistsAndValidFileNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Microsoft.SharePoint; 3 | using System.Management.Automation; 4 | using System.Management.Automation.Internal; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.Validators 7 | { 8 | 9 | public class ValidateDirectoryExistsAndValidFileNameAttribute : ValidateArgumentsAttribute 10 | { 11 | protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) 12 | { 13 | string str = arguments as string; 14 | if (string.IsNullOrEmpty(str)) 15 | { 16 | throw new PSArgumentNullException(); 17 | } 18 | 19 | FileInfo info = new FileInfo(str); 20 | if (info.Directory.Exists) 21 | { 22 | if (info.Name.EndsWith("\\") || info.Name.EndsWith("/")) 23 | { 24 | throw new PSArgumentException("Filename not specified"); 25 | } 26 | } 27 | else 28 | { 29 | throw new PSArgumentException("Directory not found"); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Validators/ValidateDirectoryExistsAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Microsoft.SharePoint; 3 | using System.Management.Automation; 4 | using System.Management.Automation.Internal; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.Validators 7 | { 8 | 9 | public class ValidateDirectoryExistsAttribute : ValidateArgumentsAttribute 10 | { 11 | protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) 12 | { 13 | string str = arguments as string; 14 | if (string.IsNullOrEmpty(str)) 15 | { 16 | throw new PSArgumentNullException(); 17 | } 18 | 19 | if (!Directory.Exists(str)) 20 | { 21 | throw new PSArgumentException("Directory not found"); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Validators/ValidateFileExistsAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Microsoft.SharePoint; 3 | using System.Management.Automation; 4 | using System.Management.Automation.Internal; 5 | 6 | namespace Lapointe.SharePointOnline.PowerShell.Validators 7 | { 8 | 9 | public class ValidateFileExistsAttribute : ValidateArgumentsAttribute 10 | { 11 | protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) 12 | { 13 | string str = arguments as string; 14 | if (string.IsNullOrEmpty(str)) 15 | { 16 | throw new PSArgumentNullException(); 17 | } 18 | 19 | if (!File.Exists(str)) 20 | { 21 | throw new PSArgumentException("File not found"); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | --------------------------------------------------------------------------------