While running a powershell script using installshield, Enable-ADFSEndpoint can not succeed - powershell

I am trying to invoke a powershell script from installshield, but I am getting errors on the Enable-ADFSEndpoint line.
When I paste this script into powershell itself, it works properly. But when running through install script's LaunchAppAndWait() function, it fails. Here is my installshield code:
Param1=WINDISK +"\\Windows\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe";
Param2="-ExecutionPolicy remotesigned -File \""+ INSTALLDIR +"PSServer\\Support\\adfs_cmdlets.ps1\"";
LaunchAppAndWait(Param1, Param2, LAAW_OPTION_WAIT);
And the script code is as follows:
Add-PSSnapin Microsoft.Adfs.PowerShell
#ENABLE ENDPOINTS
Enable-ADFSEndpoint –TargetAddress "/adfs/services/trust/2005/windows"
Enable-ADFSEndpoint –TargetAddress "/adfs/services/trust/13/windows"
There is of course more script than this, but upon execution through installshield, it isn't getting further.
I am very much so a novice at installshield, so any hints may help and are much appreciated. Again, it is my current thought that the problem lays within installshield, because when my powershell script is invoked through the powershell command prompt, it works properly. Thank you in advance to anyone that may respond.
I also realize it is likely that I have left out important information, and am of course willing to edit it back in upon request.

Related

Powershell Command in Windows Server 2019 Task Scheduler?

I am trying to schedule a Powershell task to start automatically after Windows starts (to restart a process in case of a crash or maintenance). My knowledge of Powershell is very limited, but when I manually want to start the task, I need to go to the folder in Explorer, and open Powershell from there which defaults me to "PS C:\Users{{username}}\Documents\fso\fso> " where I then type in "./watchdog.bat". In trying to setup Task Scheduler, it seems like it's looking for a .ps1 file which I have no knowledge of. Would someone mind helping me with this?
Much thanks in advance :)
Thanks for Mathias R. Jessen's help,
The solution is add a command or file to run, in the "Add arguments" field, either put -Command './watchdog.bat' or -File "C:\path\to\script.ps1", where script.ps1 would be a powershell script calling watchdog.bat

Run a VBScript using Start-Process

I am trying to run a VBScript using some code I already have written for generically running executables. I have used it successfully with EXE & BAT files, but VBS files are giving me headaches.
I found this that does it with CMD and Invoke-Expression, and this that does it with &. But I have found no references to doing it with Start-Process, and when I try something simple like
Start-Process wscript.exe -ArgumentList:"UNC PATH TO HelperTest.vbs"
I get
Execution of the Windows Script Host failed. (Not enough storage is
available to complete ths operation. )
But I can run the super simple VBS file directly no problem. This only happens when the VBS is on a network share. Running it locally works fine. Also, not including a fully qualified path works fine, as in
Start-Process wscript.exe -ArgumentList:"HelperTest.vbs"
So it's not an actual permissions issue on the share. Am I just bumping in to some obscure bug and I am not going to get this to work, or am I doing something wrong and getting confused by a not very helpful error message?

Running Powershell function from .bat file giving blocked error?

I am trying to run a simple powershell command from command prompt. Command is
powershell -command get-help
but I am getting a blocked error message
Any suggestions to fix this will help. I am using something similar in one of my .bat file.
The issue was related to Avecto blocking the powershell -command. If anyone faces similar issue you can ask your sys admins to get added to Powershell Power user group (a group with no restrictions from Avecto).

Script not running first time in console, does afterwards

Hoping you can help as I have run out of ideas and at this point I think it is because I don't understand PowerShell properly.
I read this series; https://foxdeploy.com/2016/05/17/part-v-powershell-guis-responsive-apps-with-progress-bars/ and tried to do the same thing, then I discovered that I could not call my script by opening a normal PowerShell console (Not ISE) and doing .\script.ps1
I also noticed that I could not do the same with the example script located here;
https://github.com/1RedOne/BlogPosts/blob/master/GUI%20Part%20V/PowerShell_GUI_Template.ps1
It does run the SECOND time however and every time after that? For example if you do
.\script.ps1 (doesn't work)
.\script.ps1 (works)
.\script.ps1 (works)
etc...
But if you do
powershell .\script.ps1 (doesn't work)
powershell .\script.ps1 (doesn't work)
However if you close ISE, open it again and run script it works first time?
I don't really know what is causing this.
Does anyone have any ideas?
If you would like to see this just copy from github link as that one has same problem as mine.
The issue is due to line 39-41 in the script on GitHub:
$syncHash.Window=[Windows.Markup.XamlReader]::Load( $reader )
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
As you can see, presentationframework.dll is not being loaded into the appdomain until after XamlReader.Load() is being called.
The entire rest of the script is dependant on the output from this call, so the entire thing fails.
Second time around, the presentationframework assembly has already been loaded, so the call succeeds and the Window is created correctly.

My PowerShell script only works when running from ISE

I can't post all of the script contenet, but the basic idea is that it downloads JSON and converts it to objects using the ConvertFrom-Json cmdlet. Some objects are filtered out, and the rest are written to an XML/XLS document (in the Excel 2003 format). This file is then attached to an email and sent to various people.
The problem I'm having is that it only works when run from the Powershell ISE. Once I try setting up a scheduled task, calling it from cmd, or even calling it from powershell, the attached file is completely empty. It is as if some functions do not run (the one that loops through and creates all rows).
I can continue to run from ISE for the time being, but the idea of this script is to send out an automatic email that will require no intervention. Any ideas as to what could be causing this?
You need to run the script "dot sourced"
which can be done like this
powershell.exe -noexit -file c:\test.ps1
or
pwershell.exe -noexit ". c:\test.ps1"
See this link under the -File section
http://technet.microsoft.com/en-us/library/hh847736.aspx
Based on the answer from the comments to the original post, it seems that the script was (unexpectedly?) working in the ISE because of the bug/quirk/feature that allows scripts run in the ISE to be aware of variables used in the console window and vice-versa.
This can often cause logic problems or unexpected results when a script runs with a variable already defined (and not initialized carefully in the script).
Ways to avoid this problem:
Try to test your code in as clean an environment as possible.
http://powershell.com/cs/blogs/tips/archive/2015/02/12/getting-a-clean-powershell-environment.aspx
To make sure a script runs in a completely clean test environment, you
could of course restart the PowerShell ISE. A more convenient way is
to open another PowerShell tab: in the PowerShell ISE, choose File/New
PowerShell Tab.
Use Set-StrictMode 2 in your script to catch undefined variables, etc.
https://technet.microsoft.com/en-us/library/hh849692.aspx
Set-StrictMode -Version 2.0
Prohibits references to uninitialized variables (including uninitialized variables in strings).
Prohibits references to non-existent properties of an object.
Prohibits function calls that use the syntax for calling methods.
Prohibits a variable without a name (${}).
I have had this problem be for and for me executing the scrip using single-threaded function from powershell worked.
You could also try some other options, go to this link to find more info.
Example
powershell.exe -noexit c:\test.ps1 -sta
Change the missing variable or function to global.
function global:mycall{}
Start your Script with:
[cmdletbinding()]