I am using SharePoint 2013 and i want to create some spweb from a site template...
I have created a site and added my desired content and i saved that site as template, then went to solution gallery and downloaded the .wsp file.
Now, i need to create a new site collection with some subsites which are based on that template, and to do so i think need to upload the .wsp file to the solution gallery the way i can find the newly saved template, and i need to do that from PowerShell !
I tried 2 ways,
First,
I tried to add-spsolution and install-spsolution like following
Add-SPSolution -LiteralPath $SPIntranetTemplateFilePath
Install-SPSolution -Identity SPITemplateFile.wsp -CompatibilityLevel 15 -force
but i don't find the .wsp in the solution gallery and the template is not in templates list...
I tried to use Install-SPWebTemplate but this command is not recognized as a cmdlet in my PowerShell (I have added Add-PSSnapin Microsoft.SharePoint.PowerShell)
I have used this too
## SharePoint DLL
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
Can anyone help me to use my WspFile the way i can create subsites based on my template ?
After Add-SPSolution try Install-SPSolution
http://technet.microsoft.com/en-us/library/ff607534(v=office.15).aspx
I think you need to add it as a sandboxed user solution for it to show up in the site collection's solution gallery. This approach worked for me.
$theSite = Get-SPSite "http://server/pathto/site"
# add the solution to the sandbox
Add-SPUserSolution (Resolve-Path .\relativePathTo.wsp) -Site $theSite
# get the user solution and activate it for the site
$customSolution = Get-SPUserSolution -Site $theSite | ? { $_.Title -match "Custom Template Title" }
Install-SPUserSolution $customSolution -Site $theSite
Once you have the sandboxed solution installed, the trick to using it to create a subsite is to use the object model to grab the template.
$localeId = 1033 # or whatever is appropriate for you
$customTemplate = $theSite.RootWeb.GetAvailableWebTemplates($localeId) | ? { $_.Title -match "Custom Template Title" }
Now, you can create a subsite based on NO template at all, and then apply the custom template:
$newSubsite = $New-SPWeb "http://server/pathto/site/subsite" # can also apply options for unique permissions, nav bar, etc.
$newSubsite.ApplyWebTemplate($customTemplate)
Related
start "odopen://sync/?siteId=$siteid17&webId=$webid17&listId=$listid17&userEmail=$upn&webUrl=$URL17&webtitle=$webtitle17&listtitle=$listtitle17"
How is it possible to run the following command inside Powershell without an appearing popup window or any userinteraction? I've tried adding /ArgumentList "/S", "/Background". Also tried with -WindowStyle Hidden at the end. Appreciate some help :)
Your command as-is basically says "Start the program that opens odopen:// (OneDrive) links" and can't really be given any silent style instructions. The proper way to configure this kind of thing is through OneDrive Group Policies, but we can cheat and set registry keys.
The link above goes into detail about how to configure group policy, but also tells us that the specific group policy setting to "Configure team site libraries to sync automatically" sets this registry key:
[HKCU\Software\Policies\Microsoft\OneDrive\TenantAutoMount]"LibraryName"="LibraryID"
And that your LibraryID is in this format, which looks familiar:
tenantId=xxx&siteId=xxx&webId=xxx&listId=xxx&webUrl=httpsxxx&version=1
So to put it in a script, I would use something like this, adapted from Nicola Suter's blog post here:
$tenantAutoMountRegKey = "HKLM:\SOFTWARE\Policies\Microsoft\OneDrive\TenantAutoMount"
$autoMountTeamSitesList= #{
#Enter your SharePoint libraries to configure here as key/value pairs
MySharePoint="odopen://sync/?siteId=$siteid17&webId=$webid17&listId=$listid17&userEmail=$upn&webUrl=$URL17&webtitle=$webtitle17&listtitle=$listtitle17"
}
# Check if the key exists and create if missing:
if (-not (Test-Path $tenantAutoMountRegKey)){ New-Item -Path $tenantAutoMountRegKey -Force }
# Add the sites for automatic mounting
$autoMountTeamSitesList | Set-ItemProperty -Path $tenantAutoMountRegKey -Name $_.Key -Value $_.Value
This generally takes effect the next time a user signs into OneDrive, though Microsoft warns it may take up to 8 hours to start syncing (Keeps hundreds of users from syncing the same library at the same time)
TL;DR: You cannot.
Using odopen will always show sign-in window (as stated here: https://learn.microsoft.com/en-us/onedrive/deploy-on-windows#help-users-sign-in), what you can do is only populate it with data, which is what you are already doing.
If you want to do it silently, there is documentation about it: https://learn.microsoft.com/en-us/onedrive/use-silent-account-configuration
Currently, we have Document Libraries created in SharePoint Online and would like to move them using Powershell to its own Subsite. The reason we would like to move them is that we would like to keep the version history. Since we are dealing with 1000s of files, I would like to use Powershell to complete this task.
I am currently connecting to my SharePoint site using:
Connect-PnPOnline -Url "Sitename" -UseWebLogin
Here is where I need assistance. I am trying to use Move-PnPFolder but I am not sure how to write a command that would define the source, destination, and move of all files in the document library to a subsite that I have manually created.
Here you need to mix of PnP and CSOM PS script... the normal way how we get the SharePoint list items... we need read the the list items then inside the foreach loop you need to call the below command : Move-PnPFolder -Folder 'Shared Documents/Reports/2016/Templates' -TargetFolder 'Shared Documents/Reports' Something like below :
foreach ($oneFolder in List. Folders) { Move-PnPFolder -Folder 'Shared Documents/Reports/2016/Templates' -TargetFolder 'Shared Documents/Reports' }
Note :
In the above command from the $oneFolder property you will get the source folder URL and you already know the target folder location.
This is just sample code to present the concept.
I am trying to do a simple task of creating a folder in an azure web app and add a file in it. Here is what I've achieved so far and need some help with the right commands
Add-AzureAccount
Select-AzureRmSubscription -SubscriptionName 'Demo'
$webApp = Get-AzureRmWebApp -Name 'test--app' -ResourceGroupName 'TEST-POC-AUTOMATION'
$webApp.<CANT FIGURE OUT WHICH COMMAND>
$root = 'D:\home\site\wwwroot\webapps\ROOT'
if (!(Test-Path $root))
{
md $root
}
I am trying to wonder if this is possible or i've to use KUDU API to achieve this. Appreciate any inputs.
You could use Kudu API to do this, check this link.
PUT /api/vfs/{path}/
Creates a directory at path. The path can be nested, e.g. `folder1/folder2`.
If you want to use Power Shell to call the API, you could check this example.
I want to execute the Project Properties command in the VBA menu of Excel application using Powershell.
Following is the script -
$excelApplication = New-Object -ComObject ("Excel.Application")
$excelApplication.Visible = $True
$workbook = $excelApplication.Workbooks.Open("C:\Workbooks\PasswordProtectedVBEFile.xlsm")
$appReference = $workbook.Application
$appReference.VBE.CommandBars(1).FindControl(2578, $True).Execute()
I encounter the error - You cannot call a method on a null-valued expression., an inspection revealed - $appReference.VBE is empty. i.e. Write-Host $appReference.VBE outputs empty line.
I want help in troubleshooting why do I get an empty value for VBE?
I found the way out!
In short, we need to grant access to VBA Project Model explicitly before we could automate/access programmatically using script.
Journey to this discovery was interesting. I stumbled on this git project which helped me troubleshoot the problem.
The solution to my problem was this security check which I found in referred project
$mo = Get-ItemProperty -Path HKCU:Software\Microsoft\Office\*\Excel\Security `
-Name AccessVBOM `
-EA SilentlyContinue | `
? { !($_.AccessVBOM -eq 0) } | `
Measure-Object
This security check ensures VBA Project model is available programmatically. Well though this is just a check against registry, I wanted to know how to set a value. It was simple and one time activity in Excel.
You could allow such programmatic access by checking the check box "Trust access to the VBA Project model". This setting could be accessed by navigating in Excel (2010) File > Options > Trust Center > Trust Center Settings > Macro Settings.
I'm trying to move my tools to powershell, can this be done in PowerShell? the bit I'm really interested in is:
IEventService es = tfs.GetService(typeof(IEventService)) as IEventService;
List<Subscription> ls = es.GetAllEventSubscriptions().ToList();
Edit: what I really want to do might be using a .NET assembly from powershell and this might then be a duplicate of Using .NET library from PowerShell
Here is a TFS API in PowerShell function that I found on a blog long ago that will get you started. I've posted it to a GitHub Gist. Basically you ensure you've loaded up the TFS assemblies into the AppDomain and then you can add any TFS Service Interfaces you want to the object and just operate on them just as you would in any c# application, etc.
https://gist.github.com/3288447
Once you have the TFS object returned from the method in the Gist above, you can operate on the loaded services like so:
#use work item service
$tfs = get-tfs $env:TFSSERVERURL -silent
$project = $tfs.wit.Projects | ?{ $_.Name -eq $projectName}
#todo - replace with text for query or file read -- this is deprecated
$query = $project.StoredQueries | ?{ $_.Name -eq 'Active Bugs' }
$queryText = $query.QueryText.Replace("#project","'$projectName'")
$results = $tfs.wit.Query($queryText)
#do something with the results...
In your request above you can just alter the get-tfs method to add your service interface to the set loaded and then operate on the .NET methods much like I do in the example above.