When upgrading to EPi 10 I try to convert the database with powershell for the staging environment. I run the following:
(...)\packages\EPiServer.Framework.10.0.1\tools> powershell -ExecutionPolicy ByPass Import-Module .\ConvertDatabaseToUtc.psm1 -Verbose
which runs fine. But when I try to run ConvertEPiDatabaseToUtc, I get the message "...is not recognized as the name of a cmdlet, function, scriptfile...". Any idea what I am doing wrong?
I think it's Convert-EPiDatabaseToUtc, note the hyphen.
No, that's if you run it in PackageManagerConsole. http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Deployment/storing-utc-date-and-time-in-the-database/
Ok. I think I understand the problem. You seems to be running in a command line context. You should run it in the context of powershell, such as PS ISE. Otherwise the modules imported will not be available on your next command.
Thanks. I run it with Windows Powershell ISE as Administrator. Isn't that enough?
It should be enought to be admin.When your run the import with the verbose flag on, does it say anything that can hint on what is happening?
This is the entire response when I run the command:
"powershell -ExecutionPolicy ByPass Import-Module .\ConvertDatabaseToUtc.psm1 -Verbose"
VERBOSE: Loading module from path 'C:\Prosjekter\[project]\packages\EPiServer.Framework.10.0.1\tools\ConvertDatabaseToUtc.psm1'.VERBOSE: Exporting function 'Get-WebConfig'.VERBOSE: Exporting function 'New-DateTimeConversionOffset'.VERBOSE: Exporting function 'GenerateOffsets'.VERBOSE: Exporting function 'CreateOffsetRows'.VERBOSE: Exporting function 'CreateOffsetInDB'.VERBOSE: Exporting function 'InitFieldNames'.VERBOSE: Exporting function 'InitBlocks'.VERBOSE: Exporting function 'RunBlocks'.VERBOSE: Exporting function 'SwitchToUtc'.VERBOSE: Exporting function 'ExecuteSP'.VERBOSE: Exporting function 'ConvertEPiDatabaseToUtc'.VERBOSE: Exporting function 'GetConnectionString'.VERBOSE: Exporting function 'Convert-EPiDatabaseToUtc'.VERBOSE: Importing function 'Convert-EPiDatabaseToUtc'.VERBOSE: Importing function 'ConvertEPiDatabaseToUtc'.VERBOSE: Importing function 'CreateOffsetInDB'.VERBOSE: Importing function 'CreateOffsetRows'.VERBOSE: Importing function 'ExecuteSP'.VERBOSE: Importing function 'GenerateOffsets'.VERBOSE: Importing function 'Get-WebConfig'.VERBOSE: Importing function 'GetConnectionString'.VERBOSE: Importing function 'InitBlocks'.VERBOSE: Importing function 'InitFieldNames'.VERBOSE: Importing function 'New-DateTimeConversionOffset'.VERBOSE: Importing function 'RunBlocks'.VERBOSE: Importing function 'SwitchToUtc'.
Looks good, and after that running the command in the same folder gives you the error?
I had the same problem when running the script in pre-prod. The staging environment worked fine, even though their setup should be identical. I haven't found the reason yet.
The error was "Get-Project is not recognised...". I simply commented out the line "$connectionString = GetConnectionString $connectionString" and everything worked.
GetConnectionString tries to analyze your project and figure out your connectionstring. Since this is passed as an argument, I figured this line was not needed.
@Espen The cmdlet Convert-EPiDatabaseToUtc (with a hyphen) is designed for Visual Studio so it requires cmdlets like Get-Project. When you run standalone just call the function ConvertEPiDatabaseToUtc to bypass this.
@Torunn Remove "powershell -ExecutionPolicy ByPass" if you run inside ISE, otherwise you start another powershell session rather than importing the module in your session.
Thanks everyone! The reason I added "powershell -ExecutionPolicy ByPass" was that I got the error "the running scripts are disabled on this system". What I did, was to change this policy by running "Set-ExecutionPolicy RemoteSigned".
Then I was able to run the Import-Module without the bypass, and finally run ConvertEPiDatabaseToUtc.
Does cmdlet Convert-EPiDatabaseToUtc work with connectionstring in a separate file with configSource option? I couldn't make it working without specify the full connectionstring in the parameter when using the configSource.
p.s. I see the Get-WebConfig function handles the configSource, but not sure how to debug this. Would you be able to give some details how Epi team debug these PS scripts?