In case you need to update a bunch of sites that look the same. in my case I have to update on a regular base about 120 sites.
Connect-SPOService –Url 'YOUR ADMIN SITE FULL URL"
# Get all sites
Get-SPOHubSite
# so you get the the hub id you need if not just remove the loop on next section
$hubSiteId= "ID HERE"
$sites = Get-SPOSite -Limit ALL
foreach ($site in $sites)
{
$siteDetailed = Get-SPOSite -Detailed $site.Url
if($siteDetailed.HubSiteId -eq $hubSiteId)
{
$siteUrl = $site.url
$siteUrl
$username = "USER HERE"
$password = "PASS SITE"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, (ConvertTo-SecureString $Password -AsPlainText -Force))
$ctx.Credentials = $credentials
$web = $ctx.Web
$ql = $web.Navigation.QuickLaunch
$ctx.load($ql)
$ctx.ExecuteQuery()
$node = $web.Navigation.QuickLaunch | where { $_.Title -eq "TITLE HERE" }
$node.DeleteObject()
$ctx.ExecuteQuery()
}
}
What you will find here
If you are one of those multi hat kind of person you might want to take a look here.
Some of the sections here will cover: SharePoint, SQL, Server, VB Script, Batch files, PCI Compliance
Some of the sections here will cover: SharePoint, SQL, Server, VB Script, Batch files, PCI Compliance
Icon
Wednesday, March 6, 2019
Add user to security group - SharePoint Online - Power Shell - Loop
To add a user to all sub sites on your hub site here the WORKING script using power shell and
Connect-SPOService –Url "YOUR ADMIN SITE HERE"
# Get all sites
Get-SPOHubSite
#SO YOU CAN GET THE ID YOU NEED
# add users to a security group
$hubSiteId= "HUB ID HERE"
$sites = Get-SPOSite -Limit ALL
foreach ($site in $sites)
{
$siteDetailed = Get-SPOSite -Detailed $site.Url
if($siteDetailed.HubSiteId -eq $hubSiteId)
{
$site.Url
$x = Get-SPOSiteGroup -Site $site.url
foreach ($y in $x)
{
if($y.Title -like "*Owners*") #OR GROUP YOU NEED
{
$group = Get-SPOSiteGroup -Site $site.URL -Group $y.Title
$group.title
Add-SPOUser -Site $site.url -LoginName "FULL EMAIL OF USER" -Group $group.title
}
}
}
}
Connect-SPOService –Url "YOUR ADMIN SITE HERE"
# Get all sites
Get-SPOHubSite
#SO YOU CAN GET THE ID YOU NEED
# add users to a security group
$hubSiteId= "HUB ID HERE"
$sites = Get-SPOSite -Limit ALL
foreach ($site in $sites)
{
$siteDetailed = Get-SPOSite -Detailed $site.Url
if($siteDetailed.HubSiteId -eq $hubSiteId)
{
$site.Url
$x = Get-SPOSiteGroup -Site $site.url
foreach ($y in $x)
{
if($y.Title -like "*Owners*") #OR GROUP YOU NEED
{
$group = Get-SPOSiteGroup -Site $site.URL -Group $y.Title
$group.title
Add-SPOUser -Site $site.url -LoginName "FULL EMAIL OF USER" -Group $group.title
}
}
}
}
Uncheck or Unlock Document or Page SharePoint Online - power shell
after trying A LOT to discard changed on a page by a user, I finally got it.
This is actually working like a charm for pages and documents.
Connect-SPOService –Url "YOUR ADMIN URL"
{
$siteUrl = "YOUR SITE URL"
$siteUrl
$username = "USER HERE"
$password = "PASS HERE"
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName,(ConvertTo-SecureString $Password -AsPlainText -Force))
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$Ctx.Credentials = $SPOCredentials
$web = $Ctx.Web
$ctx.ExecuteQuery()
# Load the up list
$lookupList = $ctx.Web.Lists.GetByTitle("YOUR LIBRARY")
$ctx.Load($lookupList)
# Prepare the query
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = '<View Scope="RecursiveAll"><RowLimit Paged="TRUE">1000</RowLimit></View>'
$listItems = $lookupList.getItems($query)
$ctx.Load($listItems)
$ctx.ExecuteQuery()
$query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
#Load File
$file = $ctx.Web.GetFileByServerRelativeUrl("RELATIVE URL OF PAGE HERE");
#Relative URL of document is : sample.. /sites/mysite/SitePages/Home.aspx
$ctx.Load($file)
$Ctx.ExecuteQuery()
$file.UndoCheckOut()
$file.Update()
$Ctx.ExecuteQuery()
}
I hope this helps. !!!
This is actually working like a charm for pages and documents.
Connect-SPOService –Url "YOUR ADMIN URL"
{
$siteUrl = "YOUR SITE URL"
$siteUrl
$username = "USER HERE"
$password = "PASS HERE"
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName,(ConvertTo-SecureString $Password -AsPlainText -Force))
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$Ctx.Credentials = $SPOCredentials
$web = $Ctx.Web
$ctx.ExecuteQuery()
# Load the up list
$lookupList = $ctx.Web.Lists.GetByTitle("YOUR LIBRARY")
$ctx.Load($lookupList)
# Prepare the query
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = '<View Scope="RecursiveAll"><RowLimit Paged="TRUE">1000</RowLimit></View>'
$listItems = $lookupList.getItems($query)
$ctx.Load($listItems)
$ctx.ExecuteQuery()
$query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
#Load File
$file = $ctx.Web.GetFileByServerRelativeUrl("RELATIVE URL OF PAGE HERE");
#Relative URL of document is : sample.. /sites/mysite/SitePages/Home.aspx
$ctx.Load($file)
$Ctx.ExecuteQuery()
$file.UndoCheckOut()
$file.Update()
$Ctx.ExecuteQuery()
}
I hope this helps. !!!
Wednesday, March 29, 2017
Issues openning pdf files in browser SharePoint 2010?
Here an easy solution
$webApp = Get-SPWebApplication("http://yourwebappurl")
$webApp.AllowedInlineDownloadedMimeTypes.Add("application/pdf")
$webApp.Update()
Thank Brandon Atkinson
$webApp = Get-SPWebApplication("http://yourwebappurl")
$webApp.AllowedInlineDownloadedMimeTypes.Add("application/pdf")
$webApp.Update()
Thank Brandon Atkinson
Cognos 11 - 10 Report title with Parameter - Dynamic
I have seen that there is lots of confusion there when this question is posted.
I need the title of my report to by dynamic in Cognos.
Not that hard.
Go to your query or one of the queries you are using in the page with the title.
Add a funny filter like
?TitleParam? = ?TitleParam?
Make it optional.
You have your parameter now.
Then go to your Report title and change the type from text to report expression
In the report expression just add the parameter from the list
And that is it.
Now you have a dynamic report title.
I need the title of my report to by dynamic in Cognos.
Not that hard.
Go to your query or one of the queries you are using in the page with the title.
Add a funny filter like
?TitleParam? = ?TitleParam?
Make it optional.
You have your parameter now.
Then go to your Report title and change the type from text to report expression
In the report expression just add the parameter from the list
And that is it.
Now you have a dynamic report title.
Tuesday, November 3, 2015
Openning excel doc in SharePoint errors - Read only document or security certificate problem.
This was very tricky but figured out eventually.
SharePoint 2010 and 2013, excel 2010.
Microsoft update KB3054886 will brake the ability to open excel documents with content type.
Just go to your installed updates remove "KB3054886" No need to restart computer just Explorer.
I hope this helps. It took me several hours to fix it and there are no other post online about this.
SharePoint 2010 and 2013, excel 2010.
Microsoft update KB3054886 will brake the ability to open excel documents with content type.
Just go to your installed updates remove "KB3054886" No need to restart computer just Explorer.
I hope this helps. It took me several hours to fix it and there are no other post online about this.
Tuesday, June 30, 2015
Management Reporter 2012 format error - FRX migration
I had this error since I have migrated from FRX.
The error was a general error "An unknown error has occurred"
Went to configuration console the I have found "System.OverflowException: Value was either too large or too small for a Decimal."
Solution:
It was the format. I had a custom format for the percent, at the column level. Change any custom format to their standard, in this case percent. Then like magic everything worked just fine.
I hope this helps because I looked all over the net for a solution and it looks like nobody have had this issue before.
The error was a general error "An unknown error has occurred"
Went to configuration console the I have found "System.OverflowException: Value was either too large or too small for a Decimal."
Solution:
It was the format. I had a custom format for the percent, at the column level. Change any custom format to their standard, in this case percent. Then like magic everything worked just fine.
I hope this helps because I looked all over the net for a solution and it looks like nobody have had this issue before.
Wednesday, October 1, 2014
Find records where your column has numbers or not SQL Server
Well, after looking for a while online I was kind of surprised
nobody have had blogged about this. Maybe I was looking for the wrong keywords
I don’t know
Find only records with number on the column
WHERE PATINDEX ( '%[^0-9]%' , [Field Name]) = 0
I was able to come up with this simple way.
Find records where your column has numbers :
WHERE PATINDEX ( '%[^0-9]%' , [Field Name]) > 1WHERE PATINDEX ( '%[^0-9]%' , [Field Name]) = 0
Find records where your column does not have numbers
WHERE PATINDEX ( '%[^0-9]%' , [Field Name]) = 1
I hope you enjoy this.
Tuesday, July 22, 2014
Mass add link to Navigation Pane SharePoint 2010 Power shell
--add a link to navigation pane mass sites
$sites = Get-SPWeb "Site Here"
foreach ($site in $sites.webs)
{
$web = Get-SPWeb $Site.URL
$qlNav = $web.Navigation.QuickLaunch
$qlHeading = $qlNav | where { $_.Title -eq "Libraries" }
$linkNode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("Name", "URL", $true)
$qlHeading.Children.AddAsLast($linkNode)
$qlHeading.Update
$web.Update
$web.Dispose
}
enjoy
Hierarchy Query
This I Took from another Blog but is so cool I have to re post it,
This is to make a level hierarchy query
Only SQL server 2008 and up
with MyCTE AS
(
SELECT
TYPEID,
ParentTypeId,
TYPE,
1 as level,
CAST(CAST(TYPEID AS BINARY(4)) AS VARBINARY(8000)) AS SortPath
FROM
TASKTYPE
WHERE
(ParentTypeId IS NULL)
UNION ALL
SELECT
TY.TYPEID,
TY.ParentTypeId ,
TY.TYPE,
EL.level + 1,
CAST(el.SortPath + CAST(TY.TYPEID AS BINARY(4)) AS VARBINARY(8000)) AS SortPath
FROM TASKTYPE as TY
INNER JOIN MyCTE AS el on TY.ParentTypeId = el.TypeID
WHERE (TY.ParentTypeId IS NOT NULL)
)
Select Typeid, parenttypeid, type = SPACE((level-1)*4)+type , level
from MyCTE
ORDER BY SortPath
This is to make a level hierarchy query
Only SQL server 2008 and up
with MyCTE AS
(
SELECT
TYPEID,
ParentTypeId,
TYPE,
1 as level,
CAST(CAST(TYPEID AS BINARY(4)) AS VARBINARY(8000)) AS SortPath
FROM
TASKTYPE
WHERE
(ParentTypeId IS NULL)
UNION ALL
SELECT
TY.TYPEID,
TY.ParentTypeId ,
TY.TYPE,
EL.level + 1,
CAST(el.SortPath + CAST(TY.TYPEID AS BINARY(4)) AS VARBINARY(8000)) AS SortPath
FROM TASKTYPE as TY
INNER JOIN MyCTE AS el on TY.ParentTypeId = el.TypeID
WHERE (TY.ParentTypeId IS NOT NULL)
)
Select Typeid, parenttypeid, type = SPACE((level-1)*4)+type , level
from MyCTE
ORDER BY SortPath
Enjoy
Wednesday, April 16, 2014
Edit library in SharePoint site list with PowerShell
I like simple scripts I don't really like functions and all that when I need is to run a quick update.
Here a really nice one I've modified from some smart guys
I needed to remove the property "Force Check Out" from all libraries on my site collection.
$sites = Get-SPWeb {Site URL}
foreach ($site in $sites.webs)
{
$web = Get-SPWeb $site.URL
$library = $web.Lists[{Library Name}]
$library.ForceCheckOut = $false
$library.Update()
$web.Update()
$web.Dispose()
}
Additional options here
$library.EnableVersioning = $true
$library.EnableMinorVersions = $true
$library.MajorVersionLimit = $majorVersionLimit
$library.MajorWithMinorVersionsLimit = $minorVersionLimit
$library.ForceCheckOut = $requireCheckOut
I hope it helps
Friday, March 28, 2014
Add library to SharePoint sites using power shell
Will work on your sites three, run from your top site.
$sites = Get-SPWeb <site url>
foreach ($site in $sites.webs)
{
$listTemplate = $Site.ListTemplates["Document Library"];
$Site.Lists.Add(<Library name>,<Library Name>,$listTemplate);
$list = $Site.Lists[<Library Name>];
$list.Title = <Library Title>;
$List.DefaultItemOpen = "PreferClient";
$list.EnableVersioning = $true;
$list.EnableMinorVersions = $false;
$list.MajorVersionLimit = 0;
$list.ForceCheckout = $true;
$List.OnQuickLaunch = $true;
$List.ContentTypesEnabled = $true
$list.Update()
$ctToRemove = $list.ContentTypes[<Main Content Type>]
$list.ContentTypes.Delete($ctToRemove.Id)
$list.Update()
$SPWeb1 = Get-SPWeb -Identity <Main Site where content type is>
$ctToAdd = $SPWeb1.ContentTypes[<Content Type Name>];
$ct = $List.ContentTypes.Add($ctToAdd);
$list.Update()
$Site.Dispose()
$SPWeb1.Dispose()
}
Get table size T SQL
Simple and effective your admin will love this
SELECT DB_NAME() AS DatabaseName
, object_name(i.object_id) AS TableName
, ISNULL(i.name, 'HEAP') AS IndexName
, i.index_id AS IndexID
, i.type_desc AS IndexType
, p.partition_number AS PartitionNo
, p.[rows] AS NumRows
, au.type_desc AS InType
, au.total_pages AS NumPages
, au.total_pages * 8 AS TotKBs
, au.used_pages * 8 AS UsedKBs
, au.data_pages * 8 AS DataKBs
FROM sys.indexes i INNER JOIN sys.partitions p
ON i.object_id = p.object_id AND i.index_id = p.index_id
INNER JOIN sys.allocation_units au ON
CASE
WHEN au.[type] in (1,3) THEN p.hobt_id
WHEN au.type = 2 THEN p.partition_id
end = au.container_id
INNER JOIN sys.objects o ON i.object_id = o.object_id
WHERE o.is_ms_shipped <> 1
ORDER BY TableName, i.index_id
SELECT DB_NAME() AS DatabaseName
, object_name(i.object_id) AS TableName
, ISNULL(i.name, 'HEAP') AS IndexName
, i.index_id AS IndexID
, i.type_desc AS IndexType
, p.partition_number AS PartitionNo
, p.[rows] AS NumRows
, au.type_desc AS InType
, au.total_pages AS NumPages
, au.total_pages * 8 AS TotKBs
, au.used_pages * 8 AS UsedKBs
, au.data_pages * 8 AS DataKBs
FROM sys.indexes i INNER JOIN sys.partitions p
ON i.object_id = p.object_id AND i.index_id = p.index_id
INNER JOIN sys.allocation_units au ON
CASE
WHEN au.[type] in (1,3) THEN p.hobt_id
WHEN au.type = 2 THEN p.partition_id
end = au.container_id
INNER JOIN sys.objects o ON i.object_id = o.object_id
WHERE o.is_ms_shipped <> 1
ORDER BY TableName, i.index_id
Database in lock state?
With this script you will get your panic attack under control
Use <Database>
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Agent XPs', 1;
GO
RECONFIGURE
Use <Database>
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Agent XPs', 1;
GO
RECONFIGURE
Easy way to Shrink databases Log
Easy to set up as an scheduled task
USE DatabaseName
GO
DBCC SHRINKFILE(<TransactionLogName>, 1)
BACKUP LOG <DatabaseName> WITH TRUNCATE_ONLY
DBCC SHRINKFILE(<TransactionLogName>, 1)
GO
Same apply to the database file
USE [RC_BI_DW] DBCC SHRINKFILE (N<Database file name> , 0, TRUNCATEONLY)
SharePoint Add Gropup to Site using Power Shell
Simple Script to add an existing group to a site or sites.
$sites = Get-SPWeb "Site url"
foreach ($site in $sites.webs)
{
$site.AssociatedGroups.Add($site.SiteGroups["Group Name"]);
$GroupAccount = $site.SiteGroups["Group Name"]
$timeoffassignment = New-Object Microsoft.SharePoint.SPRoleAssignment($GroupAccount)
$timeoffrole = $site.RoleDefinitions["Read"]
$timeoffassignment.RoleDefinitionBindings.Add($timeoffrole)
$site.RoleAssignments.Add($timeoffassignment)
$site.Update()
$site.Dispose()
}
foreach ($site in $sites.webs)
{
$site.AssociatedGroups.Add($site.SiteGroups["Group Name"]);
$GroupAccount = $site.SiteGroups["Group Name"]
$timeoffassignment = New-Object Microsoft.SharePoint.SPRoleAssignment($GroupAccount)
$timeoffrole = $site.RoleDefinitions["Read"]
$timeoffassignment.RoleDefinitionBindings.Add($timeoffrole)
$site.RoleAssignments.Add($timeoffassignment)
$site.Update()
$site.Dispose()
}
So you wear multiple hats?
If you are one of those multi hat kind of person you might want
to take a look here.
I hope I can help with some tricks or tips that will make
your life a little easier.
Some of the sections here will cover:
·
SharePoint· SQL Server
· VB Script
· Batch files
· PCI Compliance
Subscribe to:
Posts (Atom)