Powershell script not working from device

Mario onMicrosoft 41 Reputation points
2021-05-05T13:48:11.96+00:00

I want to use a Powershell script to send me an customize email when different actions (events) occurs concerning my APC UPS device. When the script is run from Powershell is works as it should be. However, when the script is executed from the UPS, it does not work.

The problem has to do with Credentials. Unsafe credential script 1) works perfectly. But getting credential as with script 2) does not work when executed from UPS. The whole setup of Credential in windows, by using Credential Manager, is good because the script successfully send the email when run from PowerShell.

Can someone help me with this problem?

The script runs from an APC UPS connected to a Windows Server 2012 R2. All scripts are located on this server. The Powershell script is run from the UPS by using .bat file.

1) Create credentials. This WORKS

$username = "xxxxxx@yyyyyyyy"
$password = "zzzzzzzzzz"
$myPwd = ConvertTo-SecureString -string $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -argumentlist $username, $myPwd

2) Create credentials. This does NOT work.

$cred=Get-StoredCredential -target XXXXXX

Thanks
Mario

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2021-05-05T14:21:20.907+00:00

    The Powershell script is run from the UPS by using .bat file.

    What exactly does "from the UPS" mean?

    Are you running Powershell.exe on the Windows server and referencing the UPS as a network drive? IE: you are reading the script "from the UPS" into the server's memory where powershell.exe is running?

    Powershell.exe \\UPS\Share\SendMail.ps1
    

    Create credentials. This does NOT work.

    What error do you get? What account is being used to run the script? Is this being called by a Windows service or the task scheduler?

    0 comments No comments

  2. Mario onMicrosoft 41 Reputation points
    2021-05-05T14:46:01.523+00:00

    ups = uninterruptible power supply.

    Via the UPS application PowerChute Business Edition you can execute a script when an event, lets say current outage, occurs. In this case, a .bat file is executed. The .bat file executes the Powershell script

    The .bat script
    PowerShell.exe -ExecutionPolicy Unrestricted -noProfile -nonInteractive -file c:\xxxxx\PS\scripts\upsMailSelfTestPast.ps1

    The system does not give any error.

    I think maybe it has to do with permissions. It works ok from within Powershell but not when it is executed from the UPS.


  3. Mario onMicrosoft 41 Reputation points
    2021-05-07T12:22:52.317+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.