Solved

Powershell Question/ issue

Posted on 2013-10-25
9
800 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:kt KTAdmin
  • 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:kt KTAdmin
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:kt KTAdmin
ID: 39600471
I just tried the script block provided and same error.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39600493
Replace

If ($_ -ne $null)

with

If ($_.trim() -eq "")
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:kt KTAdmin
ID: 39600495
Actually, after inserting this statement the errors go away!  Thanks!


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

Author Comment

by:kt KTAdmin
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:kt KTAdmin
ID: 39600580
Sorry! I thought I accepted the experts comments. I will correct.
0
 

Author Closing Comment

by:kt KTAdmin
ID: 39600588
Thanks for the input. I'll keep this in mind.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
how to add IIS SMTP to handle application/Scanner relays into office 365.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now