Interoperability of PowerShell - windows

I am distributing an installer and it will open and run a PowerShell script. The installer will be used by people who have Windows XP and up.
Am I guaranteed that this script will run/execute on all these versions of Windows? I'm looking for the similar Cross-Windows-Platform interoperability that Batch files provide.
I've heard of the error: "File cannot be loaded because the execution of scripts is disabled on this system" what can I do in this scenario? If a user has disabled scripts does that mean I will need to use a different language(maybe just Batch)?

The error you're quoting is due to the default execution policy of PowerShell when it's installed. The message indicates that PowerShell is installed,but by default it's very restricted about what scripts may run for security purposes.
See this article for more on the subject.
If you're going to use PowerShell in your installer, make it part of the system requirements for your software. I can't find anything that definitively says you can redistribute PowerShell with your application, but it's worth asking Microsoft about it.
PowerShell isn't "guaranteed" to be on any desktop OS older than Win7, but it is distributed via Microsoft Update and there's no compelling reason for users to not have it installed.

If you manage this environment, then make sure that powershell is installed on the XP workstations before deploying the script. There is also the option of configuring group policy for powershell to enable script execution and what type of scripts to allow, but that's outside the scope of this question.
If you don't go the group policy route, and instead want to just run the script directly, then in your installer, call powershell.exe directly and pass in the following parameters:
powershell.exe -executionpolicy bypass -file \\path\to\script
The script path doesn't have to be a unc path if it's local, that was just an example.

No, PowerShell scripts are not guaranteed to run on Windows XP or Windows Server 2003. Although PowerShell is available for these platforms, it's not installed by default.

No, PowerShell scripts may not work, because the PowerShell isn't pre-installed on Win XP/2003.
It is included in the Management Framework for XP/2003.
For me, I suggest to use the .bat instead.

Related

I can't execute some commands in PowerShell

I'm using Windows 8.1, and I can't use some commands in PowerShell.
For example, commands about AD User (Get-ADUser, New-ADUser), or commands about certain Windows features (Get-WindoswFeature, Enable-WindoswFeature).
A lot of people use above commands, but I can't use them.
I don't know why it is. Please help me
The PowerShell modules for those commands are not installed on client operating systems by default. You have to install the Remote Server Administration Tools for your specific client OS to get the modules.

PowerShell Cannot dot-source this command because it was defined in a different language mode

I've created a Windows application package using Visual Studio and when I run Add-AppDevPackage.ps1 script I get this error on some computers.
Cannot dot-source this command because it was defined in a different language mode. To invoke this command without importing its contents omit the '.' operator`
I feel like this has something to do with the Group Policy since the particular device is an Enterprise issued Microsoft Surface 2. I cannot make any changes to this group policy.
How do I proceed to install this application on this device?
Anything in particular I should try?
Have you tried unrestricted execution policy?
Set-ExecutionPolicy Unrestricted
Restrict it after you're done. It is a loophole if your admins didn't plug it.

scripting languages native to windows for remote users support

I work for a application dev company but I am in the support side of it. I am looking to run scripts on to remote-host (logmein Rescue Technician Pro). Our clients all run windows machines and the oldest OS version we support is XP SP3 and the latest win8. I need a scripting language that is native to windows and doesn't require any download this or unzip that. These scripts are Powershell scripts but as we all know the executionpolicy needs to be set to unrestricted. I need a scripting language that automates mouse clicks and keystrokes like hitting enter on the keyboard or typing words into cmd/Powershell, then hitting enter for example. I am trying to run a script in another language to disable the excutionpolicy in Powershell and then start the powershell scripts from this point. I hope I have explained myself.
UPDATE:
I am bad at what I am trying to explain I guess. I need to run a script to disable ExecutionPolicy on remote users through LOGMEIN RESCUE TECHNICIAN. Logmein has a tab called "SCRIPTS" that automatically startup when you connect to the remote session. The problem is that PowerShell by default is set to executionpolicy restricted. That will not allow my scripts to run and I have to run them manually from my machine, I believe their is a way to just run the scripts and have them out put the results to me without having to pull up the remote users GUI, all the computers are their own independent machines and not on a domain. I need to run the scripts as unrestricted on the remote machine on initiation of the remote session. Thats why I having going around in circles trying to figure this out. I was able to disable powershell from the cmd but i need to hit enter, i need to script the enter key stroke but again i keep running into blocks just run my scripts. I'm annoyed by this now at this point.
You can run a powershell script like so:
powershell -executionpolicy unrestricted -file "C:\Myscript.ps1"
This will not change the global executionpolicy for the whole machine, but just to run that script.
Two options:
1.Stick with PowerShell. When you launch PowerShell, instead of launching from the shortcut, run the following command (either from a cmd prompt, or run command):
powershell.exe -ExecutionPolicy ByPass
This will run PowerShell with the execution mode set to ByPass.
2.Use the old way of scripting that works on all versions of Windows, VB scripts. (although, after using PowerShell, VB scripts are hard to go back to)
I'd honestly go with JScript (or VBScript, but JScript is a much nicer language IMHO), since you don't want to have to install anything on the remote machines. XP doesn't include PowerShell, so you'd have to install it at some point.
WSH (Windows Scripting Host) languages like VBScript and JScript, and PowerShell can all simulate mouse clicks and keystrokes, but if you want one script that will run on all of those platforms out-of-the-box, you'll need to stick with WSH languages.
If you have any control over what gets installed on the remote systems, though, go with PowerShell, or - at very least - make sure that the Windows Scripting Host components are up to date with the latest release available for the platform. I'm not sure whether that would come as part of the typical Windows Updates or not.
Just my $0.02.

How to admin a remote Windows Server with a command line interface?

When I was a Linux admin I could do anything from the SSH command line. Now, as a Windows admin, I have to deal with the Windows Remote Desktop graphical interface, which I found to be inefective (slow) and hard to automate tasks in it.
a) Can I connect to a Windows Server through SSH or any encrypted connection with command line interface?
b) If yes can I do ANY administrative task?
Examples:
create a new virtual folder in IIS
setup firewall ports
restart services
change user policies
start desktop applications
I know about the existence of Windows PowerShell 2.0 Remoting, but I don't know if it fullfills all conditions above
My conclusion so far: from Windows PowerShell can do MOST but not ALL administrative tasks. And I still don't know if Windows PowerShell 2.0 Remoting uses an encrypted connection.
PowerShell is what you're looking for. It is primarily targetted at system administration (although it's fanastic as a programmer's shell, too).
PowerShell v2 remoting is based on Windows Remote Management. See http://msdn.microsoft.com/en-us/library/aa384426(VS.85).aspx. It includes facilities for ecryption and authentication, as you'd expect.
PowerShell includes cmdlets that let you do a lot of everyday tasks. Microsoft server applications (IIS, Exchange, etc.) either have or are building PowerShell cmdlets to administer them. PowerShell's WMI support is excellent, giving you a lot of machine administration power. PowerShell can talk to .NET directly, which lets you go further than built-in facilities when needed. And writing C# for PowerShell to call works out cleanly, too.
You asked for a command line interface, but don't think that you're restricted to the ancient and crufty Windows Console subsystem. PowerShell v2 includes a new GUI interactive shell / script editor, with colorization and debugging. It's sweet.
You can also try http://sshwindows.sourceforge.net/
I don't have personal experience with it but it looks promising.
Did you consider Google? (looks like you edited your question. You now no longer ask if the example tasks can be achieved using PowerShell)
Powershell snap-in for IIS 7
Restart-Service
Group policies
etc...
Sorry for not answering your question. I was in a similar situation.
I gave up to do all tasks on the windows shell
Instead I do use the shell for some tasks, but I am also using rdesktop (through ssh) and I put icons for the most important gui admin tools on the windows quicklaunch.
I gave up making windows feel like unix because it never will.
alternatively try to download and install eurysco to use the following features that is based on another logic...
1.create a new virtual folder in IIS (from eurysco commandline to launch vbs or powershell script)
2.setup firewall ports (from eurysco commandline to launch netsh.exe advfirewall)
3.restart services (from eurysco service control)
4.change user policies (from eurysco system registry or commandline to launch powershell script)
5.start desktop applications (from eurysco commandline to launch powershell script)
http://www.eurysco.com/features

PowerShell script packaging and WinNT execution?

Is there any free software to package a powershell script into a standalone WIN32 executable?
It seems it was possible to get the powershell beta's to run on win2000 and winNT, is there any known way to get the final powershell to run on it?
I don't think there is any software that will package a PowerShell script into a stand-alone executable. That would require bundling PowerShell itself with the script (no small feat).
The oldest supported OS is Windows XP SP2, so there is not a supported way to get PowerShell to run on NT or 2000.
A easy step would be to create a .NET exe which embedded the script.
This would, of course, require PSH (and any non-standard snapins) installed when executed.
To remove those dependencies you would need to be able to handle any cmdlets used, as noted #aphoria this would be reinventing PSH, and all the snapins.
Not strictly the answer you are looking for (free software), but it may be useful to others. Here are some commercial options for packaging scripts into single executables:
Admin Script Editor
PrimalScript OR PrimalPackager (just packaging portion of PrimalScript)

Resources