Solved

Powershell Question/ issue

Posted on 2013-10-25
9
816 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
[X]
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
  • 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this video we show how to create a Shared Mailbox 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 Recipients >> Sha…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

695 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