Receiving error when executing New-SPSite in PowerShell - sharepoint

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.

Related

powershell IQY dump script fails

I'm currently working on automating a powershell script to make a dump of a small DB.
The database is accessible through a company Sharepoint and I am leveraging an IQY file exported from said Sharepoint to read the database contents.
When I run the script manually (i.e. calling it from the command line), it works with no issues, but when I try and start the script from Task Scheduler, the following exception is raised:
System.Reflection.TargetInvocationException
the line that is generating the exception is:
$iqy = $xl.Workbooks.Open($query, 2, $true)
Where $xl is a new Excel.Application ComObject, created correctly and $query is a string containing the full file path of the iqy file.
As for my configuration, I'm trying to run my script on a Windows Server 2008R2, using a local administrator user (same user that is supposed to launch the scheduled script), which is also authorized to access the Sharepoint. I'm running Powershell 3.0. I'm not loading any Sharepoint-related snapins.
The only answers I found poking around hinted at granting "Trust" to the IQY file location and the Sharepoint itself in Excel. That did not help.
The Exception also seems to point at a sharepoint issue, but since the script runs fine when started manually, I cannot understand how it could be anything to do with Sharepoint.
Am I missing some intricacy of the Task Scheduler?
Any help would be greatly appreciated.
Never mind, I seem to have found an answer.
If anyone is encountering the same issue, it appear the Excel Com Object has a bug that does not allow it to run from the Task Scheduler if you set it to run regardless of whether the user is logged in.
To circumvent that create the following 2 folders on the machine where the script is supposed to run:
(32Bit, always)
C:\Windows\System32\config\systemprofile\Dektop
(64Bit)
C:\Windows\SysWOW64\config\systemprofile\Desktop
After creating the folders, it worked as expected.
Source: http://social.technet.microsoft.com/Forums/windowsserver/en-US/aede572b-4c1f-4729-bc9d-899fed5fad02/run-powershell-script-as-scheduled-task-that-uses-excel-com-object?forum=winserverpowershell

Can't Uninstall Sharepoint Application - Invalid State

Our Sharepoint 2013 Application failed to install and is stuck in a odd state. I followed the recommended approach for deleting the application using powershell commands on the hosted Sharepoint server, but it doesn't execute properly.
Visual Studio Deployment/Retract Reports:
Skipping the uninstall step because the app for SharePoint is in an invalid state and cannot be uninstalled.
PowerShell Commands
$instances = Get-SPAppInstance -Web http://mysite/sites/collection
$instance = $instances | where {$_.Title -eq 'Application.Title'}
Uninstall-SPAppInstance -Identity $instance
Executing this PS command throws...
The System Account cannot perform this action.
There is no option from the Sharepoint UI to remove the application, and retrying the install also fails. I've tried other user accounts to execute this powershell command (other than the system account), but no dice. I will have to delete the developer site collection if there is no other solution.
I'm faced this problem before on my Office 365 SharePoint Online when deploy SharePoint Hosted App. Then I submit Microsoft Service request and work with MS Technical Support Team on this issue. This problem seem to be something error in SharePoint backend database by itself (I'm not sure to consider it is SharePoint defect).
Did you check the app details installation error report? If you get the message:
"The content database on the server is temporarily unavailable."
Need help: Error 'Install App for SharePoint': An instance of this App already exists at the specified location., I'm quite not understand the answer but there is one comment from Jeremy Thake which seem to be deleted on this thread, he said that:
"…so I actually just restarted the whole environment and when Windows
came back up and I went to the SharePoint Site…the App was gone ;-)"
So here is my advice before you commit to delete your site collection:
Try to deploy your to the another developer site collection and check whether this problem still occur as the same.
Try to increase your app version or change app name/title/id and deploy to the same site collection and check whether this problem still occur as the same to your new app instance.
For SharePoint Server, try to restart IIS/Window Server if you're able to do that. Also install any latest SharePoint Update/CU.
For Office365 - SharePoint and have you have license account, you should submit the service request, if not you should wait about several day and try to remove this app instance again through UI.
Hope you can remove your app and know the root cause exactly.
I have faced this issue some times in on-premises SharePoint.
But for solving this I gave another account (or you can use 1 that you have) shell admin rights.
Note this account CAN'T be marked as a System account on SharePoint!!
Then with this different shell admin account you execute the same script. That always worked for me (I also got some strange installation behavior and needed do remove the app).

How to trigger a powershell script if some new items added in 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.

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

How to deploy RSWebParts.cab manually?

I'm using the SSRS 2005 Web parts to display my reports in a MOSS 2007 SP1 Portal. I have successfully installed the Web parts in my development, testing, and UAT servers using the following command: stsadm -o addwppack -filename path/to/RSWebParts.cab. But when I tried running the same command in the production server, it will give me the following error:
This solution contains no resources scoped for a Web application and cannot be deployed to a particular Web application.
I know I usually will get this kind of error message when I tried to deploy my custom solutions having no Web application resources (such as web.config entries) to a specific Web application. But this is not my custom solution, it is an out-of-the-box SSRS Web part and it does have resources scoped to a Web application.
I tried to even use different combination of the command by providing the -url, -globalinstall, and -force switches but it still give the same error.
The configuration of the 4 servers are exactly the same, both from software and hardware perspectives. All other features are working properly on the production server.
I even tried to extract the cab file manually to the bin folder of my Web application, then modify the Web.config manually to include the SafeControl element (copied from the manifest.xml inside the cab file). But it gave me an error saying it couldn't find the resources file. Even though, I extracted the whole file, including the resource files in the bin folder.
Is there anyone who can help me resolve the problem? Thanks a lot.
I have resolved it with the following command and it worked successfully. Do not add any extra things. The following code copies RSwebparts.cab in C:\ directory.
C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\BIN>
stsadm.exe -o addwppack -filename C:\RSWebParts.cab -globalinstall -force
Cheers & enjoy
Have you tried all possible combinations of the command?
The following combination works well for all of the web part packs we install:
stsadm -o addwppack -filename path/to/RSWebParts.cab -globalinstall -force -url ContentURL

Resources