Why do some scripts fail to remote when locked - powershell

I have one script that asks a few computers via invoke command once an hour for 7 hours and it works fine. The computer locks still runs.
I have other scripts that query thousands of computers and if the computers locked it's like permissions are blanked and it stops working. I can't explain it. And everything I Google pulls up bad information due to keywords. I don't have example code. But for example I'm listing a specific directory in every computer and it fails when I log out. I don't have 15 hours to wait for the script to finish. I am sorry for no code but I don't know where else to ask. Just some direction pointing and I can figure it out. Please.

Related

Task Scheduler doesn't send email in the night

I have a batch file that runs a piece of R script, which scrapes some websites and results in two actions: (1) save the data and (2) send it to me through email.
I want this to be done on a daily basis during the night so that each day in the morning I will have some updates. So I set a task in Task Scheduler that runs at 2am each day. However, it didn't work as intended. I could see the website were scraped and the data were saved (by checking modified time), but never got the email.
Pretty sure both the R script and the batch file works perfectly if I run them in the normal way. More strangely, if I set the task to be triggered at, say, 10am when I am normally logged in and using the PC, everything works just fine and I can get the email.
So the only difference is that at 2am my PC is locked (not logged out) whereas at 10am I am using the PC. However, I have ticked the options 'run whether user is logged on or not' and 'run with highest privileges' in Task Scheduler anyways, so I cannot see where the problem is. Any help? Thanks!
Tried various setting options in Task Scheduler but didn't work.

Delete Built-in Administrator

Back story real quick: some reason some servers have 2 local admin account... no idea, I took over the job and cleaning everything up.
I need to go through 600-ish (or more) servers to delete the extra account.
PowerShell is great but can't work this out. How can I modify and read this location in PowerShell?
I can read up to here: HKLM:\SAM, and cannot see HKLM:\SAM\SAM... ?
How can I get PowerShell to edit permissions and read this location?
Once I can see this location I will work out how to delete it remove-item-somethingsomething
Thanks all :)

Script runs fine in ISE, but not in Powershell Console

I wrote an extremely lengthy script that creates a form. The main purpose of it it to connect to vCenter servers, total up hosts/vms within different datacenters and also identify ESXi host versions. Running the script in ISE the form loads fine and when I click the Button to start the many various functions to update the fields, it runs. I have Foreach() fields throughout and added in a little StatusLabel to the bottom of the form to show me where in the script it is currently scanning.
Once all was done and working, I saved the PS1 file and moved it to a shared server to be run. When I run the Powershell console (as Admin) and point to the file, the Form loads ok. Once I click the button to begin generating the info, It just changes to (Not Responding) and grays out. I know it's working and if left there long enough it will return the info.
Why does the console window not function like the ISE? I want to be able to see the information and Status Label update/change as it goes through the script (just like I do in the ISE).
Appreciate the feedback. The script is several thousand lines long and would need to be scrubbed before I upload. Was hoping to just get some general info before doing that.
I updated to v4 and verified that my command window was running as STA using the command from Jan Chrbolka. Script runs properly now.
I was also facing the same issue.(Btw, I cannot upgrade Powershell to V4 right now since it is my company owned one.)
The Browse button that I incorporated in my form was not working when I am lauching it from Powershell command line. It went to Not Responding state when I click the browse button.
I took the advise from Jan ChrbolkaMay about the STA and MTA.
I checked for the threads related to that and changed the script execution format to the below one which fixed my issue.(adding the word -STA)
powershell -STA -File D:\PS\GUI.ps1
For checking the current state. Use the below query in Commandshell as well as ISE.

Script that runs itself every now and then

I work in marine systems institute. We have a buoy that sends information about the sea every few hours to a central computer in the institute. It drops it as a .txt file in a certain folder. It would be really great if I could make a script that looks into that folder every 3 hours and checks if there are any new files. If there is a new file, it should upload it to an ftp.
I have no idea where to start. Are there any suggestions what language, where to look, what to search etc.
The computer is running 24/7 and the script can easily be an executable that is active all the time. The script doesn't have to restart itself every time, it can be up and running 24/7 also.
Thanks in advance
EDIT1: My op.sys is windows
If your platform is Windows, I suggest Windows Forms Application. An IDE is available, Visual Studio - it is easy to use and has everything you need for your application. You basically need a timer object that will execute a function (checking the file) in a certain interval. 3 hours is long enough, you can even check it every 5 min.
AutoHotKey can be learned by anyone in a day, and is powerful enough to do what you describe.
A program written in a real language could do exactly what you like with full customization, robustness, portability, and maintainability, but will take quite a bit longer to make.
It might be a little over your head if you never done any programming(Forgive me if you have).
A good solution is to use FileSystemWatcher http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx. Then create a windows service to run it.
But again that takes some experience implementing.
Try using an ftp client such as smartftp which can watch the folder where the files are created, and automatically upload them.

Making and Interfacing with Custom Services

I've been searching for this for awhile now, and I am not sure if I am just not using the correct search terms or if the answer is really that hard to find.
What I am trying to do is to create a new Windows service for a game server from a batch file, and then have a task run another batch file every 30 minutes or more that would run two commands on the game server's command line and do some file work.
Specifically, I am running a Minecraft server using Bukkit for a gaming community I help run, and I want to make sure that the thing is always up unless I specifically tell it to stop (like a service). Bukkit is run directly from a batch file and has it's own command line thing running on it.
I am told that you CAN run this type of thing as a service, but the command line will be hidden from view and/or interaction. This is the second part of my query. I have a handy little backup.bat file that copies all the world files and userdata files into a backup directory, 7zips it, and deletes the directory. The only thing is, is that Minecraft likes to always have the worlds' region files open and writing at all times, meaning that it could cause map corruption if I just run it straight off. To compensate, I need to run the command "save-off" on the server to disable the file hooks temporarily, run the backup, and as soon as it finishes, run "save-on" so that the game can continue without lost data.
What I would like to know about this second one is, is it possible to interface with the game service through a batch file, or do I need to create an application to do that? If the latter, how exactly does one go about doing that? I have moderate C++ knowledge (up through my second OO-C++ course in college), and can possibly learn another language if absolutely necessary.
So, in short, two questions:
1. Is it possible to, and how to run a BAT file as a Windows Service?
2. How to interface with said service via BAT files, and if not possible, what kind of application do I need to write (redirection to or writing a tutorial works for me).
Thank you in advance for any and all help!
Old question, user account doesn't seem active on SO anymore, but hey, if you stumble upon this because you have a similar problem:
Since we are speaking about a Bukkit Minecraft server, turn to the "Essentials" plugin for Bukkit.
It now includes a Backup function that does exactly what the OP asks for, namely stop the save so the files can be manipulated without corruption, launch a script, then starts again.
The script can be a backup one (examples provided in the linked page) but can be used to run any operation on the world's files.