how to manage my office 365 remotely

hello All,

i am having a problem in connecting my local office 365 and manage things remotely.
the below scrip works fine when i am trying to connect to my office 365 from my laptop but how do i do if i want to execute the a script 3 times a day when my laptop is off as well.

so i have to got a management server where i can run my script and here is the problem arises.
anybody is having any solution here… i know that i must be missing a very small point here.

$filepath = “C:\Temp”

#set outlook to open
$o = New-Object -comobject outlook.application
$n = $o.GetNamespace(“MAPI”)

#you’ll get a popup in outlook at this point where you pick the folder you want to scan
$Account = $n.Folders | ? { $.Name -eq ‘username@domain.com’ };
$Inbox = $Account.Folders | ? { $
.Name -match ‘Inbox’ };
$f = $Inbox.Folders | ? { $_.Name -match ‘SHO’ };

#date string to search for in attachment name
$email = $f.items.getlast()
$email.Attachments | %{$.saveasfile((join-path $filepath $.filename))}

Because your code uses outlook automation you need to install outlook on the management server as well as having your email profile configured. You might want to try something like this using exchange cmdlets.

https://4sysops.com/archives/auto-archive-attachments-from-an-exchange-mailbox-with-powershell/