scripting, batch file and powershell

Salt0912Salt0912 Member Posts: 27 ■□□□□□□□□□
I work for xyz company and we use logmein all the time. I am looking into scripting, bat file and powershell. All the computers are mainly xp-8 and no older then xp. There are mountains of information on google and I have been reading forums for about 3 days now at work. I have found it difficult to find any direction to start as there is still lots of confusion on scripting, batch file and powershell. Below I will list what I don't understand.

Scripting:

any programming language that is easy to pick up and run simple programs or process i.e perl, php, python

Batch file:

Plan text commands that are executed in the cmd.exe.

Powershell:

from my understanding it replaces the cmd.exe because you can ping in powershell like in cmd.exe but also an advanced program that is like the unix shell command(sorry new to all of this I am a noob)

I mainly want to pick this up so I can run a script(programming language) or a batch file/powershell( if i can run these in a script or have them call scripts or vica versa(programming language) to execute command line, move files, move the mouse like a actual user was doing it to automate some things in a program, deactivate UAC.

would i not need batch files or power shell if a scripting language could do the examples i named above or would i need a scripting language and with in the scripting language embed a batch or powershell file? what would i call my scripting language i.e an exe? i know i need an interpreter for my scripting file. why batch or powershell if they do the same thing or do they do different things?

for example do i create a batch file to call on powershell or vica versa?

my other question is can i just omit batch file and use powershell all by itself with a scripting language?

scripiting> batchfile> powershell

scripting > powershell> batch file

powershell> scripting> batchfile

batch file> scripting> powershell

in that order or again can i just omit on or two of them and just run one that does everything. I also downloaded this from i believe logmein or googled it. when I import this, it pulled them up in my logmein tech terminal. it works but here another questions why is this in a xml file? when i imported it gave me a bunch of .bat i could run now. so this leads to my other question...you can write an xml(xml is a scripting langauge?) file that holds .bat files? so script langage> batch file=true but then you must be able to do a scripiting language> powershell> batch=true but why would i want to run a batch file if powershell does the same thing right? I can replace the xml file or extension with whatever programming language i want?

<?xml version="1.0" encoding="utf-8"?>
<scripts>
<script>
<name>Initialize Screen</name>
<file>C:\RescueScripts\Initialize.bat</file>
<resource>C:\RescueScripts\ToggleDesktop.scf</resource>
<platforms>00000001</platforms>
<autoexec>false</autoexec>
</script>
<script>
<name>Clear Internet Temp Files</name>
<file>C:\RescueScripts\ClearInternetFiles.bat</file>
<resource></resource>
<platforms>00000001</platforms>
<autoexec>false</autoexec>
</script>
<script>
<name>Flush DNS Cache</name>
<file>C:\RescueScripts\FlushDNS.bat</file>
<resource></resource>
<platforms>00000001</platforms>
<autoexec>false</autoexec>
</script>
<script>
<name>Renew IP Addresses</name>
<file>C:\RescueScripts\RenewIPAddress.bat</file>
<resource></resource>
<platforms>00000001</platforms>
<autoexec>false</autoexec>
</script>
</scripts>


sorry its been 3 days and I have been digging through information.

thanks for any help.

Comments

  • ptilsenptilsen Member Posts: 2,835 ■■■■■■■■■■
    You are mistakenly defining scripting as being different than writing batch files or powershell scripts. PowerShell scripts, vbscripts, and batch files are the most common scripting methods for Windows tasks. Scripting generally refers to writing code in any interpreted language and running it with an interpreter. PowerShell and the Windows Command Prompt are both interpreters, for example.

    For automating Windows tasks, PowerShell is far and away the most versatile overall, offering ease-of-use, string manipulation comparable to (even superior, arguably) BASH or Python, hierarchy-based scripting, and capabilities similar to compiled programming languages, and lots of Cmdlets already designed to perform common operations. Limitations of PowerShell are that it's not as simple and easy-to-use as batch scripts for basic command-line tasks, and it is a mistake to think it replaces CMD. One can call CMD commands or execute as if using CMD within PowerShell several different ways, but there are some (admittedly frustrating) limitations, and ultimately to just perform really simple tasks, batch scripts can be better.

    Vbscript is an alternative, and was probably the de facto way to script automation tasks in Windows for over a decade. Vbscript is still useful in that there are tons of existing scripts that still work just fine and it does not require any dependencies. PowerShell, by comparison, requires the appropriate version of PowerShell be installed for any Cmdlets or other features you want to use. PowerShell 2.0 is installed in Windows 7 and Server 2008 R2, and almost anything you'd want to do works in 2.0. In fact, almost everything works just fine in 1.0. However, XP and Server 2003 do not have PowerShell installed by default, so in automating tasks across multiple versions of Windows, this can be a big limitation, and in many cases it is not practical to install PowerShell everywhere just to use it instead of Vbscript. Vbscript is also going to arguably be easier for someone who has studied any form of Visual Basic and not studied object-oriented languages like C or Java. Not because PowerShell is object-oriented, but because it uses similar syntax and conventions. If you're not comfortable with any languages, PowerShell is a perfectly fine place to start.

    Batch scripts are ideal for simple tasks. Complex tasks that require more complicated logic structures are easier in PowerShell and other scripting languages, and actually making .NET or WMI calls (which are needed for more "complicated" tasks, for lack of a better word) is not really an option with batch scripting.

    Other scripting languages, such as Python, can be used in Windows, but they come with the disadvantage compared to PowerShell of not being expressly designed for Windows scripting, requiring just as painful (if not more so) dependencies, and in my opinion offer no real advantage.

    You can definitely call batch files from PowerShell and PowerShell script from batch files (and vbscript, too, from both and vice versa). In some rare instances, I have done this because I can get a task completed faster using both, but in general it is IMO worth it to just write the whole thing in PowerShell (or even vbscript).
    Working B.S., Computer Science
    Complete: 55/120 credits SPAN 201, LIT 100, ETHS 200, AP Lang, MATH 120, WRIT 231, ICS 140, MATH 215, ECON 202, ECON 201, ICS 141, MATH 210, LING 111, ICS 240
    In progress: CLEP US GOV,
    Next up: MATH 211, ECON 352, ICS 340
  • blargoeblargoe Member Posts: 4,174 ■■■■■■■■■□
    If you are learning from scratch, just learn powershell. Powershell is going to continue to grow in importance to the lay admin in Microsoft environments, and 99% of anything you'd want to automate in Windows can be either done directly in powershell, or called from powershell.
    IT guy since 12/00

    Recent: 11/2019 - RHCSA (RHEL 7); 2/2019 - Updated VCP to 6.5 (just a few days before VMware discontinued the re-cert policy...)
    Working on: RHCE/Ansible
    Future: Probably continued Red Hat Immersion, Possibly VCAP Design, or maybe a completely different path. Depends on job demands...
  • ptilsenptilsen Member Posts: 2,835 ■■■■■■■■■■
    Just to add, if you want to learn scripting, there are tons of resources for learning specific languages out on the web, including a few threads here. PowerShell in particular is pretty well documented. I've learned most of it from having to figure out how to do specific tasks and then doing them, but a structured approach is probably better. Coming from a computer science background is going to make things the easiest, but I didn't when I first started learning and you certainly don't need to, either.
    Working B.S., Computer Science
    Complete: 55/120 credits SPAN 201, LIT 100, ETHS 200, AP Lang, MATH 120, WRIT 231, ICS 140, MATH 215, ECON 202, ECON 201, ICS 141, MATH 210, LING 111, ICS 240
    In progress: CLEP US GOV,
    Next up: MATH 211, ECON 352, ICS 340
  • cruwlcruwl Member Posts: 341 ■■□□□□□□□□
    Theres a really good book out there learn power shell in a month of lunches. Check it out, it really helped me. and like it was said above powershell can pretty much do anything a batch file or VBS script can do. Just learn powershell.
  • doverdover Member Posts: 184 ■■■■□□□□□□
    Agreed. Dive into Powershell. There are some great instructional videos from TrainSignal and CBT Nuggets if you're a subscriber and the book mentioned above and a couple more would be great resources.

    Learn Powershell 3 in a Month of Lunches

    WIndows PowerShell 3.0 Step by Step (Microsoft Press)

    O'Reilly Windows PowerShell Cookbook 3rd ed.

    Plus get a Win8 machine, Powershell 3.0 and ISE installed and use the get-help, and get-commands.

    I'm with ptilsen, I've learned 90% of what I know of PS from having to get something done, but I just decided to start a more formal learning while I wait for some test results to come back. I picked up the Microsoft Press book and the O'Reilly Cookbook.
  • ptilsenptilsen Member Posts: 2,835 ■■■■■■■■■■
    If you don't want Windows 8, PS 3.0 will install on 7, FWIW. You should get 3.0 for the updates to the ISE alone.
    Working B.S., Computer Science
    Complete: 55/120 credits SPAN 201, LIT 100, ETHS 200, AP Lang, MATH 120, WRIT 231, ICS 140, MATH 215, ECON 202, ECON 201, ICS 141, MATH 210, LING 111, ICS 240
    In progress: CLEP US GOV,
    Next up: MATH 211, ECON 352, ICS 340
  • Salt0912Salt0912 Member Posts: 27 ■□□□□□□□□□
    Thanks everyone, i have the o'reilly cook book for powershell and I have v1.0 but I'm running win7 sp1 x86 on my machine at work. I have the ISE and modules, I have no idea what these are for but how do I install 3.0? I read that you need win7 sp1 to install it on your computer. Which I have but wouldn't let me when I tried downloading it.

    what about grabbing the mouse and making it auto click on something on a remote user computer? this is done through a scripting language like a C language for example and then anything dealing with systems, networks can be done with powershell/batchfile correct?
  • the_hutchthe_hutch Banned Posts: 827
    Powershell scripting is VERY easy to pick up if working in the ISE, and EXTREMELY powerful. A few things that might help:

    1. Upgrade to 3.0 (this is a must IMO).
    2. Use 'Get-Help'. If you use 'Get-Help' followed by any PS command, you will be provided a lot of very helpful information to include usage, syntax and examples. For example:
    Get-Help Get-ADUser
    3. You can also use the online switch to be automatically directed to additional information about the command on the web. Example:
    Get-Help Get-ADUser -online
    4. Use already existing scripts as templates when you are trying to accomplish something. And then just analyze the scripts line-by-line to understand what they are doing. Modify as needed to apply to your specific task or environment. Modifying scripts will get your feet wet, and you'll be surprised how quick you'll be ready to start writing your own scripts.
    5. Don't be afraid to ask for help. There is a huge support community online for PowerShell scripting. Check out powershell.org.
  • Salt0912Salt0912 Member Posts: 27 ■□□□□□□□□□
    the_hutch wrote: »
    Powershell scripting is VERY easy to pick up if working in the ISE, and EXTREMELY powerful. A few things that might help:

    1. Upgrade to 3.0 (this is a must IMO).
    2. Use 'Get-Help'. If you use 'Get-Help' followed by any PS command, you will be provided a lot of very helpful information to include usage, syntax and examples. For example:
    Get-Help Get-ADUser
    3. You can also use the online switch to be automatically directed to additional information about the command on the web. Example:
    Get-Help Get-ADUser -online
    4. Use already existing scripts as templates when you are trying to accomplish something. And then just analyze the scripts line-by-line to understand what they are doing. Modify as needed to apply to your specific task or environment. Modifying scripts will get your feet wet, and you'll be surprised how quick you'll be ready to start writing your own scripts.
    5. Don't be afraid to ask for help. There is a huge support community online for PowerShell scripting. Check out powershell.org.


    Thanks a lot but what about moving a mouse cursor over an object in a application in windows and clicking it in a scripting programming file? I assume I just google powershell templates for examples? I tried to download version 3.0 but was unable to do so. I am about to add powershell.org to favorites right now.
  • the_hutchthe_hutch Banned Posts: 827
    Salt0912 wrote: »
    what about moving a mouse cursor over an object in a application in windows and clicking it in a scripting programming file?

    Not sure I'm following on that one. Not saying you aren't on to something, but sounds like something I'm not familiar with.
    Salt0912 wrote: »
    I assume I just google powershell templates for examples?
    Usually I focus on something more specific. I'll have an idea of what I'm trying to accomplish and then google that. For example:
    Powershell query registry key
    Salt0912 wrote: »
    I tried to download version 3.0 but was unable to do so.
    You need to install Windows Management Framework 3.0 (http://www.microsoft.com/en-us/download/details.aspx?id=34595)
  • ptilsenptilsen Member Posts: 2,835 ■■■■■■■■■■
    PowerShell is able to make .NET calls, and cursor movements can be controlled with .NET calls. You need to learn the basics of .NET programming and PowerShell to get anywhere on your own. To be honest I don't have a good resource to point you to this second, but there's bound to be one. Here is the MSDN article on moving cursor position with .NET:
    Cursor.Position Property (System.Windows.Forms)

    The PowerShell code to do so would be very similar to the C# code. Other cursor methods and properties are found here:
    Cursor Class (System.Windows.Forms)
    Working B.S., Computer Science
    Complete: 55/120 credits SPAN 201, LIT 100, ETHS 200, AP Lang, MATH 120, WRIT 231, ICS 140, MATH 215, ECON 202, ECON 201, ICS 141, MATH 210, LING 111, ICS 240
    In progress: CLEP US GOV,
    Next up: MATH 211, ECON 352, ICS 340
  • the_hutchthe_hutch Banned Posts: 827
  • the_hutchthe_hutch Banned Posts: 827
    ptilsen wrote: »
    PowerShell is able to make .NET calls, and cursor movements can be controlled with .NET calls. You need to learn the basics of .NET programming and PowerShell to get anywhere on your own.

    I disagree. I don't know much about .NET but I get a LOT accomplished with Powershell. Mostly using it to multi-thread network security tasks to include vulnerability remediation (remote installation of patches, removal or modification of registry keys, etc...), Active Directory object querying and manipulation, discovery scanning, system analysis for security events, rogue system identification, etc...

    That being said...I am definitely interested in learning more about the .NET capabilities and will definitely check these out. Thanks for the links ptilsen icon_thumright.gif
  • ptilsenptilsen Member Posts: 2,835 ■■■■■■■■■■
    the_hutch wrote: »
    I disagree. I don't know much about .NET but I get a LOT accomplished with Powershell. Mostly using it to multi-thread network security tasks to include vulnerability remediation (remote installation of patches, removal or modification of registry keys, etc...), Active Directory object querying and manipulation, discovery scanning, system analysis for security events, rogue system identification, etc...
    Did you see the context of my response? He is asking to move the mouse. There is no other way to do this but .NET, a low-level API call, or machine code, and .NET is the only way to do it in PowerShell. I am not suggesting .NET is required to accomplish anything or a lot with PowerShell, just this.
    Working B.S., Computer Science
    Complete: 55/120 credits SPAN 201, LIT 100, ETHS 200, AP Lang, MATH 120, WRIT 231, ICS 140, MATH 215, ECON 202, ECON 201, ICS 141, MATH 210, LING 111, ICS 240
    In progress: CLEP US GOV,
    Next up: MATH 211, ECON 352, ICS 340
  • boredgameladboredgamelad Member Posts: 365 ■■■■□□□□□□
    If you're really just looking for a simple way to automate mouse movement and clicks, I recommend AutoHotkey. Even though it's called AutoHotkey, it is more of a macro scripting tool.

    I used this at my previous job for a lot of ticketing issues where I would have to click a bunch of buttons in the exact same order every time I opened a ticket. Saved myself about 10 mouse clicks per ticket, which adds up over time. It's got a bit of a learning curve as you learn to write the scripts but the documentation is very thorough. You can even export scripts as standalone EXE files which you can call from the command line, even on computers that don't have AutoHotkey installed.

    Of course if you want to learn how to actually script something like this yourself, more power to you! I pick up a little bit of programming/scripting knowledge every day and am getting a kick out of it.
  • ptilsenptilsen Member Posts: 2,835 ■■■■■■■■■■
    I should add I have also heard of AutoHotKey and similar solutions, and found overall that they were probably a better way to try to program mouse movements than actually writing code from scratch.
    Working B.S., Computer Science
    Complete: 55/120 credits SPAN 201, LIT 100, ETHS 200, AP Lang, MATH 120, WRIT 231, ICS 140, MATH 215, ECON 202, ECON 201, ICS 141, MATH 210, LING 111, ICS 240
    In progress: CLEP US GOV,
    Next up: MATH 211, ECON 352, ICS 340
  • QordQord Member Posts: 632 ■■■■□□□□□□
    Salt0912 wrote: »
    I assume I just google powershell templates for examples? I tried to download version 3.0 but was unable to do so. I am about to add powershell.org to favorites right now.

    No, not templates. Just scripts. I'd say to start here:
    Weekend Scripter: Install PowerShell 3.0 on Windows 7 - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs

    Once you've got that done, think of something you could (or want to) automate. Personally, I'd say to start simple. Remember: Anything you can do in CMD should work just fine in Powershell. Start simple, check your IP using ipconfig. Nothing fancy, right? Then try to do the same thing, but have it output the result of ipconfig to a text file on your desktop using native Powershell commands. Maybe try to have it save the file to a different computer on your network next. Have it run ipconfig on a remote computer and save the results on your local desktop as a csv file. Maybe even force it to only give you the IP and Gateway, filtering out the rest of the stuff.

    You might think these sound like simple, trivial tasks....and they might be. But you've got to start somewhere, and simple's a good way to go. If you don't like those ideas, think of something (small) you want to accomplish, and figure out how to do it. I started playing with PS because I was tasked with IPAM for BYOD at all of our locations, so I had about 20 DHCP pools on 14 servers I had to keep tabs on. I got tired of manually checking leases and figuring percent in use, so I figured out how to script it. Just find something you want to make happen, and make it happen. My 2 cents.

    EDIT: For a gui or simple mouse movements, I say AutoIt. If I need to make a gui for anything, it's done with AutoIT.
  • netsysllcnetsysllc Member Posts: 479 ■■■■□□□□□□
    If you are wanting to emulate mouse movements and clicks through scripting you will want AutoIt - AutoItScript
  • Salt0912Salt0912 Member Posts: 27 ■□□□□□□□□□
    Really thanks everyone for there input on the subject. I booked marked a lot of the links and downloaded the o'reily books. I am just going to try and create the mouse movement from scratch as its better for me to learn it this way instead of autoit. If it becomes time consuming then i'll just go down that route with autoit. I need the mouse to click on a tab or section to move through the application on a windows computer.

    Can I write like in C++ or C# and have them call powershell?

    I know android just got something like the command line but what about ios and windows phone?

    when i try to install .net3 it says my computer is not available for the update? I have win 7 sp1 and i am running a 32 bit system. Currently running PS version 2.0 and .net 2
Sign In or Register to comment.