Reputation: 21
I'm new to using Kentico and I've been given a task to write a script with it using powershell. I'm having a little trouble getting started. I'm following "PowerShell Calling Reflected Kentico API" to try to get it to work. In particular, I tried:
# Configure path to the root of your web project
$webRoot = "C:\inetpub\...\CMS\"
$bin = $webRoot + "bin\"
# Load settings from web.config
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $webRoot + "web.config")
Add-Type -AssemblyName System.Configuration
[Configuration.ConfigurationManager].GetField("s_initState", "NonPublic, Static").SetValue($null, 0)
[Configuration.ConfigurationManager].GetField("s_configSystem", "NonPublic, Static").SetValue($null, $null)
([Configuration.ConfigurationManager].Assembly.GetTypes() | where {$_.FullName -eq "System.Configuration.ClientConfigPaths"}) [0].GetField("s_current", "NonPublic, Static").SetValue($null, $null)
# Add DLL resolution path
[System.AppDomain]::CurrentDomain.AppendPrivatePath($bin);
# Load CMSDependencies
Get-ChildItem -recurse "$webRoot\CMSDependencies\"|Where-Object {($_.Extension -EQ ".dll")} | ForEach-Object { $AssemblyName=$_.FullName; Try {Add-Type -Path $AssemblyName} Catch{ "Failed to load assembly: " + $AssemblyName + " " + $_.Exception.LoaderExceptions}}
# Load all assemblies from \bin\ (to be sure that all handlers get attached etc.)
Get-ChildItem -recurse "$bin"|Where-Object {($_.Extension -EQ ".dll")} | ForEach-Object { $AssemblyName=$_.FullName; Try {Add-Type -Path $AssemblyName} Catch{ "Failed to load assembly: " + $AssemblyName + " " + $_.Exception.LoaderExceptions}}
# Optionally, replace the above with loading only the minimum set of assemblies
#$references = @(("CMS.Base.dll"),("CMS.DataEngine.dll"), ("CMS.DataProviderSQL.dll"),("CMS.Membership.dll")) | Foreach-Object{ $bin + $_ }
#Add-Type -Path $references
# If the API you are going to use is about to touch the file system set the web application root path
#[CMS.Base.SystemContext]::WebApplicationPhysicalPath = $webRoot
# Initialize application
"Application initialized:" + [CMS.DataEngine.CMSApplication]::Init();
But I'm getting an error on [CMS.DataEngine.CMSApplication]::Init():
Exception calling "Init" with "0" argument(s): "Login failed for user ..."
What might be the issue with the login?
Upvotes: 0
Views: 160
Reputation: 1869
I think that this is an error with your SQL connection. Check your web.config
file to see if you're using trusted authentication in the connection string (CMSConectionString
). If you're using trusted, it may simply be that the user that you're using to run PowerShell does not have the correct SQL permissions.
Upvotes: 3