question

Saravanaraj-6475 avatar image
0 Votes"
Saravanaraj-6475 asked LimitlessTechnology-2700 answered

Powershell "Cannot process argument"


I am running into below error while trying to run this piece of code, can someone throw some light on what I am missing here? Thanks!

 $SecurePassword = ConvertTo-SecureString "password" -AsPlainText -Force -ErrorAction Stop
 $SSCred = New-Object System.Management.Automation.PSCredential ("PROD\username", $SecurePassword) -ErrorAction Stop
 Write-Host "$(Get-date): Done Secret Server Login"
    
 $AzureProdLock = Get-SecretServerCredential -SamAccountName pjob9001 -OperatorCredentials $SSCred -Verbose:$True -ErrorAction Stop
 $Null = Connect-AzAccount -ServicePrincipal -Credential $AzureProdLock -Tenant "tenantId" -ErrorAction Stop -WarningAction SilentlyContinue



Error msg:
"Exception calling ".ctor" with "2" argument(s): "Cannot process argument because

the value of argument "userName" is not valid. Change the value of the "userName" argument and run the operation again.""

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

mschiavon avatar image
0 Votes"
mschiavon answered

Try single quote "PROD\username" => 'PROD\username'

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hello Saravanaraj,

PowerShell protects access to variables, aliases, functions, and PowerShell drives (PSDrives) by limiting where they can be read and changed. PowerShell uses scope rules to ensure that you do not inadvertently change an item that should not be changed.

In the second line for PROD\ avoid double quotes ("PROD\username") and replace them with single quotes ( 'PROD\username' )


https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes?view=powershell-7.1#parent-and-child-scopes

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.1#double-quoted-strings

Hope this answers all your queries, if not please do repost back.
If an Answer is helpful, please click "Accept Answer" and upvote it : )

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.