Powershell to logoff and clean profile on another server

Post Reply
jimhung777
Posts: 14
Joined: Mon Aug 07, 2017 5:39 am
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2013

Powershell to logoff and clean profile on another server

Post by jimhung777 »

Hey guys,



Here is the code I execute successfully.

Code: Select all

#TI
sCommand = 'Powershell D:\TEST\file.ps1';

ExecuteCommand(sCommand, 0);

#PS
New-Item c:\TEST\new_file.txt -type file


However, when I tried to use TI to call PowerShell to log off a user or clean user's profile on another server, it did not work!
I'm sure this code can be executed by Powershell.exe merely.

Code: Select all

#servername: XENPW55CV.woo.unatu
#username: 177684
#serverOA: 10.35.36.30

#clean user profile
(Get-WmiObject Win32_UserProfile -ComputerName XENPW55CV.woo.unatu -Filter "localpath='C:\\Users\\177684'").Delete()

#log off user
logoff ((quser /server:10.35.36.30 | Where-Object { $_ -match 177684 }) -split ' +')[2] /server:10.35.36.30


I don't know what's wrong... :o :o :o Is there anyone could help us or give us some direction?

Thanks so much! :)
Last edited by jimhung777 on Fri Apr 27, 2018 2:42 am, edited 1 time in total.
User avatar
PavoGa
MVP
Posts: 616
Joined: Thu Apr 18, 2013 6:59 pm
OLAP Product: TM1
Version: 10.2.2 FP7, PA2.0.9.1
Excel Version: 2013 PAW
Location: Charleston, Tennessee

Re: Powershell to logoff and clean profile on another server

Post by PavoGa »

Might try changing to this:

Code: Select all

sCommand = 'Powershell D:\TEST\file.ps1 2>ErrorFile.txt';
and try to capture any errors the Powershell script is returning. The TI code looks fine.
Ty
Cleveland, TN
Wim Gielis
MVP
Posts: 3103
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Powershell to logoff and clean profile on another server

Post by Wim Gielis »

Can you run any PS script?
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
jimhung777
Posts: 14
Joined: Mon Aug 07, 2017 5:39 am
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2013

Re: Powershell to logoff and clean profile on another server

Post by jimhung777 »

PavoGa wrote: Thu Apr 26, 2018 12:51 pm Might try changing to this:

Code: Select all

sCommand = 'Powershell D:\TEST\file.ps1 2>ErrorFile.txt';
and try to capture any errors the Powershell script is returning. The TI code looks fine.
Hi PavoGa,
Thank you for your idea!
Even though I can't run the code you provide, I still look for an alternative to reach the same result..
Here it is.

Code: Select all

#PS
#log off user
logoff ((quser /server:10.35.36.30 | Where-Object { $_ -match 177684 }) -split ' +')[2] /server:10.35.36.30

set-content D:\TEST\error.log $error

Wim Gielis wrote: Thu Apr 26, 2018 1:15 pm Can you run any PS script?
Hi Wim, definitely.
I can run PowerShell with the code above, but when it comes to using TI to call .ps1, it failed to log off the user.
And I also put PS script in TI, still not work now.
Hopefully, with the help of PavoGa, I got some clue.

Code: Select all

Error [5]:Access is denied.

Could not logoff session ID 1, Error code 5
Last edited by jimhung777 on Fri Apr 27, 2018 2:42 am, edited 1 time in total.
User avatar
macsir
MVP
Posts: 782
Joined: Wed May 30, 2012 6:50 am
OLAP Product: TM1
Version: PAL 2.0.9
Excel Version: Office 365
Contact:

Re: Powershell to logoff and clean profile on another server

Post by macsir »

Check your service account you are using for TM1. It might be the service account don't have proper privilege compared with the one you run the PS script.
In TM1,the answer is always yes though sometimes with a but....
http://tm1sir.blogspot.com.au/
jimhung777
Posts: 14
Joined: Mon Aug 07, 2017 5:39 am
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2013

Re: Powershell to logoff and clean profile on another server

Post by jimhung777 »

macsir wrote: Thu Apr 26, 2018 9:16 pm Check your service account you are using for TM1. It might be the service account don't have proper privilege compared with the one you run the PS script.
Hi macsir,

You are GOAT.

In DEV environment, it works according to your instruction.
But it still has some problem in PROD, I will upgrade from Powershell 2.0 to 4.0 to see if it is about the version. (now DEV 4.0, PROD 2.0)

Thanks!
Post Reply