问题
Morning,
I wander if you guys can help.
here is the sample
$From = Read-Host "Alias of the User Please?"
Add-MailboxFolderPermission ${From}:\Calendar –User Test01 –AccessRights Editor
Add-MailboxFolderPermission ${From}:\Calendar –User Test02 –AccessRights Editor
Add-MailboxFolderPermission ${From}:\Calendar –User Test03 –AccessRights Editor
Add-MailboxFolderPermission ${From}:\Calendar –User Test04 –AccessRights Editor
Add-MailboxFolderPermission ${From}:\contacts –User Test01 –AccessRights Editor
Add-MailboxFolderPermission ${From}:\contacts –User Test02 –AccessRights Editor
Add-MailboxFolderPermission ${From}:\contacts –User Test03 –AccessRights Editor
Add-MailboxFolderPermission ${From}:\contacts –User Test04 –AccessRights Editor
So if I run this, the user get replace and its add and blank space after the name, consequently the command failed.
Weird is, if I write-Host in front of the command, it get replace without the blank space.
What can i edit in the command to work successfully.
Cheers
E
回答1:
I can't reproduce your problem. Are you sure you're not adding a space in the user-input?
It may be haiving a problem with casting your two values together as a string. You should define the path as a string and let the variable expand automatically, instead of trusting auto-cast. You could also add Trim()
to your user-input to remove any leading og trailing whitespaces that the user might have typed. Try:
$From = (Read-Host "Alias of the User Please?").Trim()
Add-MailboxFolderPermission "$From:\Calendar" –User Test01 –AccessRights Editor
.....
来源:https://stackoverflow.com/questions/24692694/unwanted-blank-space-after-variable