#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

HowTo: Determine if You are Still Logged In

I have run into some instances where my script will fail in the middle of processing due to my user account timing out. So, in this post I will show how to determine if you are still connected and how to resolve if you are not.

Within my scripts I started adding the following if statement to determine if I am still connected. If not, I log back in.

$DatasourceName = 'BMF-WS2016-PWDI:PW'
$UserName = 'pwadmin'
$PasswordFile = 'C:\temp\encrypted.txt'

if([pwwrapper]::aaApi_IsConnectionLost()){
    Write-Warning -Message "Need to log back into ProjectWise datasource '$DatasourceName'." 
    New-PWLogin -DatasourceName $DatasourceName -UserName $UserName -Password (Get-SecureStringFromEncryptedFile -FileName $PasswordFile) 
} else { 
    Write-Host "Still connected." -ForegroundColor Green 
}

Experiment with it and have fun.

Hopefully, you find this useful. Please let me know if you have any questions or comments.  If you like this post, please click the Like button at the bottom of the page.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.