$web = Get-SPWeb -Identity https://sharepoint/sites/PowerShellTests $folder = $web.Folders["Workflows"] $property = $folder.Properties["docid_msft_hier_listid_validate"] $dt = Get-Date -Year 2100 -Month 12 -Day 31 $folder.Properties["docid_msft_hier_listid_validate"] = $dt $folder.Update() $web.Update()
$url = "https://sharepoint/sites/PowerShellTests" $web = Get-SPWeb $url $lib = $web.GetList($web.Url + "/oldName") $rootFolder = $lib.RootFolder $rootFolder.MoveTo($web.Url + "/newName")
$wa = $get-spwebapplication "my site host url"$wa.Sites | foreach-object { if ( $_.Url.StartsWith("my site host url/personal") ) { Set-SPSite -Identity $_.Url -QuotaTemplate "Personal Site" }}
function SendSmtpMail($server, $sender, $recipients, $subject, $body, $file){ $msg = new-object Net.Mail.MailMessage $smtpServer = new-object Net.Mail.SmtpClient($server) $msg.From = $sender $msg.Subject = $subject $msg.Body = $body foreach ($recipient in $recipients) { $msg.To.Add($recipient) } if ($file -ne "") { $att = new-object Net.Mail.Attachment($file) $msg.Attachments.Add($att) } $smtpServer.Send($msg) if ($file -ne "") { $att.Dispose() }}$smtpServer = "my smtp server"$file = "path to file"$recipients = @( "user1@test.de", "user2@test.de" )$sender = "sender@mydomain.com"$subject = "My Subject"$body = "My Mail Text"SendSmtpMail $smtpServer $sender $recipients $subject $body $file
$locked = $true while ($locked) { try { $file = New-Object System.IO.FileInfo $Path [IO.File]::OpenWrite($file).close(); $locked = $false } catch { # file is locked by a process. Start-Sleep -s 1000 } }
$analytics = Get-SPUsageDefinition | where { $_.Name -like "Analytics*" } $pageRequests = Get-SPUsageDefinition | where { $_.Name -like "Page Requests" }
$analytics.Receivers.Count $pageRequests.Receivers.Count
if ($analytics.Receivers.Count -eq 0) { $analytics.Receivers.Add( "Microsoft.Office.Server.Search.Applications, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c", "Microsoft.Office.Server.Search.Analytics.Internal. AnalyticsCustomRequestUsageReceiver") } if ($analytics.EnableReceivers -eq $false) { $analytics.EnableReceivers = $true $analytics.Update() } if ($pageRequests.Receivers.Count -eq 0) { $pageRequests.Receivers.Add( "Microsoft.Office.Server.Search.Applications, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c", "Microsoft.Office.Server.Search.Analytics.Internal. ViewRequestUsageReceiver") } if ($pageRequests.EnableReceivers -eq $false) { $pageRequests.EnableReceivers = $true $pageRequests.Update() }
$farm = Get-SPFarm $file = $farm.Solutions.Item("MySolution.wsp").SolutionFile $file.SaveAs("c:\temp\MySolution.wsp")
# Configuration $app = Get-SPWebapplication "web app url" $jobname = "my job name" $siteurl = "site url will be used within the job" # Install $job = New-Object MyNamespace.MyClass( $jobname, $app, $siteurl) $job.Schedule = [Microsoft.SharePoint.SPSchedule]:: FromString("daily between 01:00:00 and 01:00:00") $job.Update() Restart-Service SPTimerV4 # Check (Get-SPTimerJob | where-object{$_.Name -eq $jobname)}) | fl
# enter valid values $url = "https://sharepoint.c2go.net/sites/test" $listName = "MyListName" $login = "MyLogin" $web = Get-SPWeb $url $userid = ($web.Allusers | where-object { $_.LoginName -eq $login }).ID $user = $web.AllUsers.GetByID($userid) $token = $user.UserToken; $impSite = New-Object Microsoft.SharePoint.SPSite ($web.Url, $token); $impWeb = $impSite.OpenWeb() $impList = $impWeb.Lists[$listName] $impList.Views
$destinationUrl = "https://sharepoint/sites/teamsite/documents"$file = get-childitem "e:\tmp\document.txt"$webclient = New-Object System.Net.WebClient $webclient.UseDefaultCredentials = $true$webclient.UploadFile($destinationUrl + "/" + $file.Name, "PUT", $file.FullName)
add-pssnapin microsoft.sharepoint.powershell $spserver = get-spserver | ?{$_.role -eq "Application"} foreach ($server in $spserver) { $name = [string]::concat("\\", $server.name) write-host "Performing IIS Reset on Server:"$server.name iisreset $server.Name write-host "Stopping SPTimerV4 on Server:"$server.name $stat = sc.exe $name stop sptimerv4 $stat = sc.exe $name query sptimerv4 while ($stat -match "STOP_PENDING") { write-host "Stopping" $stat = sc.exe $name query sptimerv4 start-sleep 4 } write-host "Starting SPTimerV4 on Server:"$server.name $stat = sc.exe $name start sptimerv4 $stat = sc.exe $name query sptimerv4 while (-not $stat -match "RUNNING") { write-host "Starting" $stat = sc.exe $name query sptimerv4 start-sleep 4 } write-host "SPTimerV4 started on Server:"$server.name}
# if I have to talk to a different but truested domain$dc = "my_domain_controller"# my groups$group1 = "my_first_group"$group2 = "my_second_group"diff (Get-ADGroupMember -Identity $group1 -Server $dc) (Get-ADGroupMember -Identity $group2 -Server $dc) -Property 'distinguishedName' -IncludeEqual | ?{ $_.sideIndicator -eq "==" } | foreach-object { write-host $_.distinguishedName ; Remove-ADGroupMember -Identity $group1 -Server $dc -Members $_.distinguishedName -Confirm:$false }
$followedSite = „https://sharepoint/sites/news“$loginName = „roloff“$profile = $upm.GetUserProfile($loginName)$manager = New-Object Microsoft.Office.Server.Social.SPSocialFollowingManager($profile)$actorInfo = New-Object Microsoft.Office.Server.Social.SPSocialActorInfo$actorInfo.ContentUri = $followedSite$actorInfo.ActorType = 2 # SPSocialActorType.Site$manager.Follow($actorInfo)
$adGroup = "" # AD Group with MySite users$siteURL = "" # any local SharePoint Site will do$members = Get-ADGroupMember -Identity $adgroup -Recursive | sort name# get UserProfileManager$serviceContext = Get-SPServiceContext -site $siteURL -ErrorAction Stop$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext) -ErrorAction Stopforeach ($member in $members){if ($upm.UserExists($member.SamAccountName)){ $profile = $upm.GetUserProfile($member.SamAccountName) $perssite = $profile.PersonalSite if ($perssite -eq $null) { # either this $profile.CreatePersonalSite(1031) # should work in most cases # or this # $profile.CreatePersonalSiteEnque($true) # will work in all cases; gets language from mysite host $perssite = $profile.PersonalSite if ($perssite -eq $null) { # do some error handling } }}}
Get-SPDatabase | where-object { $_.TypeName -eq "Content Database" } | select Displayname, @{Name="Mbytes";Expression={$_.DiskSizeRequired/ 1Mb}}
# URL to your MySite web application$MySiteWebUrl = "https://mysite.collaboration-2-go.net" # where to find users in the AD$searchbase="DC=collaboration-2-go,DC=net" # required if server domain and user domain are different$dc="my_domain_controller" # required if server language is English and# MySite language is different$culture = "de-DE"$webapp = Get-SPWebApplication -identity $MySiteWebUrl[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture foreach ($site in $webapp.Sites){ # Get Active Directory Information $login = $site.Owner.LoginName if ($login.contains("\")) { $login = $login.substring($login.indexof("\") + 1) } $ldapfilter = "(SamAccountName=" + $login + ")" $aduser = Get-ADUser -LDAPFilter $ldapfilter -SearchBase $searchbase -Server $dc $displayName = $aduser.GivenName + " " + $aduser.Surname if ($displayName -eq " ") { $displayName = $site.owner.DisplayName } if ($site.RootWeb.WebTemplate -eq "SPSPERS") # ignore MySite host { # more sophisticated approach is possible but # I'm not sure about the blog URL foreach ($web in $site.AllWebs) { if (($web.WebTemplate -eq "BLOG") -and ($web.Title -eq "Blog")) { $title = "Blog von " + $displayName $web.Title = $title $web.Update() } $web.Dispose() } } $site.Dispose()}
$web = Get-SPWeb https://sharepoint/sites/blogwrite-host $web.Properties["ms-blogs-skinid"]$web.Properties["ms-blogs-skinid"] = 1$web.Properties.update()
$FolderPath = "/TEMP" $NewFolder = "CalendarTest" $PFRoot = "file://./backofficestorage/litwareinc.com/Public Folders" # Use PowerShell cmdlet to create new folder # (depending upon whether a root folder or not) if ($FolderPath -ne "") { $f = $FolderPath -replace("/", "\") New-PublicFolder -Name $NewFolder -Path $f } else { New-PublicFolder -Name $NewFolder } # Use ADO to change the folder type $o=New-Object -comobject ADODB.Record $updated=$false $timeout=60 while (($updated -eq $false) -and ($timeout -gt 0)) { $o.Open($PFRoot + $FolderPath + "/" + $NewFolder, "", 3, -1, -1, "", "") foreach($item in $o.Fields) { if($item.Name -eq "http://schemas.microsoft.com/exchange/outlookfolderclass") { $updated=$true $item.Value="IPF.Appointment" } } $o.Fields.Update() $o.Close() if ($updated -eq $false) { Start-Sleep -s 1 $timeout -- } }