1

This is kind of specific to this Document Management System(DMS) application we use called Worksite / Filesite. Basically, we have 3 offices and 3 servers and if people login from a particular site's OU, no matter the physical presence, they should be presented with that site's connection after running the below command. I'm close to achieve the result, but it's not working for multiple reasons and in different situations.

This code runs on a Windows 10 machine

Start-Process 'C:\Program Files (x86)\Microsoft Office\Office16\OUTLOOK.EXE'
Start-Process 'C:\Program Files (x86)\Internet Explorer\iexplore.exe'
$Office1 = & 'C:\Program Files (x86)\Interwoven\WorkSite\addiman.exe OFFICE1-SRV'
$Office2 = & 'C:\Program Files (x86)\Interwoven\WorkSite\addiman.exe OFFICE2-SRV'
$Office3 = & 'C:\Program Files (x86)\Interwoven\WorkSite\addiman.exe OFFICE3-SRV'
$loggedinuser = Get-ADUser -Identity $env:UserName
if (Select-String -Pattern "Office1-User" -InputObject $loggedinuser) { $Office1 }
if (Select-String -Pattern "Office2-User" -InputObject $loggedinuser) { $Office2 }
if (Select-String -Pattern "Office3-User" -InputObject $loggedinuser) { $Office3 }

What happens is, the add-in for all 3 sites are added for Outlook, which I don't want. If I use the same code on remote terminal services machine, it executes just for $Office1 and stops even if the user is from either $Office2 or $Office3

My questions are :

  1. How can I use -Searchbase to execute the right command for the right office? "If the logged on user is $env:username, searchbase in OU and then execute $thisexe"
  2. My if statements are wrong, but I'm not getting an effective method to use the Switch function EDIT : Just to see how this is working, I ran the script without any conditions and it is simply executing each line sequentially and now, I'm even more confused.
SunnyWorld
  • 21
  • 3

1 Answers1

1

Maybe you can use DistinguishedName:

$loggedinuser = get-aduser -Identity $env:UserName -Properties DistinguishedName 
if ($loggedinuser.DistinguishedName  -like "*Office1-User*") {

$Office1 = & 'C:\Program Files (x86)\Interwoven\WorkSite\addiman.exe OFFICE1-SRV'


}
etc
Vitaly
  • 75
  • 4
  • I had already tried the DistinguishedName approach and it's still the same problem. – SunnyWorld Jun 22 '17 at 05:52
  • Ok...you wrote this: If I use the same code on remote terminal services machine ... do you use Invoke-Method? Did you import the module Active-Directory? Something like: Invoke-Command -computername $host {Install-windowsfeature -name RSAT -module Management Tools}, and on the remote pcs - winrm qc? =) – Vitaly Jun 22 '17 at 08:45
  • Thanks for the pointer, Vitaly! :) However, regardless of RSAT involved, this should run locally as well. What's happening is, it is executing every line of the executable and adding all the 3 servers to the user. – SunnyWorld Jun 23 '17 at 01:48
  • Ok =)...then you can try this: if ($loggedinuser.DistinguishedName -like "*Office1-User*") { & 'C:\Program Files (x86)\Interwoven\WorkSite\addiman.exe OFFICE1-SRV' } elseif ($loggedinuser.DistinguishedName -like "*Office2-User*") { & 'C:\Program Files (x86)\Interwoven\WorkSite\addiman.exe OFFICE2-SRV' } else { & 'C:\Program Files (x86)\Interwoven\WorkSite\addiman.exe OFFICE3-SRV'} – Vitaly Jun 23 '17 at 03:37
  • Thanks for the effort. However, I still have the same problem. I had also tried the elseif approach, but had the flow wrong and the code became a mishmash. Wish there was a proper debugger to step through each line to see what exactly is happening since the current method of debugging has to add lines for breakpoints, etc. – SunnyWorld Jun 23 '17 at 07:10