Zack
asked on
Powershell - Cannot find an overload for ".ctor" and the argument count: "1".
Hi EE,
I am running the following script (the script function is essentially to refresh databases from prod to UAT environments) see attached with the following command:
./Invoke-Edited.ps1 -Environment Test -ScriptBlock {param($p1, $p2)} -ArgumentList $ComputerName, $SQLBackupPath
I am running the scripts remotely and I am getting the following error
Cannot find an overload for ".ctor" and the argument count: "1".
At C:\Invoke-Edited.ps1:54 char:9
+ [ValidateNotNullOrEmpty('D C1PRDSQLFC I02')]
Any assistance is appreciated.
Thank you.
Edited.ps1
I am running the following script (the script function is essentially to refresh databases from prod to UAT environments) see attached with the following command:
./Invoke-Edited.ps1 -Environment Test -ScriptBlock {param($p1, $p2)} -ArgumentList $ComputerName, $SQLBackupPath
I am running the scripts remotely and I am getting the following error
Cannot find an overload for ".ctor" and the argument count: "1".
At C:\Invoke-Edited.ps1:54 char:9
+ [ValidateNotNullOrEmpty('D
Any assistance is appreciated.
Thank you.
Edited.ps1
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry Zack I didn't understand.
if you want to set a parameter value the way is:
Remove the Mandatory parameter (from $true), so that makes it mandatory=$false...
if you want to set a parameter value the way is:
Remove the Mandatory parameter (from $true), so that makes it mandatory=$false...
[Parameter(Mandatory=$false,Position=0)]
$ComputerName = "DC1PRDSQLFCI1"
ASKER
Hi Jose,
That's fine thank you very much for your assistance: I am stuck with this issue now;
Command: PS C:\> ./Invoke-Edited.ps1 -Environment Test -ScriptBlock {param($p1, $p2)} -ArgumentList $Comput
erName, $SQLBackupPath
A parameter cannot be found that matches parameter name 'ScriptBlock'.
What I'm trying to do is parse execute $ComputerName and SQLBackupPathName remotely on the target box.
If don't parse these variables to execute remotely, I get this error. Cannot bind argument to parameter 'Path' because it is null.
My apologies if my query is opaque.
Thank you.
That's fine thank you very much for your assistance: I am stuck with this issue now;
Command: PS C:\> ./Invoke-Edited.ps1 -Environment Test -ScriptBlock {param($p1, $p2)} -ArgumentList $Comput
erName, $SQLBackupPath
A parameter cannot be found that matches parameter name 'ScriptBlock'.
What I'm trying to do is parse execute $ComputerName and SQLBackupPathName remotely on the target box.
If don't parse these variables to execute remotely, I get this error. Cannot bind argument to parameter 'Path' because it is null.
My apologies if my query is opaque.
Thank you.
You'd need to defined the scriptblock:
like this:
Your ScriptBlock only receives 2 parameters ($p1,$p2) and DOES NOTHING :) hahaha
like this:
$sb = {
param(
[Parameter(mandatory=$true,position=0)]$A,
[Parameter(mandatory=$true,position=1)]$B
)
Write-Host "C: $($A+$B)"
}
Invoke-Command -ScriptBlock $sb -ArgumentList 1,3
Your ScriptBlock only receives 2 parameters ($p1,$p2) and DOES NOTHING :) hahaha
ASKER
Hi Jose,
Okay, but how can nest $sb inside the existing code structure:
I am not so sure that PowerShell allows for this can you clarify?
Thank you.
Okay, but how can nest $sb inside the existing code structure:
param
(
[Parameter(Mandatory=$true,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Select PeoplePoint environment")]
[ValidateNotNullOrEmpty()]
[ValidateSet("Development", "Test", "Training")]
[String]$Environment,
#[Parameter(Mandatory=$false,Position=0)]
#$ComputerName = ("DC1PRDSQLFCI1"),
# [Parameter(Mandatory=$false,Position=1)]
# $SQLBackupPath = ('\\DC1PRDSQLFCI1\Z$\MSSQL13.SQL2016APPS\MSSQL\Backup\DC1PRDSQLFCI02$SQL2016APPS\PeopleEntProd\FULL')
$ComputerName = ("DC1PRDSQLFCI1"),
$SQLBackupPath = ('\\DC1PRDSQLFCI1\Z$\MSSQL13.SQL2016APPS\MSSQL\Backup\DC1PRDSQLFCI02$SQL2016APPS\PeopleEntProd\FULL')
$sb = {
param(
[Parameter(mandatory=$true,position=0)]$ComputerName
,
[Parameter(mandatory=$true,position=1)]$SQLBackupPath
)
Write-Host "C: $($ComputerName+$SQLBackupPath)"
}
)
I am not so sure that PowerShell allows for this can you clarify?
Thank you.
ASKER
Hi Jose,
To clarify in the -Environment variable needs to be entered in manually by the user but the $ComputerName + $SQLBackupPath are to be fixed specified in the ps1 script and to be executed remotely.
Thank you.
To clarify in the -Environment variable needs to be entered in manually by the user but the $ComputerName + $SQLBackupPath are to be fixed specified in the ps1 script and to be executed remotely.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Jose,
Fair point and thank you for your assistance I will begin to pay around with this script and see if I can get it working.
Fair point and thank you for your assistance I will begin to pay around with this script and see if I can get it working.
ASKER
Okay if want to set the parameter value in the form of the pre-set variable can I use something like this? :
Open in new window
Thank you.