Link to home
Start Free TrialLog in
Avatar of Anthony K O365
Anthony K O365Flag for United States of America

asked on

Powershell Question/ issue

I am getting this error when using the following script:


GC "C:\Users.txt" |%{Add-MailboxPermission 'mailbox' -user $_ -AccessRights FullAccess}

the Users.txt is just a list of email addresses or logon names. The script works, but I still get these errors.  Any thoughts?


Cannot process argument transformation on parameter 'User'. Cannot convert value "" to type "Microsoft.Exchange.Configuration.Tasks.SecurityPrincipalIdParameter". Error: "Parameter values of type Microsoft.Exchange.Configuration.Tasks.SecurityPrincipalIdParameter can't be empty. Specify a value, and try again.
Parameter name: identity"
    + CategoryInfo          : InvalidData: (:) [Add-ADPermission], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Add-ADPermission
Avatar of SubSun
SubSun
Flag of India image

Script looks ok.. check your input file and make sure you don't have any empty lines.. Or try...

GC "C:\Users.txt" |%{
	If ($_ -ne $null){
	Add-MailboxPermission 'mailbox' -user $_ -AccessRights FullAccess
	}
}

Open in new window


If $_ -ne $null not working then, try $_ -ne ""
Avatar of Anthony K O365

ASKER

When you say 'empty lines' what do you mean? Here is the actual input path:

"C:\Users\ktookes\Desktop\Kens Share\Exchange Powershell Cmd\Users.txt" |%{Add-MailboxPermission  Mailbox -user $_ -AccessRights FullAccess}

Again, the script works. I will also try your scrip block and get back...

thanks!
I just tried the script block provided and same error.
Replace

If ($_ -ne $null)

with

If ($_.trim() -eq "")
Actually, after inserting this statement the errors go away!  Thanks!


If $_ -ne $null not working then, try $_ -ne ""
I've requested that this question be closed as follows:

Accepted answer: 0 points for ktookes's comment #a39600495

for the following reason:

There may be an issue with Powershell. However, the null statement worked for me. Thanks for the expertise!
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry! I thought I accepted the experts comments. I will correct.
Thanks for the input. I'll keep this in mind.