I have a User Creation AD script which adds users automatically.
For the moment the script is ok, but i expect that the script has to be modified in the future.
For example i want to change this script:
<Departments>
<Department>Finance</Department>
<Department>IT</Department>
<Department>Marketing</Department>
<Department>Sales</Department>
<Department>Executive</Department>
<Department>Human Resources</Department>
<Department>Security</Department>
</Departments>
to
<Departments>
<Department>Finance</Department>
<Department>IT</Department>
<Department>Marketing</Department>
<Department>Sales</Department>
<Department>Executive</Department>
<Department>Human Resources</Department>
<Department>Security</Department>
<Department>Intern</Department>
</Departments>
So i want to add a line in the existing Powershell script, using another Powershell script.
This is just an example. In the future i want add a lot of code.
Is this possible ?
Related
I am writing an initial setup shell script for a Mac.
When I run the script, it asks for the password several times.
Is there any way to make this happen only once during script execution?
If possible, I would like to know how to actively ask for it at the beginning of the script, instead of asking for it when some command requires it.
I wanted to execute a PowerShell script file script.ps1 like this:
powershell ./script.ps1
How will I simulate a 'tab' (auto-complete) feature in script file?
Eg : on the PowerShell prompt, I can do
PS> get [TAB]
for getting suggestions for commands starts with 'get-'
Same thing : how will I write in a script file, means saving the script.ps1 file like:
get-\t
and executing PowerShell ./script.ps1 resulting error instead of getting suggestion for command which starts with "get-"
Any idea to encode the tab event inside a script file to achieve the command auto completion ?
powershell get-command get-*
Is working
It's very unclear what you intend to do but here are the basics on tab-completion:
Save the PS1 file then you can type part of the file name and autocomplete will offer it among the suggestions (though this is done in alphabetical order for all possible suggestions that PowerShell knows.)
If you wish to get parameter tab completion you need to enabled the cmdlet (script) or function as an "advanced" function with a Param block which defines all of the Parameters you cmdlet or function accepts.
The typing: Get-MyCommand - # will result in the possible param and switch names being offered in turn.
Running PSReadline (available from the PowerShell Gallery an enhance the autocomplete feature for all commands and parameters.
If you are seeking to perform some other function you'll need to edit your question to be more specific and how clear examples....
I'm writing a shell script. what it does is it will create a file by the input that is received from the user. Now, i want to add the feature called "view a file" for my current script. Now, it's unreasonal to retype it again since i've already had a script that helps
I know it's crazy when it is possible to it with normal shell command. I'm actually writing a script that help me to create pages that are generated from the touch command. (this pages had attached date, author name, subjects, and title).
The question is how to call a another script or inhere another script?
Couple of ways to do this. My prefered way is by using source
You can -
Call your other script with the source command (alias is .) like this: source /path/to/script.
Make the other script executable, add the #!/bin/bash line at the top, and the path where the file is to the $PATH environment variable. Then you can call it as a normal command.
Use the bash command to execute it: /bin/bash /path/to/script
Bit of an odd one I know.
We have an install script provided to us by the product developers, we implement this product across multiple servers but the default install script they provide is only designed for a single server. As such we have created a shell script with SSHs across all the servers and runs the script, the issue is that the inputs into the default script are hidden but by running it through our script they are no longer hidden.
Here's the gist of it:
sshCmdString=echo "./INSTALLSCRIPT.sh CONFIG-PARAMETERS
ssh -T $sshuser#$HOST $sshCmdString
I'm wondering how I would go about altering the ssh script to hide the input again?
I know read -s hides input within a bash script but I've found that this hides all the outputs of running the script if I put in before/in the command to run the script on the other servers.
Is there another option out there that will hide inputs but display outputs/logging from the script?
I have a program that I work with, that has an onboard lua compiler to allow for custom written actions.
Since the tool itself is very limited, especially if it goes for complex reactions over networks, I want to use Powershell over lua.
Methods like os.execute() or io.popen() use the standard command line from windows and not Powershell.
Is there a way to use Powershell with lua?
I tried to write a command line script with the Powershell editor and run this script with os.execute, but it opens it as a textfile, it would be better to write the commands directly in lua but if there is no other way, executing a Powershell script directly would also be fine. (In Windows itself you can execute the script with right mouse "click/Execute with Powershell")
-- You can generate PowerShell script at run-time
local script = [[
Write-Host "Hello, World!"
]]
-- Now create powershell process and feed your script to its stdin
local pipe = io.popen("powershell -command -", "w")
pipe:write(script)
pipe:close()
Your description of the problem makes it sound like you're using a command such as os.execute("powershellscript.ps1"), and that call invokes cmd.exe with your string as the proposed command line. Normally, Windows will open a .PS1 file for editing; this was a deliberate decision for safety. Instead, try altering the os.execute() command to explicitly call PS: os.execute("powershell.exe -file powershellscript.ps1"). If you need to pass parameters to your script, enclose them in {}. See https://msdn.microsoft.com/en-us/powershell/scripting/core-powershell/console/powershell.exe-command-line-help for more info on invoking PowerShell from the command line.