The Sitecore Powershell console is the coolest thing in Sitecore. Totally amazing piece of work. If I had to choose one thing I was allowed to use on a Sitecore project it would be Powershell. Or SIM. Or Sitecore Sidekick. Aaargh! Too many cool toys.
Anyway, I had a requirement recently to run some code. Without deploying code. Standard.
While driving over the mountain – I had a sudden idea. Can I use Sitecore Poweshell to call my existing classes to do what I want?
#Set up some test data $assetId = 2428 $derivativeDefinitionId = 1</code> #Create a class $helper = New-Object Kumquat.SAS.Picturepark.PictureparkServiceHelper #Put the test data in the correct classes $test = New-Object "System.Collections.Generic.List[Kumquat.SAS.Picturepark.Data.PacResponse]" $pacResponse = New-Object Kumquat.SAS.Picturepark.Data.PacResponse $pacResponse.AssetId = $assetId $pacResponse.DerivativeDefinitionId = $derivativeDefinitionId $test.Add($pacResponse) #Run the code $downloads = $helper.GetAssetDownloads($test) #Report Write-Host "Download Url: " $downloads.DownloadUrl
So this code creates an instance of a class, pops some test details in a list and then calls a method on the class.
Isn’t that cool??
Also, letting any old content editor do this is scarily dangerous. Imagine, the power of .Net at your fingertips. We could break some serious shtuff.
I’m guessing that’s (one reason) why the latest version of Powershell includes a security feature which forces you to provide your authentication details when running Powershell… Get upgrading people!