Using PowerShell as VIM shell - powershell

I'm using the console version of VIM (not gvim) in Windows, and I have a question about using PowerShell as the shell.
I have set my shell to be powershell and I can run commands, but there's one thing I don't know. I have a bunch of things going on in my PowerShell profile, and I was wondering if it's possible to somehow pass something to PowerShell using VIM, so that in the profile I can check and decide what to do.
I know there's an option -NoProfile we can pass to powershell.exe, but my problem is that I don't want to ignore my whole profile, because I need some parts, such as aliases etc.
Thanks,

Related

Limitations of Target field in windows LNKs

I am attempting to use a shortcut to a powershell script, which has to be run elevated, and has some arguments which can be somewhat long. And the location of the script itself may be in a rather buried folder since Architects really like to have massive folder structures. The issue is I am running out of room. And Microsoft using 57 characters for C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe is not helping.
I also can't use the Start in: to provide the path to the script. My guess is I am just hosed by Microsoft's limitations in shortcuts, but I wonder if someone knows some secret sauce for doing something like, maybe forcing the shortcut to just use powershell.exe rather than the full path?
Or is my only option to get as terse as I possible can with my arguments?

Reading user's PS1 from Swift command-line tool

Is it possible to extract the user's PS1 from the environment in a Swift script, so that I can replicate their prompt?
I left a note for myself a few years ago saying that it "disappears from the environment in the context of the script", but I figured it would be useful to ask.
(I'm aware that this question won't necessarily work between shells, but assume that I only care about bash. Furthermore, I know I can't necessarily interpret everything in a user's prompt, but I would like to get it).
Try this in Swift script :
bash -i -c 'echo "$PS1"'

How to Automate scripts with options in Powershell?

I'm not a native English speaker as such pardon some discrepancy in my question. I'm looking at a way to Automate option selection in Programs/Scripts running via PowerShell.
For example:
Start-Process -FilePath "velociraptor.exe" -ArgumentList "config generate -i"
In the above snipper PowerShell will run Velociraptor and initiate the configuration wizard from a Ps1 file. The Wizard has few options. After running it will generate some Yaml files.
As such what would be the way to have PowerShell Script automate the option selection process? I know what the option should be. I looked around but I don't know proper terms to find what I need. Nor am I sure this can be done with PowerShell.
The end goal is to have the Ps1 download Exe, run the config command and continue with choosing the selection based on predefined choices. So far I gotten download and lunching of the velociraptor.exe working. But not sure how to skip the window in screenshot and have PowerShell script do it instead.
I couldn't find a CLI reference for velociraptor at https://www.velocidex.com/, but, generally speaking, your best bet is to find a non-interactive way to provide the information of interest, via dedicated _parameters_ (possibly pointing to an input file).
Absent that, you can use the following technique to provide successive responses to an external program's interactive prompts, assuming that the program reads the responses from stdin (the standard input stream):
$responses = 'windows', 'foo', 'bar' # List all responses here
$responses | velociraptor.exe config generate -i

PowerShell SCript to Execute CMD.exe with Arguments

SO I have surfed this site and the web and I feel as though I am missing something simple.
I find related questions but none that combine a scriptblock and remote calling of a 3rd party app (not a simply windows function or app)
I have the following string that I can copy into a command window and run without issue
"C:\Program Files (x86)\Vizient\Vizient Secure Channel v2.1\VizientSC.exe" UID=me#musc.edu PWD=XXXXXXXXX HCOID=123456 PRODTYPE=PRO-UHCSECURECHANNEL-CDB PACKAGETYPE=OTH FOLDERPATH="\\da\db5\MyFiles\Viz\20180413"
To simplify this, lets just assume I want to run this same String every time BUT with a REMOTE call.
I have written this many different ways but to no avail using
Invoke-Command -ComputerName "edwsql" -ScriptBlock { .........
I simply want to run the designated string using cmd.exe on a remote machine.
The EXE being run in the string is a 3rd party software that I do not want to install all all possible locations. Much simpler to run remote form the box it is already installed and is secure.
Can someone point me in the right direction???? Pls???? I'm new to PowerShell. I am trying to phase out some old PERL as the folks who can support that on the client site are few and far between these days.
You don't need to try so hard. PowerShell can run commands. If the command you want to run contains spaces, enclose in " (as you have done) and invoke it with the & (call or invocation) operator. This is all you need to do:
& "C:\Program Files (x86)\Vizient\Vizient Secure Channel v2.1\VizientSC.exe" UID=me#musc.edu PWD=XXXXXXXXX HCOID=123456 PRODTYPE=PRO-UHCSECURECHANNEL-CDB PACKAGETYPE=OTH FOLDERPATH="\\da\db5\MyFiles\Viz\20180413"
If a parameter on the executable's command line contains any characters that PowerShell interprets in a special way, you will need to quote it.

#!/bin/bash equivalent in windows / specify interpreter for executable script IN the script

I don't really know which part of the described technology stack the behaviour i'm describing is actually a property of - linux, or bash/sh? but it does not really matter i guess.
Anyway, on linux, in a bash or sh shell, i can run a script marked as executable in the file system without specifying the interpreter on the shell or somewhere global, but right in first line of the file,
e.g.
#!/bin/bash
#!/usr/bin/python
or even
#!/usr/bin/gcl -f
for a common lisp implementation.
Is there a general windows, powershell or cmd.exe equivalent to this?Specifically, specifying the interpreter/command line to run the script with in the script itself, rather than on the command line or in the windows registry.
If not, what are similar options? The most similar thing I know about are shortcuts. Is there something more similar?
In Windows the file extension specifies, which programs is used to Interpret a script.
You can also specify the Interpreter like "cmd": CMD /c "c:\temp\script.cmd" or with Powershell: powershell.exe script.ps1
What you can do (in Powershell) is, to specify the Version, which is used to run the script. Use #Requires -version 3.0 in first line and it will throw error on v4 cmdlets etc.