UNwanted blank space after variable

送分小仙女□ 提交于 2019-12-11 21:08:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!