Solved

Powershell Question/ issue

Posted on 2013-10-25
9
809 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A brief introduction to what I consider to be the best editor for PowerShell.
In this video we show how to create a Distribution Group 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 >>…
To show how to generate a certificate request 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 Servers >> Certificates…

776 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