Cannot enable feature with feature receiver via PowerShell - powershell

I've got a problem where I can enable a feature the UI and everything works as expected through site settings, but if I try and enable the feature via the Sharepoint powershell (which we are doing as part of a scripted deployment), I get the following:
Enable-SPFeature : Failed to create
receiver object from assembly "xxxxx,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=967e6960f5af91e6 ",
class "xxxxx.EventReceiver" for
feature "xxxxx.Public.Search" (ID:
026d7c45-a359-4550-822d-1a6c35e58e0
d).: System.ArgumentNullException:
Value cannot be null. Parameter name:
type
Does anyone know why this would occur, or some things I should check? The feature definition is definitely correct (since deploying it through the UI works as expected, and I've also double checked the PublicKeyToken is correct etc etc), and restarting the services and iisreset doesn't enable me to use Enable-SPFeature either.

I have the same issue. The curious thing is when you open up a new SP2010 powershell window and reissue the same command the assembly is found without any problems. See:
http://khurramdotnet.blogspot.com/2011/01/enable-spfeature-command-throwing.html

Try this: go to the Control Panel, click on "Programs", click on "Programs and Features", select "Microsoft SharePoint Server 2010" (or whatever you have installed), click "Change", select "Repair" and click "Continue". This is what helped me.

Try this: http://geoffwebbercross.blogspot.ca/2011/06/failed-to-create-receiver-object-from.html
It worked for me, I did not have to change a stitch in my code / solution

I had this yesterday, turns out the feature name and the feature receiver name werent matching. To resolve it I copied the FeatureActivated code into notepad (entire code block) or whichever events it is you have coded.
Copy the entire event code that you
have written I.e. the
FeatureActivated method (including
signature)
Remove the EventReceiver
from your project.
Add a new event
received to your project (you can
double check the name for changes)
Paste the Event code back into the
event receiver.
I use the following code to deploy using powershell
if(($Solution -ne $null) -and ($Solution.ContainsWebApplicationResource))
{
if ($FeatureScope -eq "Web")
{
Install-SPSolution $SolutionName -url $siteUrl -GACDeployment -Confirm:$false
}
else
{
Install-SPSolution $SolutionName -AllWebApplications -GACDeployment -Confirm:$false
}
}
else
{
Install-SPSolution $SolutionName -GACDeployment -Confirm:$false
}
while($Solution.Deployed-eq$false)
{
Start-Sleep 2
Write-Host "." -NoNewline
}

Don't use the "normal" PowerShell, use the SharePoint 2010 Management Shell instead.

Related

Running powershell without useriteraction

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

How do I run Invoke-WebRequest cmdlet from third party program?

I have been trying to get this to work via a game control panel TCAdmin.
$ModPg1 = Invoke-WebRequest "http://steamcommunity.com/sharedfiles/filedetails/?id=731604991"
$ModVer1 = ($ModPg1.ParsedHtml.getElementsByTagName('div') | Where{ $_.className -eq 'detailsStatRight' } ).innerText | Select -Last 1
If I run this cmdlet via a program like TCAdmin (or task scheduler), I get the following error....
Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
Explorer is installed, and set up. The script works just fine if I run it manually.
My guess is there is a way to get TCAdmin to run the scripts the same way I would as a windows User.
Cant find a way nearly as simple to scrape the info 'm looking for.
As for this...
get TCAdmin to run the scripts the same way I would as a windows User.
For any app to run as a user, that users profile must be used on the host where the code is to be run. You cannot natively run PoSH on a host as another user context. This is not a PoSH issue, it is a Windows User Principal security boundary. There are tools that let you do this. For example SysInternal PSExec and AutoIT. Yet as stated that error is pretty specific. The user profile for Internet Explorer has not been created and that only happens when you use IE at least once.
So, as Adam points, out, use the setting the error message states to use or use your code to start IE at least once.
$SomeUrl = 'https://stackoverflow.com'
$ie = New-Object -com internetexplorer.application
$ie.visible = $true
$ie.navigate($SomeUrl)
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1 } # Wait for IE to settle.
Again, if trying to run this in the context of another user, the two above tools will get you there, but you still have to fire up IE to have a profile for it.

Accessing Excel VBA editor from Powershell

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.

Sitecore powershell script - how to initialize custom scripts

I used sitecore powershell last year to migration heaps of items.
I installed the latest one and I don't see "Initialization script" field under Console/All Users item.
I had used this field to intialize all my custom scripts like below so that I can access from PSE.
Execute-Script -Item (Get-Item -ID "{0B0E50B9-CD3C-4FE7-BB6D-D2A9AAEB7568}" -Path master:\)
Any help will be good.
This was removed in SPE 3.1 due to the unpredictable nature.
https://github.com/SitecorePowerShell/Console/issues/365
If you could post a new issue on what your custom script does, perhaps we can provide you with an alternate solution.

Merge-SPLogFile- Doesn't return me any records

thanks for taking the time to try any help me out!
As the title suggests I cannot get the Merge-SPLogFile cmdlet to return me any results!
I find hunting down error messages in SharePoint logs a very time consuming and laborious process- Being relatively new to PowerShell I only recently stumbled across the cmdlet. Knowing how much time this could save me I was excited to implement it.
I started with the following code:
Add-PSSnapin Microsoft.SharePoint.Powershell
$correlationId = "C826869C-4A8E-10E2-6C5E-58A1C87EB651"
Merge-SPLogFile –Path “C:\Users\Administrator\Desktop\SPLog.log” –Correlation $correlationId -Overwrite
This gives me the warning- "WARNING: Cmdlet did not return any records in the log file. Check your time range or filters."
Naturally I typed the error into my search engine and it seems other people have had the same problems when the -Correlation argument isn't in upper case. I tried both uppercase and lowercase but to no avail. I was able to manually find the GUID in the logs so I know it exists.
When I ran out of luck with this technique I thought I would try filtering using different arguments (by time):
Add-PSSnapin Microsoft.SharePoint.Powershell
[int] $HowFarBack = 15
[int] $howFarBackInMinutes = (-1) * $HowFarBack
[datetime] $startDateTime = [System.DateTime]::Now.AddMinutes($howFarBackInMinutes)
write-host $startDateTime
Merge-SPLogFile -Path 'C:\Users\Administrator\Desktop\SPLog.log' -Overwrite -StartTime $startDateTime
I get exactly the same error. To rule out my arguments being incorrect I tried not giving it a filter at all:
Add-PSSnapin Microsoft.SharePoint.Powershell
Merge-SPLogFile -Path 'C:\Users\Administrator\Desktop\SPLog.log' -Overwrite
I still get- "WARNING: Cmdlet did not return any records in the log file. Check your time range or filters." The logs are all there and in the default "LOG" folder within the 15 hive. I haven't changed any logging settings away from the defaults.
I am running on SharePoint 2013 Foundation.
What am I doing wrong?
The problem in my case was that there was no diagnostic logging activated for my SharePoint Farm.
How to enable diagnostic logging
Go to your Central Administration (usually http://YOUR_SHAREPOINT:10000/) (there is also a shortcut in your start menu on the server you installed the SharePoint at)
Go to "Monitoring"
Under "Reporting" click "Configure diagnostic logging"
Select the categories that you want to merge in case of an Error. I just selected All Categories here. Then click the "Ok" button at the bottom of the page.
(5. Reproduce the error and use the SP Shell again to Merge the Log Files)