Is it possible to run powershell using SSH from remote-host? - powershell-remoting

Is it possible to run powershell script using "ssh" or any protocol from remote-host (Linux)?
Followed these steps:
Have 'freeSHd' installed which runs ssh/ telnet services.
Able to connect Windows 2008R2 host thru SSH.
Able to run (powershell.exe) and entered into powershell environment.
Set the Execution Policy to 'Restricted' (Set-ExecutionPolicy Unrestricted) before running the powershell script.
Ran the script & "C:\Scripts\setUp.ps1"
Received following error:
The term 'Add-ADFSRelyingPartyTrust' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. t C:\Scripts\setUp.ps1:1 char:26
+ Add-ADFSRelyingPartyTrust <<<< -Name 'RP' -MetadataURL 'https://rphost:443/fed/sp/metadata'; + CategoryInfo : ObjectNotFound: (Add-ADFSRelyingPartyTrust:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Also tried running like this and resulted in same error:
C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy ByPass -command ". 'C:\Scripts\setUp.ps1'"
Please let me know how to solve this issue.
Thanks
GKS

Related

cant compile raylib for web

I have been trying to compile my raylib game to web (following this tutorial https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5) ) and i got stuck on this part:
Before compiling raylib, make sure all paths to emscripten (EMSDK_PATH) and tools are correctly configured on
C:/raylib/raylib/src/Makefile, you must verify these lines.
To compile raylib source code, just execute Notepad++ script: raylib_makefile and SET PLATFORM=PLATFORM_WEB.
To do this, start up Notepad++ for raylib, open the raylib.h file, press F6, choose raylib_makefile, verify that
in the script SET PLATFORM=PLATFORM_WEB, then click OK to run the script. That script just calls the following make
line (in case you're are working on a custom environment):
make PLATFORM=PLATFORM_WEB -B
When i open C:\raylib\raylib\src\raylib.h in notepad++ and press F6 nothing happens and when i try to call make PLATFORM=PLATFORM_WEB -B in the powershell it says
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ make PLATFORM=PLATFORM_WEB -B
+ ~~~~
+ CategoryInfo : ObjectNotFound: (make:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
please help

Github Action Run - Security import is showing "One or more parameters passed to a function were not valid"error

I built the input file (decoded base64 file into p12 file) as CERTIFICATE_PATH, P12_PASSWORD is password in secret, KEYCHAIN_PATH is defined. when I run the command on CLI, I get "1 item imported" success message. but when I run from *.yml file on GitHub action, I get "security: SecKeychainItemImport: One or more parameters passed to a function were not valid." error. any suggestions?
security import $CERTIFICATE_PATH -P $P12_PASSWORD -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
CERTIFICATE_PATH - file that contains cert.p12 data,
KEYCHAIN_PATH is TEMP/app-signing.keychain-db
Another reason in Github actions could be that you are using the wrong environment.
Take a look at this ---> Difference between Github's "Environment" and "Repository" secrets?.
Set the right environment:
environment: production
found the issue.. was passing wrong cert file.. once added correct file in the security build , was able to get it working

Cannot acces instance using compute ssh : "ERROR: [....putty.exe] exited with return code [1]

Here's my problem :
I would like to connect to a gcp instance. When I run the Google Cloud SDK shell as an administrator with the command :
gcloud compute ssh my_instance --zone=europe-west1-b -- -L=8081:locahost:8081
..I get this error : ERROR (gcloud.compute.ssh) [..../putty.exe] exited with return code [1]
My instance is running with the metadata enable-oslogin as TRUE, as the project.
Do you have an idea of what is the problem ?
When using -- in the command, you are passing SSH flags after the dashes and not gcloud command flags. To explain, gcloud compute ssh is a thin wrapper around the ssh(1) command that takes care of authentication and the translation of the instance name into an IP address.
In this case, -- is equivalent to --ssh-flag as per this SDK reference. It seems that putty is outputting an error that is not passed into the command line (SDK shell). The actual error should be visible in the dialog window before putty exits.
I have tried the command myself on Windows and the exact error was unknown option "L=8081:localhost:8081". The SSH flag is not accepted as you have an = sign there (typo).
According to linuxcommand.org manual, the flag should be in this format:
-L [bind_address:]port:host:hostport
Hence, you should run the command like this:
gcloud compute ssh my_instance --zone=europe-west1-b -- -L 8081:locahost:8081
Note also that you may have to create a firewall rule to allow Ingress to the instance on port 8081.

Error when trying to read the .ini file from .nsi script

I have to write a NSIS script for deployment the report on the server.It works fine when I am using localhost.
Now I want to send this package to my client but the problem is that I don't know the SERVER IP of the client for this purpose I have write the .ini file. The content of the ini file is
DeployReport.ini
[SETTINGS]
ServerIp=localhost
UserName=
PassWord=
DeployReport.nsi
# Script generated by DeepSofts - NSIS Script Generator
# Beginning Basic Section Script ...
Name 'DeployReport'
Icon 'modern-install-full.ico'
OutFile 'DeployReport.exe'
SilentInstall Normal
CRCCheck On
Section GetIP 0
ReadINIStr $ip "DeployReport.ini" "SETTINGS" "ServerIp"
MessageBox MB_OK "$ip"
SectionEnd
Section Command 1
Exec '"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\rs.exe" -i PublishSampleReports.rss -s http://localhost/reportserver"'
SectionEnd
ComponentText 'A few details about the application that you have created'
AutoCloseWindow True
SetCompress Auto
SetDateSave On
SetDataBlockOptimize On
The problem is that the DeployReport.nsi script works fine untill I dont use the Section GetIP 0 and I am not able to find the error in the script.
You should use the full path to the .ini ("$exedir\DeployReport.ini")

Powershell script works in Powershell but fails in Task Scheduler

I have a PowerShell script that sends an email via SMTP. The script runs fine inside Powershell ISE, but fails in Task Scheduler. I am on Windows Server 2012. I have other Powershell scripts that I run on this server using the exact same setup, but those scripts do not send an email. The return code I see in Task Scheduler is (0xFFFD0000) and I cannot find any information on this. I have the task set to run with highest privileges and I have checked that the executionpolicy is RemoteSigned. Anybody run into this before?
Here is the command in the task:
powershell -f "c:\scripts\EmailTest.ps1"
Here is the script:
$EmailFrom = "user#domain.com"
$EmailTo = "someone#somewhere.com"
$Subject = "Email Subject"
$Body = #"
Person,
Some message here
Thanks,
User
"#
$SMTPServer = "smtp.domain.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("user#domain.com", "password");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Update:
I was able to resolve the issue. Apparently I had an additional line in the script that was commented out. I'm not sure why this would cause an error but once I removed that commented out line it ran fine in Task Scheduler. the comment looked like this and was just below the other $EmailTo declaration in the above script:
#$EmailTo = "someone#somewhere.com"
I found another possible issue while looking at a similar problem. I was unable to execute a PowerShell script as a Task Scheduler action, even though the script ran correctly when logged into Windows as the target user and running within PowerShell.
Task Scheduler would consistently display the 0xFFFD0000 error when I nominated the script in the task's action arguments using what I believed to be normal PowerShell quoting rules:
-ExecutionPolicy Bypass -File 'D:\full path\to\script.ps1'
PowerShell acquiesced and Task Scheduler fired off the task immediately and without issue when I changed the quotes I used from single to double:
-ExecutionPolicy Bypass -File "D:\full path\to\script.ps1"
Dropping to a command prompt and executing the full command immediately revealed the problem:
D:\>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File 'D:\full path\to\script.ps1'
Processing -File ''D:\full path\to' failed: The given path's format is not supported. Specify a valid path for the -File parameter.
Notice the strange use of two single quotes before the path and one single quote after.
The moral of the story: When feeding the full path of a script to PowerShell as a command line parameter, use double quotes!
I was receiving the same error and ultimately I had a different issue - the optional start in directory setting wasn't applied.
Essentially, I was running a .bat file - c:\tasks\process.bat
This .bat file referenced multiple ps1 scripts that were in the tasks directory and the references were just by file name (not the full directory). On the action tab in task scheduler, there is a Start in (optional) field that I had not populated. Setting it to c:\tasks allowed the references to function properly.
First of all you have to check "ExecutionPolicy" configured on your machine. to do so, check default values by following this link https://technet.microsoft.com/en-us/library/hh847748.aspx
I fixed my probleme by using this command:
On "Add arguments" option I put:
"-Executionpolicy Bypass -command "& 'T:\deleteOldMessages.ps1' "
and