Solved

Powershell Question/ issue

Posted on 2013-10-25
9
814 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Save Exchange PowerShell Command 12 36
Exchange 2010 Migration to O365 6 38
output in HTML in Powershell 5 28
Ruby or Python 7 62
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

726 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