Jump to content
DigitalDentist

Powershell Scripts Not working

Recommended Posts

Can someone tell me why this script works locally from the server but not from Pulseway. I've tested running the script both with impersonation enabled and disabled. Both tests were done on server 2012 R2. One with default Powershell version and one with 5.1. This script runs perfectly fine from the server itself just not through pulseway. I have several scripts that give the same type of error. I'd appreciate any help so I can figure this out. It seems like Pulseway doesn't like certain characters? 

ForEach ($COMPUTER in (Get-ADComputer -Filter '*' | Select -ExpandProperty Name)) 

 {
  $key = “SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install” 
        $keytype = [Microsoft.Win32.RegistryHive]::LocalMachine 
        $RemoteBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$Server) 
        $regKey = $RemoteBase.OpenSubKey($key) 
        $KeyValue = $regkey.GetValue(”LastSuccessTime”) 
     
        $System = (Get-Date -Format "yyyy-MM-dd hh:mm:ss")  
             
        if    ($KeyValue -lt $System) 
        { 
            Write-Host " " 
            Write-Host $computer "Last time updates were installed was: " $KeyValue 
        } 
    }

Screenshot_20170721-132009.png

Screenshot_20170721-132017.png

This is what it looks like when ran from the server without involving pulseway

20170721_132729.jpg

Share this post


Link to post
Share on other sites

Hi,

At first you will need to get the PS session and then you will be able to run this script via Pulseway:

Get-PSSession -ComputerName "computer name"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Martin Stevnhoved
      Hi.
       
      I am making an Automation Script that updates a custom plugin-file, that might is always be in use, to a newer version.
      If the plugin doesn't already exist everything works fine.
      But if it already exist it cannot be overwritten, because the Pulseway Service (and managers, if any are running) is using the file.
      My solution is to stop the service, overwrite the file and start the service.
      It works very well when executing manually in ISE, but not when executed as an Automation Script from Pulseway.
      It looks like the entire script is terminated when the service stops, and the execution doesn't return anything in execution history - not even an error.
       
      Could anyone help me with the best practice for updating a plugin dll-file from an Automation Script.
       
      Best Regards,
      Martin Stevnhoved
    • By AndrewT
      I'm trying to edit/create a new log alert.
      1. When adding a new Event ID to an existing alert (comma delimited) and press Save, I get the following error in the console, and so the change cannot be saved.
      TypeError: n.split is not a function
          at e (Configuration?v=9UgYGKSsgKBU9Z8hKYeBn1ZGSfClMiErmwarSJ-k9Nk1:1)
          at h (Configuration?v=9UgYGKSsgKBU9Z8hKYeBn1ZGSfClMiErmwarSJ-k9Nk1:1)
          at b.i.save (Configuration?v=9UgYGKSsgKBU9Z8hKYeBn1ZGSfClMiErmwarSJ-k9Nk1:1)
          at fn (eval at compile (Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:218), <anonymous>:4:341)
          at f (Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:258)
          at b.$eval (Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:139)
          at b.$apply (Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:139)
          at HTMLFormElement.<anonymous> (Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:258)
          at HTMLFormElement.dispatch (jquery-2.1.4.min.js:3)
          at HTMLFormElement.r.handle (jquery-2.1.4.min.js:3)
       
      2. I create a new alert, then press Save at the bottom of the page, I'm immediately logged out and the new alert is not saved. The console shows the following error.
      POST https://xxxxxxxxx.pulseway.com/app/configuration/setgrouppolicyxml 501 (Not Implemented)
      (anonymous) @ Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:99
      q @ Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:95
      g @ Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:92
      (anonymous) @ Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:124
      $eval @ Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:139
      $digest @ Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:136
      $apply @ Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:139
      (anonymous) @ Angular?v=p7XkODdFRlnxHp13elrK938iS1GuRjGvjEN1SZnD5Xk1:258
      dispatch @ jquery-2.1.4.min.js:3
      r.handle @ jquery-2.1.4.min.js:3
      Webapp?v=q_Itvkrsn7cHaFoxY6naxi7fk3CIzlYQcu8SG1P96v01:1 Response Error 501 {data: "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Stric…> ↵ </fieldset></div> ↵</div> ↵</body> ↵</html>
      logging out
       
       
       
    • By ArrowNM
      Will be able to see in the next release an option to update time on a bulk action for multiple tickets?

    • By Keith
      I am trying to create a PowerShell script that will run DBCC checks on a SQL server and then report status back to Pulseway.  I have a working script that I can run from the command line but the script will not run correctly when sent as a Pulseway script.  Here are the details.
      The script fails because it is unable to authenticate to the SQL server.  The SQL Server is running on the same machine as I am running the script on.  Thus wil are not dealing with cross machine accounts.  I have put debug code into the script and the account reported back by PowerShell is MACHINENAME$.  The machine is in a domain and thus the script appears to be reporting back the machine account in the domain.  This implies to me that when Pulseway runs a script it is using the NT AUTHORITY\SYSTEM account and that the MACHINENAME$ account would then be used for any network access.  Is this correct?
      I have given SQL Server rights to NT AUTHORITY\SYSTEM as well as DOMAIN\MACHINENAME$ and NT AUTHORITY\LOCAL SERVICE.  Non of these rights appear to allow me to connect to SQL.  Has anyone ever written Powershell code for Pulseway and been able to connect to SQL Server?
      Any ideas, thoughts or details on the user contexts used by Pulseway would be helpful.
    • By MaxITGarrett
      Our business operates with hundreds of products in our inventory and going through all of them and manually entering them into PSA was not exactly an option, and without an import function, I had to develop an import tool that uses the PSA API. I developed it originally with hard coded parameters, in a single class, but went back today and improved it for distribution to everyone here.
      To view the source code, check out the repository at https://bitbucket.org/garrettbromley/pulseway-product-import/
      To download the executable files, download PulsewayProductImport-v2.zip at https://bitbucket.org/garrettbromley/pulseway-product-import/downloads/
       
      Instructions:
      Download the Excel template and add your inventory into that sheet. I personally had a Microsoft Surface that I walked around with and inventoried everything. To change the categories/sub categories, open the "Back End" tab on the sheet and edit those tables to your liking The only column that isn't required is the UPC Code. Run the Import Tool Input your PSA credentials Type in the full directory to the excel sheet (make sure its closed before running it) Confirm the number of detected items Watch the tool work Make a stock adjustment with the levels of stock for each item (this unfortunately cannot be automated) It will notify you how many items have successfully been imported and which ones failed (if any) and why.  
      Please let me know if you have any questions! I will post changelogs if any updates are made.
×