none
Room script which isn't working, did before RRS feed

  • Question

  • Morning,

    I can't figure out why this isn't working, it's a slightly modified script which I got help with previously and now it's not working.

    $Rooms = Get-Content "C:\roomlist.txt"
    
    foreach ($Rooms in $Rooms)
    {
    	$Path = $Rooms + ":\Calendar"
    	
    	{
    		Add-MailboxFolderPermission -Identity $Path -User singleusernamehere -AccessRights Owner
        }
    }


    Any help is appreciated.


    Tuesday, January 20, 2015 9:57 AM

Answers

All replies

  • I tried that, it didn't work :(
    Tuesday, January 20, 2015 10:57 AM
  • I got the following error

    Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
    At line:4 char:3
    + { $Path = $Room + ":\Calendar"
    +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
        + FullyQualifiedErrorId : MethodNotFound

    Tuesday, January 20, 2015 11:00 AM
  • Hi,

    you are using $rooms in $rooms same variable multiple time. it might be causing this.

    $Rooms = Get-Content "C:\roomlist.txt"

    foreach ($Room in$Rooms)
    {
    $Path
    = $Room + ":\Calendar"

    {
    Add-MailboxFolderPermission -Identity $Path -User singleusernamehere -AccessRights Owner
       
    }
    }

    • Proposed as answer by Mike Laughlin Tuesday, January 20, 2015 2:47 PM
    Tuesday, January 20, 2015 11:51 AM
  • Did it manually... :(
    • Marked as answer by Alexgreen312 Tuesday, January 20, 2015 1:04 PM
    Tuesday, January 20, 2015 1:04 PM
  • Please look at what you typed:

    foreach ($Rooms in $Rooms) <<<===  two of the same variable won't work
    { $Path = $Rooms + ":\Calendar"
     

    It needs to be:

    foreach($r in $rooms){
      $path='{0}:calendar' -f $r.Trim()

    This will prevent issues with the colon in a string and with extra spaces in lines.  Room names must be formatted correctly.


    ¯\_(ツ)_/¯



    • Edited by jrv Tuesday, January 20, 2015 5:09 PM
    Tuesday, January 20, 2015 5:09 PM