Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Powershell Question/ issue

Posted on 2013-10-25
9
812 Views
Last Modified: 2013-10-25
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
0
Comment
Question by:K Anthony O365
  • 6
  • 3
9 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 39600430
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 ""
0
 

Author Comment

by:K Anthony O365
ID: 39600455
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!
0
 

Author Comment

by:K Anthony O365
ID: 39600471
I just tried the script block provided and same error.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 40

Expert Comment

by:Subsun
ID: 39600493
Replace

If ($_ -ne $null)

with

If ($_.trim() -eq "")
0
 

Author Comment

by:K Anthony O365
ID: 39600495
Actually, after inserting this statement the errors go away!  Thanks!


If $_ -ne $null not working then, try $_ -ne ""
0
 

Author Comment

by:K Anthony O365
ID: 39600530
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!
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39600531
You have accepted your comment instead of experts comment as answer.. :-)

This means you have trailing empty lines in your text file.. In following example.. there are three empty lines after UserC so script will throw three errors.. $_ -ne "" or $_.trim() -eq "" will instruct the script to ignore such lines so you won’t get any error..


UserA
UserB
UserC


  

Open in new window

0
 

Author Comment

by:K Anthony O365
ID: 39600580
Sorry! I thought I accepted the experts comments. I will correct.
0
 

Author Closing Comment

by:K Anthony O365
ID: 39600588
Thanks for the input. I'll keep this in mind.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
Find out what you should include to make the best professional email signature for your organization.
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…
This video discusses moving either the default database or any database to a new volume.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question