Anthony K O365
asked on
Powershell Question/ issue
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.Config uration.Ta sks.Securi tyPrincipa lIdParamet er". Error: "Parameter values of type Microsoft.Exchange.Configu ration.Tas ks.Securit yPrincipal IdParamete r can't be empty. Specify a value, and try again.
Parameter name: identity"
+ CategoryInfo : InvalidData: (:) [Add-ADPermission], ParameterBindin...mationEx ception
+ FullyQualifiedErrorId : ParameterArgumentTransform ationError ,Add-ADPer mission
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.Config
Parameter name: identity"
+ CategoryInfo : InvalidData: (:) [Add-ADPermission], ParameterBindin...mationEx
+ FullyQualifiedErrorId : ParameterArgumentTransform
ASKER
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!
"C:\Users\ktookes\Desktop\
Again, the script works. I will also try your scrip block and get back...
thanks!
ASKER
I just tried the script block provided and same error.
Replace
If ($_ -ne $null)
with
If ($_.trim() -eq "")
If ($_ -ne $null)
with
If ($_.trim() -eq "")
ASKER
Actually, after inserting this statement the errors go away! Thanks!
If $_ -ne $null not working then, try $_ -ne ""
If $_ -ne $null not working then, try $_ -ne ""
ASKER
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry! I thought I accepted the experts comments. I will correct.
ASKER
Thanks for the input. I'll keep this in mind.
Open in new window
If $_ -ne $null not working then, try $_ -ne ""