How to trigger a powershell script if some new items added in sharepoint - sharepoint

We are having Sharepoint lists where users would update their required services.
Based on the service type we will take action.
For ex: Our Sharepoint site will have actions like "build" "Copy" "Sync in Appstore".
For each action there is a powershell script written.
If a request is raised for build, powershell script should be triggered.
How to achieve it using powershell?

Take a look at SharePoint event receivers. Here's some example code written in PowerShell:
23JUN22 update - web archive with example code: https://web.archive.org/web/20141113023454/http://sharepintblog.com/2011/06/04/adding-event-receivers-with-powershell/ replacement for original link http://sharepintblog.com/2011/06/04/adding-event-receivers-with-powershell/

Basically how you would in any other framework, i think you can give it a file path as a command line to run the script of the given location.

Related

NetSuite Script Works in SANDBOX but not PRODUCTION account

I have a very simple NetSuite scrip that sets the value of the externalid when the record is saved. I have done testing on the SB account and it is working as expected. Copying the same configuration into the production account and the script is not executing. I've even added some dialog boxes to see if I can see any activity but there is none. The script is deployed, released and has "all roles" as the audience.
Any ideas what I can do to get the script to work?
Thanks.
Is your sandbox a very recent copy of Production? Does it have all the same scripts deployed as there is in production? You may want to look at the scripted record list for User Event Scripts in both environments, make sure they are the same.
You could also post your code here for us to look at it.

How do you permanently delete a folder inside an Azure VSTS project?

I have folders within both Azures VSTS (a TFVC repository) and TFS that I needed to permanently delete. On TFS this was quite easily done using the tf destroy $/<MyProject>/<Folder_To_Delete> command in a command window on the server on which the TFS is running. The web page in learn.microsoft.com that describes the "tf destroy" command (Https:// learn.microsoft.com/en-us/vsts/tfvc/destroy-command-team-foundation-version-control) shows that this command is also available for VSTS however I have been unable to get the command to work within a Developer Command Prompt window running on my local box.
tf destroy $/<MyProject>/<Folder_To_Delete> /collection:https://<MyTeamService>.visualstudio.com/<MyProject> /login:<userid>,<password>
The error I receive back is
TF31002: Unable to connect to this Team Foundation Server:
Team Foundation Server Url:
Possible reasons for failure include:
- The name, port number, or protocol for the Team Foundation Server is incorrect.
- The Team Foundation Server is offline.
- The password has expired or is incorrect.
Technical information (for administrator):
The remote server returned an error: (404) Not Found.
However if I put the URL into a browser my VSTS instance shows up. So the 404 looks to me like azure is blocking outside efforts to permanently delete on VSTS. I have logged onto the Azure portal expecting to find something like the Advanced tools option you would find on Web App Services, But the Team Services / Team Projects has nothing like this. Can someone explain to me how to properly execute the "tf destroy" command on Azure Team Services? Or does Azures VSTS just lack the support to permanently delete individual folders and files?
The tf destroy command requires a collection URL. In VSTS, there is no concept of a collection, only team projects. All team projects are created under the Default Collection.
To use the tf destroy command with VSTS, your collection URL must be in the following format:
https://accountname.visualstudio.com/DefaultCollection
By putting a collection URL of https://accountname.visualstudio.com/Project Name, the command was looking for a collection called Project Name in the VSTS account, which does not exist.
This command works:
Open a Developer Command Prompt in administrator mode and issue the following command and supply your credentials.
tf destroy $/Project Name/Folder To Delete /collection:https://accountname.visualstudio.com/DefaultCollection
To Permanently destroy an item/folder in VSTS is also using Destroy Command (Team Foundation Version Control)
tf destroy [/keephistory] <itemspec1>[;<versionspec>][<itemspec2>...<itemspecN>]
[/stopat:<versionspec>] [/preview] [/startcleanup] [/noprompt] [/silent] [/login:username,[password]] [/collection:TeamProjectCollectionUrl]]
/collection which specifies the team project collection. However, in VSTS you only have one collection. There is no collection name like TFS in the url. And multiple collections under user voice:
Let us create multiple collections on Visual Studio Team Services
https://developercommunity.visualstudio.com/idea/365419/let-us-create-multiple-collections-on-visual-studi.html
So, when you specify /collection for VSTS in tf command line, you just need to enter https://xxx.visualstudio.com
Also pay attention to the /login:<userid>,<password>, you are using the wrong format, it should be /login:userid,[password], add a /preview for test first(When tf destroy runs in the preview mode, the files are not actually destroyed.)
Finally the result will be
When you remove the /preview and perform the really destroy, you will also get a prompt info:
Do you want to destroy $/Scrum/NugetTest/Capture1025.PNG and all of
its children? (Yes/No/All)
Select Yes to delete folder and files in it, All with all of its children.
https://<MyTeamService>.visualstudio.com/<MyProject> is the wrong URL. It should just be https://<MyTeamService>.visualstudio.com/.
The parameter is asking for a project collection, not a team project within the collection.

How to Create a VM and deploy an application in Azure Resource Group Template

I want to create a set of VMs using either the Resource Group Template in VS 2015 or utilise one of the azure-quickstart-templates as the basis for doing this.
My specific requirements are also to install a simple .exe application and modify its .ini file with a key that I want to pass from the template, i.e. seqno = copyindex() or similar.
Can anybody provide some guidance please?
For a simple Windows VM you can use either a DSC Extension or a Custom Script extension on the VM. Both of the samples in the azure-quickstart repo require you to figure out how to stage the artifacts needed for the extension (in this case the EXE and the script that installs the EXE).
If you go the VS 2015 route, you can start with a VM template, add the DSC or custom script extension and then the PowerShell script provided by Visual Studio will stage the artifacts for you if you make them part of the project.
You can also mix/match - grab a template from github, modify it in VS or take the VS PowerShell script and bring it into whatever workflow works best for you.
Note: one thing to keep in mind as well - you need to pass the location of that EXE into the script that does the install - that script/vm will need to know where to get it from. In the VS 2015 workflow you can use the parameter values of _artifactsLocation and just pass that value along to the installation script. If you start with a quickstart template, you have to manage that yourself.

Receiving error when executing New-SPSite in PowerShell

I have two web applications in SharePoint 2010 that are both empty (and were created the same way through Central Admin). I have a PowerShell script that creates a new site collection and then automates various other tasks after the site collection is created. I can execute my script successfully in the first web application. Then, when executing the same script on the second web application, the following error is rendered:
"The system cannot find the file specified."
After some investigation, I have found that this command was breaking:
New-SPSite -url $newsite -name $newname -template "STS#0"
The specific error is happening because the site template (STS#0) cannot be found. I have also tried creating the site with different templates, but I get the same error. It is acting as if the second web application cannot find any of the site templates.
Thoughts?
Must have been an IIS issue. Rebooted the box and all is well.

Sharepoint Timer job deployment issue while deploying Feature through the Visual Studio 2010

I created "Timer Job" in two ways,
1.Created a SharePoint Project through the Visual Studio 2010 and added several Features and webparts that's successfully deployed later i added the "Timer job" through the feature with the scope "Site" the timerjob not available in "Job Definitions".
2.When created a project with timer job feature only it's available in "Job Definitions".
I need to deploy the timer job along with other features as mention in first scenario
Regards,
Pavan.
You should deploy timer jobs in features scoped "Web Application". Please post the code you register your job with if this does not resolve your issue.
I've successfully deployed timer jobs to features scoped as tightly as 'Web' with no issues.
Doing it this way made it easier for me get the job settings to associate with specific list instances and I don't have to hard code any site collection URLs or whatever into the job code.
You still have to make sure you get it registered with the Web Application, and here's how I designed my feature activation for my web-scoped feature:
Public Overrides Sub FeatureActivated(ByVal properties As SPFeatureReceiverProperties)
Dim web As SPWeb = DirectCast(properties.Feature.Parent, SPWeb)
' Remove job if it exists.
DeleteJobAndSettings(web.Site.WebApplication)
' Create the job.
Dim job As New TimerJob_myClass(TimerJob_myClass.JobName, web.Site.WebApplication)
Also, even though it's a Web feature and shows up under 'Manage Features', it's better to mark it hidden. This type of feature can only be activated by running an stsadm command line from PowerShell. For example:
stsadm -o activatefeature -url http://intranet.contoso.local/ -id 01234567-AAAA-BBBB-CCCC-DDDDEEEEFFFF
You should run PowerShell as a user who has rights on the content database associated with the site your working with. The app pool that would have normally run the feature receiver code during a GUI activation does not have access to the config database and that's why it fails via GUI.
my problem solved in production by activating feature with the following powershell
Enable-SPFeature -identity "sample_Job Definition" -URL http://portaluat
my job definition scope was Site

Resources