New-Object Cannot find an overload

PowerShell script exchange

New-Object Cannot find an overload

Veeam Logoby jevao » Fri Jul 24, 2015 4:17 pm

Just upgraded from Veeam 7 to Veeam 8.

Running a powershell script receive the following error:

Code: Select all

PS C:> $credential = Get-VICredentialStoreItem -Host vc.pf.com -File $sdir\storout

PS C:> $Username = $credential.user

PS C:> $Password = $credential.password

PS C:> $Domain = "vc.pf.com"

PS C:> $cred1 = "$Domain\$Username"

PS C:> $cred2 = "$Password"

PS C:> $Credentials = New-Object -TypeName Veeam.Backup.Common.CCredentials -ArgumentList $cred1,$cred2,0,0

New-Object : Cannot find an overload for "CCredentials" and the argument count: "4".
At line:3 char:16
+ $Credentials = New-Object -TypeName Veeam.Backup.Common.CCredentials -ArgumentLi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
 
jevao
Enthusiast
 
Posts: 29
Liked: 3 times
Joined: Fri Oct 28, 2011 11:38 pm
Full Name: James Collison

Re: New-Object Cannot find an overload

Veeam Logoby PTide » Fri Jul 24, 2015 4:49 pm

Hi,
New-Object : Cannot find an overload for "CCredentials" and the argument count: "4".
It seems that there is no overloaded New-Object method suitable for the amount of variables you specified ($cred1,$cred2,0,0 - four of them)

Please double-check your code and, if everything is in compliance with reference guide, kindly open a support case and post case ID here.

Thank you.
PTide
Veeam Software
 
Posts: 3021
Liked: 246 times
Joined: Tue May 19, 2015 1:46 pm

Re: New-Object Cannot find an overload

Veeam Logoby jevao » Fri Jul 24, 2015 8:50 pm

Thanks much for your reply.

Sorry, How do I understand how many arguments to supply this [Veeam.Backup.Common.CCredentials]

Code: Select all
$Credentials = New-Object -TypeName Veeam.Backup.Common.CCredentials -ArgumentList $cred1,$cred2,0,0


Thanks again.
jevao
Enthusiast
 
Posts: 29
Liked: 3 times
Joined: Fri Oct 28, 2011 11:38 pm
Full Name: James Collison

Re: New-Object Cannot find an overload

Veeam Logoby jevao » Sat Jul 25, 2015 10:12 pm

Thanks much for the reply.

Please let me know what I am missing. Thanks again.

Copied a backup script that used this command in the script that starting failing after upgraded to veeam 8:

Code: Select all

$Credentials = New-Object -TypeName Veeam.Backup.Common.CCredentials -ArgumentList $cred1,$cred2,0,0



New-Object cmdlet creates instance of type Veeam.Backup.Common.CCredentials.

veeam.backup.common.ccredentials is a static type.

Just put [] around it and you can use it.

Code: Select all

PS C:>  [Veeam.Backup.Common.CCredentials] | get-member -static

   TypeName: Veeam.Backup.Common.CCredentials

Name                                MemberType Definition                                                                           
----                                ---------- ----------                                                                           
AddToXml                            Method     static void AddToXml(System.Xml.XmlNode parentNode, Veeam.Backup.Common.CCredential...
Clone                               Method     static Veeam.Backup.Common.CCredentials Clone(Veeam.Backup.Common.CCredentials creds)
Create                              Method     static Veeam.Backup.Common.CCredentials Create(string userName, string password)     
CreateEmpty                         Method     static Veeam.Backup.Common.CCredentials CreateEmpty(bool isLocalProtect)             
Deserialize                         Method     static Veeam.Backup.Common.CCredentials Deserialize(string credsXml)                 
Equals                              Method     static bool Equals(System.Object objA, System.Object objB)                           
FromXmlData                         Method     static Veeam.Backup.Common.CCredentials FromXmlData(Veeam.Backup.Common.COutputXmlD...
GetFromXml                          Method     static Veeam.Backup.Common.CCredentials GetFromXml(System.Xml.XmlNode parentNode)     
IsEqual                             Method     static bool IsEqual(Veeam.Backup.Common.CCredentials credentials1, Veeam.Backup.Com...
IsNullOrEmpty                       Method     static bool IsNullOrEmpty(Veeam.Backup.Common.CCredentials credentials)               
ReferenceEquals                     Method     static bool ReferenceEquals(System.Object objA, System.Object objB)                   
Unserial                            Method     static Veeam.Backup.Common.CCredentials Unserial(System.Xml.XmlNode node)             
LINUX_USERNAME_RESTRICTED_SYMBOLS   Property   static string LINUX_USERNAME_RESTRICTED_SYMBOLS {get;}                               
RootTag                             Property   static string RootTag {get;}                                                         
WINDOWS_USERNAME_RESTRICTED_SYMBOLS Property   static string WINDOWS_USERNAME_RESTRICTED_SYMBOLS {get;}                             



OK so PTide was kind enough to tell me to look in reference guide.

Find cmdlet Get-VBRCredentials. Let’s try that.

Code: Select all

PS C:\users\veeam\scripts\addbk> Get-VBRCredentials | Get-Member -static


   TypeName: Veeam.Backup.Common.CCredentials

Name                                MemberType Definition                                                                           
----                                ---------- ----------                                                                           
AddToXml                            Method     static void AddToXml(System.Xml.XmlNode parentNode, Veeam.Backup.Common.CCredential...
Clone                               Method     static Veeam.Backup.Common.CCredentials Clone(Veeam.Backup.Common.CCredentials creds)
Create                              Method     static Veeam.Backup.Common.CCredentials Create(string userName, string password)     
CreateEmpty                         Method     static Veeam.Backup.Common.CCredentials CreateEmpty(bool isLocalProtect)             
Deserialize                         Method     static Veeam.Backup.Common.CCredentials Deserialize(string credsXml)                 
Equals                              Method     static bool Equals(System.Object objA, System.Object objB)                           
FromXmlData                         Method     static Veeam.Backup.Common.CCredentials FromXmlData(Veeam.Backup.Common.COutputXmlD...
GetFromXml                          Method     static Veeam.Backup.Common.CCredentials GetFromXml(System.Xml.XmlNode parentNode)     
IsEqual                             Method     static bool IsEqual(Veeam.Backup.Common.CCredentials credentials1, Veeam.Backup.Com...
IsNullOrEmpty                       Method     static bool IsNullOrEmpty(Veeam.Backup.Common.CCredentials credentials)               
ReferenceEquals                     Method     static bool ReferenceEquals(System.Object objA, System.Object objB)                   
Unserial                            Method     static Veeam.Backup.Common.CCredentials Unserial(System.Xml.XmlNode node)             
LINUX_USERNAME_RESTRICTED_SYMBOLS   Property   static string LINUX_USERNAME_RESTRICTED_SYMBOLS {get;}                               
RootTag                             Property   static string RootTag {get;}                                                         
WINDOWS_USERNAME_RESTRICTED_SYMBOLS Property   static string WINDOWS_USERNAME_RESTRICTED_SYMBOLS {get;}                             



Wow, same TypeName!

Add-VBRCredentials looks like it has all parameters needed. I will try that.

But if I wanted to use the static type and give it an argument list, is there a way to figure out the argument list.
Turns out there is. From:

http://learn-powershell.net/2013/03/14/ ... owershell/

Code: Select all

PS C:\users\veeam\scripts\addbk> ([type]"veeam.backup.common.ccredentials").GetConstructors() | ForEach {
    $_.GetParameters()
} | Select Name,ParameterType

Name                                                               ParameterType                                                     
----                                                               -------------                                                     
userName                                                           System.String                                                     
password                                                           System.String                                                     
userName                                                           System.String                                                     
password                                                           System.String                                                     
currentUser                                                        System.Boolean                                                   
isLocalProtect                                                     System.Boolean                                                   
changeTimeUtc                                                      System.Nullable`1[System.DateTime]                               
userName                                                           System.String                                                     
password                                                           System.String                                                     
currentUser                                                        System.Boolean                                                   
isLocalProtect                                                     System.Boolean                                                   
description                                                        System.String                                                     
changeTimeUtc                                                      System.Nullable`1[System.DateTime]                               



And this script is even better:

Code: Select all

PS C:\users\veeam\scripts\addbk> ([type]"veeam.backup.common.ccredentials").GetConstructors() | ForEach {
    ($_.GetParameters() | ForEach {$_.ToString()}) -Join ", "
}

System.String userName, System.String password
System.String userName, System.String password, Boolean currentUser, Boolean isLocalProtect, System.Nullable`1[System.DateTime] chang
eTimeUtc
System.String userName, System.String password, Boolean currentUser, Boolean isLocalProtect, System.String description, System.Nullab
le`1[System.DateTime] changeTimeUtc

jevao
Enthusiast
 
Posts: 29
Liked: 3 times
Joined: Fri Oct 28, 2011 11:38 pm
Full Name: James Collison

Re: New-Object Cannot find an overload

Veeam Logoby PTide » Mon Jul 27, 2015 10:08 am

Hi,

Sorry for not replying during the weekend.

In my post I just assumed what could have gone wrong. In your first post you never mentioned that everything worked fine before an upgrade. So, I suggest you to open a case with the technical support because if something 's gone unworkable after an upgrade that's a valid reason for support case to be opened.

Thank you.
PTide
Veeam Software
 
Posts: 3021
Liked: 246 times
Joined: Tue May 19, 2015 1:46 pm

Re: New-Object Cannot find an overload

Veeam Logoby v.Eremin » Mon Jul 27, 2015 1:53 pm

I think usage of Add-VBRCredentials (commandlet that has been created for credentials creation) might be easier than working directly with constructors. If you want to pass various credentials to the said commandlet, a simple cycle might do the trick, something like:

Code: Select all
foreach ($Credentials in $SavedCredentials)
{
Add-VBRCredentials -User $SavedCredentials.User -Password $SavedCredetials.Password
}


Thanks.
v.Eremin
Veeam Software
 
Posts: 13281
Liked: 970 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 5 guests