private void btnRestore_Click(object sender, EventArgs e) { SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://localhost")); StreamWriter writeMy = new StreamWriter(txtPath.Text + "restoremySite.txt", false); writeMy.WriteLine("Add-PsSnapin Microsoft.SharePoint.PowerShell"); writeMy.WriteLine("$dbName=\"WSS_Content\""); writeMy.WriteLine("$serverName=\"qx2012\""); writeMy.WriteLine("$sourcePath=\"d:\\Backup\\\""); string loginName; string url; foreach (SPSite mySite in webApp.Sites) { url = mySite.Url; if (url.IndexOf("/personal/") > 0) { loginName = url.Substring(url.LastIndexOf("/") + 1); //if (chkNew.Checked) //{ // //writeMy.WriteLine("remove-spsite -identity " + url + "-GradualDelete -Confirm:$False"); // writeMy.WriteLine("New-SPSite -URL " + url + " -OwnerAlias ccc\\" + loginName + " -Confirm:$False"); //} writeMy.WriteLine("Restore-SPSite " + url + " -Path $sourcePath'" + loginName + ".bak' -DatabaseServer $serverName -DatabaseName $dbName -force -Confirm:$False"); } } writeMy.Close(); writeMy.Dispose(); MessageBox.Show("ok"); }
/// <summary> /// Method to set a web application value /// </summary> /// <param name="webApplicationUrl">The url of the Web Application</param> /// <param name="propertyBagValues">The property bag values to insert</param> public void SetWebApplicationValue(Uri webApplicationUrl, IList <PropertyBagValue> propertyBagValues) { var webApplication = SPWebApplication.Lookup(webApplicationUrl); this.Set(webApplication.Properties, null, propertyBagValues, webApplicationUrl.AbsoluteUri); webApplication.Update(); }
public HashSet <SPPrincipal> GetPrincipals(string url) { HashSet <SPPrincipal> result = new HashSet <SPPrincipal>(); SPSecurity.RunWithElevatedPrivileges(delegate() { SPWebApplication webApplication = SPWebApplication.Lookup(new Uri(url)); foreach (SPSite site in webApplication.Sites) { foreach (SPWeb web in site.AllWebs) { foreach (SPUser user in web.AllUsers) { if (!result.Any(p => p.LoginName == user.LoginName)) { result.Add(user); } } } } }); return(result); }
public SPWebApplication GetWebApplicationForUrl(string url) { Uri uri = new Uri(url); SPWebApplication app = SPWebApplication.Lookup(uri); return(app); }
public SharePointSiteDiskSpace[] CalculateSiteCollectionDiskSpace(Uri root, string[] urls) { WindowsImpersonationContext wic = null; try { wic = WindowsIdentity.GetCurrent().Impersonate(); SPWebApplication rootWebApplication = SPWebApplication.Lookup(root); List <SharePointSiteDiskSpace> ret = new List <SharePointSiteDiskSpace>(); foreach (string url in urls) { SharePointSiteDiskSpace siteDiskSpace = new SharePointSiteDiskSpace(); rootWebApplication.Sites[url].RecalculateStorageUsed(); siteDiskSpace.Url = url; siteDiskSpace.DiskSpace = (long)Math.Round(rootWebApplication.Sites[url].Usage.Storage / 1024.0 / 1024.0); ret.Add(siteDiskSpace); } return(ret.ToArray()); } catch (Exception ex) { HostedSolutionLog.LogError(ex); throw; } finally { if (wic != null) { wic.Undo(); } } }
private void AddSiteCollections(TreeNodeCollection childNodes) { Debug.WriteLine("AddSiteCollections"); var serverUri = new Uri(_rootWeb); Debug.WriteLine("RootUrl:" + _rootWeb); SPWebApplication webApplication = SPWebApplication.Lookup(serverUri); foreach (SPSite siteCollection in webApplication.Sites) { Debug.WriteLine("** SiteUrl:" + siteCollection.Url); Debug.WriteLine("** PortalName:" + siteCollection.PortalName); try { AddSiteNodeToTreeViewNodesCollection(childNodes, siteCollection); } catch (Exception ex) { Debug.Write(ex); } // AddNodes(siteCollection.Url,node.ChildNodes); siteCollection.Dispose(); } }
public void ActivateManagementFeature(string applicationFolder, string url) { try { var solutionGuid = new Guid("8edc9014-59ed-4f9d-9e99-a750cda9dde1"); foreach (SPSolution solution in SPFarm.Local.Solutions) { if (solution.Id == solutionGuid) { SPWebApplication webapp = SPWebApplication.Lookup(new Uri(url)); if (!solution.DeployedWebApplications.Contains(webapp)) { var webapps = new Collection <SPWebApplication> { webapp }; solution.Deploy(DateTime.Now, true, webapps, true); Utilities.WaitForJobToFinish(solution); webapp.Features.Add(new Guid("b242c6bd-bbe3-4fb3-8596-9fe9272ed698"), true); } break; } } } catch (Exception ex) { Utilities.LogException("Error in InstallHelper.ActivateManagementFeature: " + ex.Message); throw; } }
public long GetSiteCollectionSize(Uri root, string url) { WindowsImpersonationContext wic = null; try { wic = WindowsIdentity.GetCurrent().Impersonate(); SPWebApplication rootWebApplication = SPWebApplication.Lookup(root); SPSite site = rootWebApplication.Sites[url]; if (site != null) { site.RecalculateStorageUsed(); } else { throw new ApplicationException(string.Format("SiteCollection {0} does not exist", url)); } return(site.Usage.Storage); } catch (Exception ex) { HostedSolutionLog.LogError(ex); throw; } finally { if (wic != null) { wic.Undo(); } } }
/// <summary> /// Gets list of SharePoint collections within root web application. /// </summary> /// <param name="rootWebApplicationUri">Root web application uri.</param> /// <returns>List of SharePoint collections within root web application.</returns> public SharePointSiteCollection[] GetSiteCollections(Uri rootWebApplicationUri) { try { WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate(); try { SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri); List <SharePointSiteCollection> siteCollections = new List <SharePointSiteCollection>(); foreach (SPSite site in rootWebApplication.Sites) { SharePointSiteCollection loadedSiteCollection = new SharePointSiteCollection(); FillSiteCollection(loadedSiteCollection, site); siteCollections.Add(loadedSiteCollection); } return(siteCollections.ToArray()); } finally { wic.Undo(); } } catch (Exception ex) { throw new InvalidOperationException("Failed to create site collection.", ex); } }
private void GenerateHierarchy(string url) { tv.Nodes.Clear(); SPWebApplication webApplication = SPWebApplication.Lookup(new Uri(url)); _rootNode = tv.Nodes.Add(webApplication.Id.ToString(), GetDisplay(webApplication), 0, 0); _rootNode.Tag = webApplication; foreach (SPSite site in webApplication.Sites) { if (FilterCheck.Checked) { if (!site.Url.StartsWith(FilterText.Text)) { continue; } } TreeNode node = _rootNode.Nodes.Add(site.ID.ToString(), GetDisplay(site), 1, 1); node.Tag = site; node.ToolTipText = "Site Collection"; IterateWebs(site, node); Application.DoEvents(); } tv.ExpandAll(); if (_rootNode != null) { _rootNode.EnsureVisible(); } }
int GetConfiguration(out string output) { string guidValue = Value("guid"); string url = Value("url"); Guid id; if (string.IsNullOrEmpty(guidValue) && string.IsNullOrEmpty(url)) { output = FormatString(culture.Resources.StsMissingParameters, "guid", "url"); return((int)ErrorCodes.SyntaxError); } else if (string.IsNullOrEmpty(url)) { id = new Guid(guidValue); } else { try { using (SPSite site = new SPSite(url)) { id = site.ID; } } catch (System.IO.FileNotFoundException) { SPWebApplication application = SPWebApplication.Lookup(new Uri(url)); id = application.Id; } } return(GetSiteConfiguration(id, out output)); }
public void UnextendVirtualServer(string url, bool deleteContent) { try { WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate(); Uri uri = new Uri("http://" + url); SPWebApplication app = SPWebApplication.Lookup(uri); if (app == null) { return; } SPGlobalAdmin adm = new SPGlobalAdmin(); adm.UnextendVirtualServer(uri, false); //typeof(SPWebApplication).InvokeMember("UnprovisionIisWebSitesAsAdministrator", // BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, // null, null, new object[] { false, new string[] { url }, app.ApplicationPool }); //app.Unprovision(); app.Delete(); wic.Undo(); } catch (Exception ex) { throw new Exception("Could not uninstall SharePoint from the web site", ex); } }
/// <summary> /// Get the client id from the web application. /// </summary> /// <param name="context"></param> /// <returns></returns> private string GetWebApplicationClientId(Uri context) { try { logger.SearchClientId(context); var webApplication = SPWebApplication.Lookup(context); // Loop each realm. var provider = SPSecurityTokenServiceManager.Local.TrustedLoginProviders.FirstOrDefault(p => p.Name == "Auth0"); foreach (var realm in provider.ProviderRealms) { var realmWebApplication = SPWebApplication.Lookup(realm.Key); if (webApplication.Id == realmWebApplication.Id) { return(realm.Value.Replace("urn:", "")); } } // Nothing found. return(null); } catch (Exception) { return(null); } }
/// <summary> /// Gets SharePoint collection within root web application with given name. /// </summary> /// <param name="rootWebApplicationUri">Root web application uri.</param> /// <param name="url">Url that uniquely identifies site collection to be loaded.</param> /// <returns>SharePoint collection within root web application with given name.</returns> public SharePointSiteCollection GetSiteCollection(Uri rootWebApplicationUri, string url) { try { WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate(); try { SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri); string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port); SPSite site = rootWebApplication.Sites[siteCollectionUrl]; if (site != null) { SharePointSiteCollection loadedSiteCollection = new SharePointSiteCollection(); FillSiteCollection(loadedSiteCollection, site); return(loadedSiteCollection); } return(null); } finally { wic.Undo(); } } catch (Exception ex) { throw new InvalidOperationException("Failed to create site collection.", ex); } }
protected virtual void EnsureManagedPath(string webApplicationUrl, string managedPath) { var webApp = SPWebApplication.Lookup(new Uri(webApplicationUrl)); if (!webApp.Prefixes.Contains(managedPath)) { webApp.Prefixes.Add(managedPath, SPPrefixType.WildcardInclusion); } }
protected override bool ProcessWorkItem(SPContentDatabase contentDatabase, SPWorkItemCollection workItems, SPWorkItem workItem, SPJobState jobState) { using (var site = new SPSite(workItem.SiteId)) { using (SPWeb web = site.OpenWeb(workItem.WebId)) { workItems.SubCollection(site, web, 0, (uint)workItems.Count).DeleteWorkItem(workItem.Id); } } try { var stringSeparators = new string[] { "-#####-" }; string[] cmds = workItem.TextPayload.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries); SPWebApplication webApp = SPWebApplication.Lookup(new Uri(cmds[0])); SPIisSettings iis = webApp.IisSettings[SPUrlZone.Default]; string port; if (iis.ServerBindings.Count > 0) { port = iis.ServerBindings[0].Port.ToString(); } else { string path = iis.Path.ToString(); port = path.Substring(path.LastIndexOf('\\') + 1); } if (!string.IsNullOrEmpty(port)) { port = ":" + port; } var reloadCacheTimerJob = new ReloadCacheTimerJob("Oceanik.ReloadCacheJob" + Guid.NewGuid(), webApp, null, SPJobLockType.None) { Schedule = new SPOneTimeSchedule(DateTime.Now) }; string command = "http://localhost" + port + cmds[1]; reloadCacheTimerJob.Properties.Add("CMD", command); reloadCacheTimerJob.Update(); SPSecurity.RunWithElevatedPrivileges(() => EventLog.WriteEntry("ReloadCacheJobDefinition.ProcessWorkItem.ExecuteCommand", command, EventLogEntryType.Information)); } catch (Exception ex) { SPSecurity.RunWithElevatedPrivileges(() => EventLog.WriteEntry("ReloadCacheJobDefinition.ProcessWorkItem", ex.Message, EventLogEntryType.Error)); } return(true); }
protected virtual void EnsureWebApplication(string webApplicatoinUrl) { var webApplication = SPWebApplication.Lookup(new Uri(webApplicatoinUrl)); if (webApplication == null) { throw new ArgumentException( string.Format("Can't lookup web application at url: {0}", webApplicatoinUrl)); } }
/// <summary> /// Activates or deactivates the web application scoped feature. /// </summary> /// <param name="activate">if set to <c>true</c> [activate].</param> /// <param name="featureId">The feature id.</param> /// <param name="urlScope">The URL scope.</param> /// <param name="force">if set to <c>true</c> [force].</param> /// <param name="ignoreNonActive">if set to <c>true</c> [ignore non active].</param> /// <returns></returns> public SPFeature ActivateDeactivateFeatureAtWebApplication(bool activate, Guid featureId, string urlScope, bool force, bool ignoreNonActive) { SPWebApplication application = SPWebApplication.Lookup(new Uri(urlScope)); if (application == null) { throw new FileNotFoundException(SPResource.GetString("WebApplicationLookupFailed", new object[] { urlScope })); } return(ActivateDeactivateFeatureAtWebApplication(application, featureId, activate, force, ignoreNonActive)); }
/// <summary> /// Runs the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, System.Collections.Specialized.StringDictionary keyValues, out string output) { output = string.Empty; Uri uri = new Uri(Params["url"].Value); SPWebApplicationBuilder builder = GetWebAppBuilder(uri); SPWebApplication app = builder.Create(); SPAdministrationWebApplication local = SPAdministrationWebApplication.Local; // Set the TimeZone of the Application if (Params["timezone"].UserTypedIn) { app.DefaultTimeZone = ushort.Parse(Params["timezone"].Value); } app.Update(); app.ProvisionGlobally(); // Execute pending timer jobs before moving on. Common.TimerJobs.ExecAdmSvcJobs.Execute(false, true); // Recreate the web application object to avoid update conflicts. app = SPWebApplication.Lookup(uri); // Upload the newly created WebApplication to the List 'Web Application List' in Central Administration: SPWebService.AdministrationService.WebApplications.Add(app); if (!Params["donotcreatesite"].UserTypedIn) { uint nLCID = uint.Parse(Params["lcid"].Value); string webTemplate = Params["sitetemplate"].Value; string ownerLogin = Params["ownerlogin"].Value; ownerLogin = Utilities.TryGetNT4StyleAccountName(ownerLogin, app); string ownerName = Params["ownername"].Value; string ownerEmail = Params["owneremail"].Value; app.Sites.Add(uri.AbsolutePath, null, null, nLCID, webTemplate, ownerLogin, ownerName, ownerEmail, null, null, null); } Console.WriteLine(SPResource.GetString("PendingRestartInExtendWebFarm", new object[0])); Console.WriteLine(); if (!Params["donotcreatesite"].UserTypedIn) { Console.WriteLine(SPResource.GetString("AccessSiteAt", new object[] { uri.ToString() })); } Console.WriteLine(); return((int)ErrorCodes.NoError); }
internal static void GetWebApplication(Uri _auri) { try { WebApplication = SPWebApplication.Lookup(_auri); } catch (Exception ex) { throw new ApplicationException(String.Format(Properties.Resources.GetWebApplicationFfailed, ex.Message)); } }
private IList <SPUser> GetUsers() { IList <SPUser> list = new List <SPUser>(); try { SPSecurity.RunWithElevatedPrivileges(delegate() { SPWebApplication webApplication = SPWebApplication.Lookup(new Uri(_url)); foreach (SPSite site in webApplication.Sites) { foreach (SPWeb web in site.AllWebs) { foreach (SPUser user in web.AllUsers) { bool found = false; if (string.IsNullOrEmpty(NameText.Text)) { found = true; AddUser(list, user); } else if (!string.IsNullOrEmpty(user.LoginName)) { if (user.LoginName.ToLower().Contains(NameText.Text.ToLower())) { found = true; AddUser(list, user); } if (!found) { if (user.Name.ToLower().Contains(NameText.Text.ToLower())) { found = true; AddUser(list, user); } } } } } } }); } catch (Exception ex) { SquadronContext.HandleException(ex); } return(list); }
private object GetNewWebApplication(SPWebApplication webapp) { object result = _internalList.OfType <SPWebApplication>().FirstOrDefault(w => w.OfficialFileUrl == webapp.OfficialFileUrl); if (result == null) { result = SPWebApplication.Lookup(new Uri(SquadronContext.Url)); _internalList.Add(result); } return(result); }
private void GetUrl() { try { SPSecurity.RunWithElevatedPrivileges(delegate() { SPWebApplication webApp = SPWebApplication.Lookup(new Uri(webAppUrl)); DateTime date1 = System.DateTime.Now; WriteLog(date1.ToString()); string head = @"url"; WriteResult(head); foreach (SPSite site in webApp.Sites) { try { //string resultText = "\"" + site.Url + "\""; //WriteResult(resultText); try { DoSubsite(site.RootWeb); } catch (Exception ex) { WriteErrorLog("Into DoSubsite method error for site " + site.Url + ex.ToString()); } } catch (Exception ex) { WriteErrorLog("write site error for site " + site.Url + ex.ToString()); } site.Dispose(); site.Close(); } DateTime date2 = System.DateTime.Now; WriteLog("End time:" + (date2 - date1).ToString()); } ); this.BeginInvoke(new MethodInvoker(delegate { btnExport.Enabled = true; linkLog.Enabled = true; })); SetLabelText("Click here to view log file."); } catch (Exception ex) { WriteErrorLog("There are something wrong!!" + ex.ToString()); } }
public void hstCreateSite(string webAppURL, string strURL, string strTitle, string strDesc, uint nLCID, string strTemplate, string strOwnerLogin1, string strOwnerName1, string strOwnerEmail1, string strOwnerLogin2, string strOwnerName2, string strOwnerEmail2, bool hhMode) { System.Uri srvrUri = new System.Uri(webAppURL); SPWebApplication webApp = SPWebApplication.Lookup(srvrUri); SPSiteCollection siteColl = webApp.Sites; SPSite oSite = null; try { // If the secondary owner information is not provided, make sure it's null if (String.IsNullOrEmpty(strOwnerLogin2)) { strOwnerLogin2 = null; } if (String.IsNullOrEmpty(strOwnerName2)) { strOwnerName2 = null; } if (String.IsNullOrEmpty(strOwnerEmail2)) { strOwnerEmail2 = null; } if (String.IsNullOrEmpty(strDesc)) { strDesc = null; } if (String.IsNullOrEmpty(strTitle)) { strTitle = null; } if (String.IsNullOrEmpty(strTemplate)) { strTemplate = null; } // add site to the site collection oSite = siteColl.Add(strURL, strTitle, strDesc, nLCID, strTemplate, strOwnerLogin1, strOwnerName1, strOwnerEmail1, strOwnerLogin2, strOwnerName2, strOwnerEmail2, true); } finally { // dispose object if (oSite != null) { oSite.Dispose(); } } }
private void GenerateSiteParentInformation() { HashSet <SiteParentInfo> hashset = new HashSet <SiteParentInfo>(); SPWebApplication application = SPWebApplication.Lookup(new Uri(SquadronContext.Url)); foreach (SPSite site in application.Sites) { GetSiteParentInfo(hashset, site); } grid.DataSource = hashset.ToList(); }
static void Main(string[] args) { Uri ruri = new System.Uri("http://localhost:51001/"); Console.WriteLine("Hämtar webbapplikationen..."); SPWebApplication spwa = SPWebApplication.Lookup(ruri); string contentDbGuid = "6c1e7e35-9dfe-4974-955f-cd7e466e2432"; Console.WriteLine("Skapar jobb..."); ChalmersStaffSync css = new ChalmersStaffSync("Chalmers Staff Sync (Manual 1.0)", spwa); Console.WriteLine("Startar jobb..."); css.Execute(new System.Guid(contentDbGuid)); }
/// <summary> /// Adds a "wildcard inclusion" managed path to a given SharePoint Web application. This is /// the same functionality you can access using the "Define Managed Paths" page in SharePoint /// Central Administration. /// </summary> /// /// <param name="webApplicationUrl">The URL of the web application.</param> /// /// <param name="relativeUrl">The relative URL of the inclusion, e.g. "sites".</param> /// static void AddManagedPath(string webApplicationUrl, string relativeUrl) { Console.WriteLine("Finding or creating managed path \"{0}\" under \"{1}\"", relativeUrl, webApplicationUrl); SPWebApplication webApp = SPWebApplication.Lookup(new Uri(webApplicationUrl)); if (webApp.Prefixes.Contains(relativeUrl)) { Console.WriteLine("...exists already"); } else { webApp.Prefixes.Add(relativeUrl, SPPrefixType.WildcardInclusion); Console.WriteLine("...created"); } }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; Logger.Verbose = true; string scope = Params["scope"].Value.ToLowerInvariant(); SPFarm farm = SPFarm.Local; SPWebService webService = farm.Services.GetValue <SPWebService>(""); m_quotaColl = webService.QuotaTemplates; m_setQuota = Params["setquota"].UserTypedIn; if (Params["quota"].UserTypedIn) { m_quota = m_quotaColl[Params["quota"].Value]; if (m_quota == null) { throw new ArgumentException("The specified quota template name could not be found."); } } SPEnumerator enumerator; if (scope == "farm") { enumerator = new SPEnumerator(SPFarm.Local); } else if (scope == "webapplication") { enumerator = new SPEnumerator(SPWebApplication.Lookup(new Uri(Params["url"].Value.TrimEnd('/')))); } else { // scope == "site" using (SPSite site = new SPSite(Params["url"].Value.TrimEnd('/'))) { Sync(site); } return((int)ErrorCodes.NoError); } enumerator.SPSiteEnumerated += enumerator_SPSiteEnumerated; enumerator.Enumerate(); return((int)ErrorCodes.NoError); }
public void UpdateQuotas(Uri root, string url, long maxStorage, long warningStorage) { WindowsImpersonationContext wic = null; try { wic = WindowsIdentity.GetCurrent().Impersonate(); SPWebApplication rootWebApplication = SPWebApplication.Lookup(root); SPQuota quota = new SPQuota(); if (maxStorage != -1) { quota.StorageMaximumLevel = maxStorage * 1024 * 1024; } else { quota.StorageMaximumLevel = 0; } if (warningStorage != -1 && maxStorage != -1) { quota.StorageWarningLevel = Math.Min(warningStorage, maxStorage) * 1024 * 1024; } else { quota.StorageWarningLevel = 0; } rootWebApplication.GrantAccessToProcessIdentity(WindowsIdentity.GetCurrent().Name); rootWebApplication.Sites[url].Quota = quota; } catch (Exception ex) { HostedSolutionLog.LogError(ex); throw; } finally { if (wic != null) { wic.Undo(); } } }
/// <summary> Creates site collection within predefined root web application.</summary> /// <param name="runspace"> The runspace.</param> /// <param name="rootWebApplicationUri">Root web application uri.</param> /// <param name="siteCollection">Information about site coolection to be created.</param> /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception> private void CreateCollection(Runspace runspace, Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection) { string siteCollectionUrl = String.Format("{0}:{1}", siteCollection.Url, rootWebApplicationUri.Port); HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl); try { SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri); rootWebApplication.Sites.Add(siteCollectionUrl, siteCollection.Title, siteCollection.Description, (uint)siteCollection.LocaleId, String.Empty, siteCollection.OwnerLogin, siteCollection.OwnerName, siteCollection.OwnerEmail, null, null, null, true); rootWebApplication.Update(); } catch (Exception) { DeleteSiteCollection(runspace, siteCollectionUrl, true); throw; } try { GrantAccess(runspace, rootWebApplicationUri); var command = new Command("Set-SPSite"); command.Parameters.Add("Identity", siteCollectionUrl); if (siteCollection.MaxSiteStorage != -1) { command.Parameters.Add("MaxSize", siteCollection.MaxSiteStorage * 1024 * 1024); } if (siteCollection.WarningStorage != -1 && siteCollection.MaxSiteStorage != -1) { command.Parameters.Add("WarningSize", Math.Min(siteCollection.WarningStorage, siteCollection.MaxSiteStorage) * 1024 * 1024); } ExecuteShellCommand(runspace, command); } catch (Exception) { DeleteQuotaTemplate(siteCollection.Title); DeleteSiteCollection(runspace, siteCollectionUrl, true); throw; } AddHostsRecord(siteCollection); }