I know when I start powershell, I can edit the file pointed to by $profile and can put commands in there such as setting aliases on startup.
I am wondering if there is a standard way to start a shell and supply a option to load a different profile file. I tried doing powershell /? but only saw a way to turn off the profile entirely.
I am basically looking for something like powershell -profile-file myprofile.ps1 or a way to get a similar behavior.
Thanks.
Check out ConEmu , it emulates CMD, Bash, and Powershell and you can customize what it does when you start up a new console dialog. Might be one of my favorite dev tools ever.
Related
I am creating a Windows virtual machine and would like to edit the default commands for the command prompt like tree so that when that command is typed it will do what I want it to do. I found 'tree.com' in System32, but when I open it, it is gibberish. How might I be able to read and edit it?
Modifying basic Windows programs is not a good idea (in case you need them there not there anymore), but there's another approaches: doskey, based on UNIX aliases: this allows you to, when you enter tree, to start up another program instead. Help can be found under doskey /? and there are plenty of examples online.
Files with extension .com are compiled executables. There is nothing to edit in there.
On windows 7, I would like to change the system locale from the command line without restarting. Is there any windows command line utility or the one in cygwin that I can use?
Thanks
The following link has information of how to change system locale kind of information from the command-line using the intlcfg.exe command.
An example command for you could be as follows, which would change syslocale to US-english en-US.
intlcfg.exe –syslocale:en-US
NOTE: You may still need to reboot for the settings to take effect, have not tried this so unsure about this part.
Doing a quick Google search turned up a lot of results with different ways to do it.
This TechNet article details how to use the Intlcfg command to change settings such as the Locale
Update language and locale settings
intlcfg.exe [-all:language_name] [-uilang:language_name] [uilangfallback:language_name] [-syslocale:language_name][-userlocale:language_name] [-inputlocale:default_keyboard_description; keyboard_description or locale_name] [-userhive:registry_path] [-syshive:registry_path] [-swhive:registry_path] [-image:path] [-dist:path] [-silent] [-skudefaults:language]
This article on AutoIt.com talks about setting up XML files and creating a script to switch between them.
It's hard to quote, but the gist is:
Create a text file with the settings
Use rundll32 to apply the changes to the registry
I am trying to do my first script. To simply get PowerShell to pull up a script typed up in notepad and saved as a .ps1 file titled "test" (have also tried Script, but know names have nothing to do with it):
Write-Host "Hello, World!"
In PowerShell I am typing
& "C:\Scripts\test.ps1"
As well as
./test.ps1
And am only met with this:
./test.ps1.txt : The term './test.ps1.txt' 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.
At line:1 char:1
+ ./test.ps1.txt
+ ~~~~~~~~~~~~~~
+ CategoryInfo: ObjectNotFound: (./test.ps1.txt:String) [], CommandNotFoundException
Have tried renaming the file within PowerShell with
PS C:\Scripts> Rename-Item test.ps1.txt test.ps1
I have switched between RemoteSigned and Unrestricted, I have tried a code including executionpolicy bypass (I do apologize, I closed my window without writing that one down). As far as I know everything is up to date and I am running Windows 10, Windows PowerShell, and regular Windows Notepad.
First, I'd HIGHLY recommend using the Windows PowerShell ISE for writing scripts. It's free, and provides a pretty decent console/editor experience, given that it's free (there are allegedly better ones out there, but this has always done just fine for me). I use Visual Studio for other stuff, and while it is an EXPONENTIALLY better product (and should be), the PowerShell ISE is pretty feature-rich.
Next, if you're just getting started, you should check out Don Jone's "Learn PowerShell 3.0 in a Month of Lunches" book. It's two versions behind the most current, however, all of the information is still relevant, and once you've finished the book, you'll be able to seek help for anything else pretty easily on your own. It covers all the basics, and is a very good first step to learning the language.
Now, to answer your question: PowerShell scripts commonly have the .ps1 file extension. Other extensions are generally used for modules (.psm1) or other helper content that Windows PowerShell leverages. For most things, you'll stick to .ps1, and when you've reached a point where you start needing the other extensions, I suspect you will have no problems identifying which ones you need.
There are two ways generally call a PowerShell script. The first is from a normal command prompt, and telling PowerShell to execute your script. This is shown below:
powershell.exe -File MyScript.ps1
There are some additional parameters that I'd recommend you use, but usage is dependent on your requirements. Here's what I usually tag on mine:
powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -File MyScript.ps1
This will tell the PowerShell process to ignore any PowerShell profiles you have set up, which is ideal if you have a bunch of stuff in your profile script that does things like read console input (for your current situation, I'm going to assume you don't, but you may in the future). The other is that ExecutionPolicy one: RemoteSigned will tell PowerShell to basically ignore anything that's been downloaded from the interwebs, but allow anything originating inside your network to run free. Probably not the best practice, but this isn't a TERRIBLE policy if you can trust that your script repository is secured. If not, then go for something tighter than this (you can read up on execution policies by typing "Get-Help about_Execution_Policies" in the PowerShell prompt, or by visiting the TechNet page about them -- the content should be similar if not identical).
The second way is from inside of a Windows PowerShell script. It's actually much easier to do. Note that you must set your execution policy to something that will allow scripts to run, but thereafter, you're smooth sailing.
. .\MyScript.ps1
This is called "dot-sourcing" your script. The advantage of doing this from within Windows PowerShell is that if you've got something like a script full of functions, they get added to the current scope (Get-Help about_Scopes), which means they're now available in your current session. A good example would be defining a function called "Test-DomainConnection" in a script you distribute with your main script: You'd dot-source the script that is distributed with the main one (this is done usually when you separate your "standard" PowerShell functions from your main script), and then use the functions in the main script. There are pros and cons to this approach, but it seems to be generally recommended (there may be some community extensions out there that remove the need to manage this manually).
For additional information, you can call Get-Help about_Scripts from inside Windows PowerShell. Because you're using Windows 10, you may need to run Update-Help from an administrative PowerShell window before the help content is available on your local system.
If you have any more questions, feel free to message me :) I've been doing PowerShell for a while and may be able to help out.
Powershell processes in order (top-down) so the function definition needs to be before the function call:
Intro:
I swear have searched around for sometime before posting, but have been unable to find an answer for this..
Question:
Regarding Windows Command Line:
is there some way to set the font/text-size via an actual windows command line in a .bat file?
-Not through going to Properties -> etc. (I understand that quite sufficiently :P)
--Plz no PowerShell.
Additional Notes:
Reason: Thinking of business system based Command Line front-end, PHP back-end.
Thanks in advance.
Without using PowerShell, the only way I can think of would be to modify the registry values under HKCU\Console. See the relevant Technet documentation. However, changes made to the registry values will not update already running console windows. You won't see your changes until you spawn a new console.
As far as how to make changes to the registry, reg /help for more info.
How can I find out the command line options a program was launched with under windows?
try: http://www.bleepingcomputer.com/tutorials/tutorial132.html
in short:
use the Process Explorer utility created by Sysinternals (now owned by Microsoft; which is probably why vista and windows 7 now have a similar functionality already present in task manager)
On vista... You can
go to the task manager
Click View --> Select Columns
Add the command line column.
To do this programatically, run "tasklist -v" to a file and then split up the file.
If you are trying to get the command line of another process programmatically you should probably read Why is there no supported way to get the command line of another process?:
Commenter Francisco Moraes wonders
whether there is a supported way of
getting the command line of another
process. Although there are
certainly unsupported ways of doing
it or ways that work with the
assistance of a debugger, there's
nothing that is supported for
programmatic access to another
process's command line, at least
nothing provided by the kernel. (The
WMI folks have come up with
Win32_Process.CommandLine. I have
no idea how they get that. You'll have
to ask them yourself.)
If you are trying to retrieve the command line of your own process you can use GetCommandLine.
Try running the .exe but with the /? flag.