Powershell remoting with V1 - powershell

Do you know of any good remoting solutions using powershell V1 (I know the V2 stuff is awesome, but my organization doesn't like using pre-release software). I don't need anything spectactular, just a way to kick off powershell script on another box and get the results back when they're done. I'm considering using sysinternals PSEXEC and export-csv/import-csv and just making something that works. I'd rather have someone else do the work, though.

I think PrimalScript's Remote Script Execution Engine would do what you're after. It does require a small service to be installed on remote computers, but you get unlimited licenses for that when you buy PrimalScript (Enterprise edition).
There's also a PSHRemoting project someone did.
N Software's NetCmdlets also come with a "PowerShell Server" (http://nsoftware.com/powershell/) which enables remoting.

There is a great article up on the PowerShell team blog that describes how to get some basic remoting working in V1.
Basically, PS V2 uses Windows Remote Management (WinRM) under the hood. Winrs is the command line tool used to work remotely with machines.
This tactic that Jeffrey talks about uses WinRS and some PowerShell trickery to get remoting working in V1. Its not as slick as V2, but you can definitely get some basic stuff working with it.

I have used PSExec successfully. You can also use WMI to kick off remote processes. Here is an example.

Lee Holmes has posted a solution using PSExec and xml (rather than csv) http://www.leeholmes.com/blog/CategoryView,category,guide.aspx

Related

Running Windows Powershell script always from task scheduler

This might be a very basic question. I have FileWatcher script in windows powershell which I want to run always so that it keeps watching a particular location for files. when I run it from Windows Powershell IDE its run perfectly fine. I understand that I can schedule a task in windows task scheduler for that but what's happening is that the task runs and then comes back in "Ready" status. This is NOT working. I think it should be in "Running" state always. I might be missing something. Please kindly help with your valuable suggestions.
You can do this with TaskSchedule…
Running PowerShell scripts as a “service” (Events: Prologue)
but this is also what permanent Event Subscriptions are for or setting up as user10675448 suggest, make it a real service.
How to run a PowerShell script as a Windows service
Windows PowerShell - Writing Windows Services in PowerShell
This article presents the end result of that effort: A novel and easy
way to create Windows Services, by writing them in the Windows
PowerShell scripting language. No more compilation, just a quick
edit/test cycle that can be done on any system, not just the
developer’s own.
There is also this approach...
PowerShell and Events: Permanent WMI Event Subscriptions
Unlike the temporary event, the permanent event is persistent object
that will last through a reboot and continue to operate until it has
been removed from the WMI repository.
There are multiple ways of setting up the WMI events and I will be
covering 3 of those ways (as they deal with PowerShell) in this
article.

PowerShellPack - TaskScheduler module - run task with no logged user

I need to schedule a task via Powershell v2 on Windows Server 2008. I am using the TaskScheduler module from the MS PowershellPack.
Scheduling a task is ok, but I need the task to run even nobody is logged on.
I saw that this is possible in Powershell v3 on Win8 or Win2k12 (this QA). But that is not my case - I need to this in Powershell version 2.
Is this possible with module I am using? Or is there some workaround?
http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357(v=vs.85).aspx
Not possible down in the V2 world, But this will accomplish everything you need, and can be directly called from powershell
Edit:
This question got me thinking, and I realized your scenario is slightly different than mine, making it so this Should Be Possible.. So I was wrong before. Turns out, the Scheduler.service comobject is compatible with Powershell 2.0, but also only works with Task Scheduler 2.0. I thought it wasn't because I am on xp, and Task Scheduler 2.0 is only available in vista and up.
Looking into the source code of that MS PowershellPack, I found that all it is doing is using the Scheduler.service com object. https://github.com/sushihangover/SushiHangover-PowerShell/tree/master/modules/TaskScheduler
For a good tutorial of how to manipulate this com object for yourself : https://blogs.technet.microsoft.com/heyscriptingguy/2009/04/01/hey-scripting-guy-how-can-i-best-work-with-task-scheduler/
And the answer to your question: How to set schedule.service "Run whether user is logged on or not" in Powershell?
Sorry for the misunderstanding.. I won't let it happen again :D
Either way the schtasks.exe will cover all your bases and IMO is easier to work with, because it is one command, and doesnt require you to Invoke-Session when trying to schedule a task on a remote server.

Deployment not in a domain - psexec.exe or powershell remoting

I am working on an automated deployment process for a web application. The deployment will need to:
Deploy DB changes to database using sqlpackage.exe
Deploy reporting services reports to the reports server using the web service
Deploy web app to web server(s)
Deploy fonts for reports
among other things
The first two are reasonably straightforward to run from the web server, as the web service and db are contactable, and the tools to deploy run over the network.
From reading it appears that powershell remoting should be the way to go, and internally this would not be a problem. However when deploying to production, this will be being carried out in a datacentre, where the machines (2web, 1db) are not on a domain at all. I'd like to come up with a generic process that can run both internally and externally with the appropriate configuration. Powershell remoting, with machines not in a domain appears to require a fair bit of configuration using https etc., as NT credentials can't be validated.
Should I battle out configuring powershell remoting, or would configuring this to just use psexec to execute a powershell script directly on the remote machien, copying the deployment artifacts to a drop folder on the remote machine be the best way to go?
psexec seems to "just work". It appears powershell remoting comes with a lot more pain.
Why not use psexec then? You can restrict it's role to just getting you on to the remote machine, and not let it infect your scripts. I have not attempted to get ps remoting working on a non-domain, but it general I have found it to be fairly high effort to get going. Psexec, as you say, can often be simpler.
Excuse the peddling, but the open source framework I helped build called PowerUp essentially does all this for your. It uses a model in which the powershell (well psake) scripts can move execution to another machine by calling a specific function. This can either be done with powershell remoting or psexec - you wouldn't need to change the script, it just requires a setting per environment to say which you would like to use.
Check other the sample at https://github.com/AffinityID/PowerUpSamples/tree/master/SimpleWebsite.
Hopefully that shows you enough, but if not let me know and we can go into more detail.

Does a command-line client exist for Microsoft Jet database engine?

Is there such a thing as a shell-based command-line client for Microsoft's Jet database engine?
Something similar to SQLite 3.x (sqlite3.exe) for SQLite.
Will PowerShell be suitable? Fellow MVP Richard Siddaway has started a very interesting series of blog postings on using PowerShell and Access. You can ignore the Office 2010 tag on his blog postings. Also note that I know nothing about PowerShell.
This may suit:
Cscript.exe is a command-line version
of the Windows Script Host that
provides command-line options for
setting script properties.
With Cscript.exe, you can run scripts
by typing the name of a script file at
the command prompt. Like Microsoft
Internet Explorer, Windows Script Host
serves as a controller of Windows
Script compliant scripting engines,
but Windows Script Host has very low
memory requirements. Windows Script
Host is ideal for both interactive and
non-interactive scripting needs, such
as logon scripting and administrative
scripting.
Windows Script Host supports scripts
written in VBScript or JScript.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/wsh_runfromcommandprompt.mspx?mfr=true
Something like osql with the right data provider? http://msdn.microsoft.com/en-us/library/aa214012(SQL.80).aspx
Entering the conversation here 10 years after the original question, but I've played with a couple of tools that should work:
YouAccess (http://youaccess.sourceforge.net): "YouAccess is a free (donationware) lifesaver console µapplication intended for SQL management of Microsoft® Access™ databases from command line, including creating them."
JetSQLConsole (https://sourceforge.net/projects/jetsqlconsole): "A command line/console interface for Microsoft Access databases, very similar to the MySQL client application."

Application Deployment with Powershell

I've developed a Powershell script to deploy updates to a suite of applications; including SQL Server database updates.
Next I need a way to execute these scripts on 100+ servers; without manually connecting to each server. "Powershell v2 with remoting" is not an option as it is still in CTP.
Powershell v1 with WinRM looks the most promising, but I can't get feedback from my scripts. The scripts execute, but I need to know about exceptions. The scripts create a log file, is there a way to send the contents of the log file back to the "client" (the local computer making the remote calls)?
Quick answer is No. Long version is, possible but will involve lots of hacks. I developed very similar deployment script/system using PowerShell 2 last year. The remoting feature is the primary reason we put up with the CTP status. PowerShell 1 with WinRM is flaky at best and as you said, no real feedback apart from ok or failed.
Alternative that I considered included using PsExec, which is very much non-standard and may be blocked by firewall. The other approach involves using system management tools such as MS's System Center, but that's just a big hammer for a tiny nail. So you have to pick your poison...
Just a comment on this: The easiest way to capture powershell output is to use the start-transcript cmdlet to pipe console output to a file. We have a small snippet at the start of all our script that sends a log file with the console output from each script to a central file share, and names the log file with script name and date executed so that we'll have an idea of what happened. Its not too hard to pipe all those log files into a database for further processing either. Probably won't seolve all your problems, but would definitely help on the "getting data back" part.
best regards,
Trond