Ive been using a custom class for some time like this in PS (2.0):
import-module .\MyClassLib.dll
$task = New-Object MyClassLib.OracleScript -Property @{
Files="MyScript.sql"
Database="TEST"
User="USER"
Password="PASSWORD"
}
$result = $task.Execute()
And this works just fine.
However i wanted to create a CmdLet in C# to do the work instead. So after creating the cmdlet i thought I could do one of the following:
Invoke-OracleScript @{
Files="Script.sql"
Database="db"
User="user"
Password="password"
}
Invoke-OracleScript @{
Files="Script.sql";
Database="db";
User="user";
Password="password";
}
Invoke-OracleScript -Property @{
Files="Script.sql"
Database="db"
User="user"
Password="password"
}
But no luck. :(.
I keep getting errors like:
- Cannot find the file System.Collections.Hashtable ( it thinks the entire hashtable is the Files parameter)
- A parameter cannot be found that matches parameter name ‘Property’
- And a couple more.
My Class:
[Cmdlet(VerbsLifecycle.Invoke, "OracleScript", ConfirmImpact = ConfirmImpact.High, SupportsShouldProcess = true, SupportsTransactions = false)]
public class Invoke_OracleScript : Cmdlet, IOracleScript
{
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public string Files { get; set; }
[Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public string Database { get; set; }
....
If I instead use parameters like this: -Files “” -Database “”, it works just fine, but everything has to be on 1 line which is very bad for reading. So the hashtable is really my biggest wish :).
Can anyone explain to me what im missing here?
(ParameterSets?, a secret attribute i’ve been unable to find in the docs, other)
Kind regards
If all you care is to make the cmdlet call to be in multiple lines, you can use backtick (`) to extend the command to the next line:
Or, you can create custom object:
Or, what you were doing:
I think hashtable as objects was a feature that was added in v3.0 ( currently in CTP)