I've been researching and learning about windows batch files, PowerShell and cmd these past few days.
We're having issues with Open Files, so we manually go to the server and do it with a press of a button. But since there might be a possible way to automate it and do the script every 5 minutes.
Someone helped me already telling me that I should make a script of
openfiles /disconnect /a* /op "E:\SERVERNAME\"
& so I did and put it on the Windows Task Scheduler Action Tab - Start a Program and put the file path of the batch file that I made.
But It seems that it's not working and we're still having the same issue.
I hope I made it clear.
Related
Currently I've got my PowerShell script on the desktop named Chrome with a Chrome logo on it. They launch that, it opens chrome for them to use but if you tab out you'll see a PowerShell script idle counting until it reaches the terminate period.
Issue - Small business owner that has several computers employees use for web (chrome) based duties day to day. Employees often leave without logging out and closing their browser.
My Solution - Run chrome in incognito by default
While this works, they are now leaving their incognito tab open and not closing it to prevent logging out...
My Solution - deployed powershell script to close chrome after a set period of idle mouse and KB.
WHY I'M HERE - Is there any way to prevent them from closing out of my powershell script? Also is there a way to make it less obvious a giant powershell icon in the dock?
This answer provides an overview of launching applications hidden.
A non-third-party solution that requires a helper VBScript, however, is described in this answer.
Assuming you have created such a script and named it runHidden.vbs and placed it in C:\path\to\HelperVBScript, you can create your shortcut file with a command line such as the following:
wscript.exe C:\path\to\HelperVBScript\runHidden.vbs powershell.exe -file c:\path\to\your\script.ps1
This will launch your PowerShell script (.ps1) invisibly, while allowing it to launch GUI applications such as Chrome visible - and only the latter will appear in the taskbar.
My first thought would be to have it run as a job when the computer is logged in. Look into launching your script as a scheduled task with the command Start-Job.
Example:
Start-Job -ScriptBlock {### YOUR CODE HERE ###}
Then, you'd need to create a scheduled task to launch this script at login.
Here's a guide on how to do that: https://blog.netwrix.com/2018/07/03/how-to-automate-powershell-scripts-with-task-scheduler/
I have a .bat file that starts up a powershell script.
Within this powershell script, i startup PowerBI with a given database.
The powershell script waits till powerBI has been done starting up, and will then be exporting data to some datadump files.
Doing this manually works fine, and also when its on the task scheduler to run when user is logged on.
The moment i change this to "Run whether user is logged on or not" it doesnt work anymore.
The reason behind this, is that it seems that powershell is unable to start PowerBI and therefore there is no open data to query in the rest of the script.
So the positive side is it runs the bat and powershell just fine, only the powershell itself seems incapable to start powerBI.
Are there any solutions to this? should i for example use a different method to call the appliation to start?
currently the powershell snippit to start the app looks like this:
$PBIDesktop = "C:\Program Files\Microsoft Power BI Desktop\bin\PBIDesktop.exe"
$template = "C:\LiveData\Data.pbix"
$waitoPBD = 60
$app = START-PROCESS $PBIDesktop $template -PassThru
log_message "Waiting $($waitoPBD) seconds for PBI to launch"
Start-Sleep -s $waitoPBD
I faced similar issue. So, sharing my experience..
First of all, please verify couple of things.
Specify user account which will be used to invoke the job. Also, ensure that, the account have sufficient permission.
Don't forget to un-check the checkbox (as shown in screenshot) under Conditions Tab
Just found this one - sorry it took so long :D
But, i had this totally nervwrecking issue to.
Solution for me is to realize that the task scheduler is very deep part of the OS.
Thats why i have to grant access to the file, for the computername$ (system name) on the file or folder containing the file to run.
Rightclick on the file or folder -> Security. Select edit and add [Name of your computer]$ and give the read and execute permissions.
That's the only way I can make it run.
But i hope you found the solution in the meantime :)
When I run powershell ISE, I can execute commands/scripts without issue. When I launch either the 32 or 64 bit command line, the window takes about 30 seconds to load and then it is frozen. It will not accept inputs of any kind (keyboard or copy/paste). I have tried doing a system check, no errors. I even tried updating to powershell 4.0, the install was successful but the command line still locks on launch. Can anyone advise how to fix this? I am using windows server 2008 R2.
Update
It appears that the powershell is in fact accepting input, except at a glacial speed. I left the window open while I was writing this post initially, and then grabbed a coffee. Upon my return I found that what I have tried to copy/paste and type was now in the powershell command line. I have now attempted to execute $PSVersionTable.PSVersion, and going on 3 minutes now I still have no response. My guess is it will come back at some point but this is obviously not acceptable. Any ideas on how to debug/fix this?
Update2
As far as I can tell all the locations listed in $PROFILE | Select * don't exist. I also tried launching: powershell.exe -noprofile, but this did not help
After reading this post I decided to try that tool and see if I had a similar problem and discovered that there were literally hundreds of writes per second happening when powershell command line was running and they were all to the FusionLog. Disabling the Fusion logging fixed the issue completely (this was enabled a while ago to debug a different issue with an app and I must have forgotten to disable it). Everything else on the machine seemed to hum along just fine with FusionLogging in the background but powershell was horribly crippled. Hope this helps someone some day.
I've looked into the forum for one hour now, and tried everything I've found here but still I don't manage to run my .exe using a powershell script.
Please forgive my ignorance, I'm very new with powershell..
Basically, my script is aimed to daily monitor files loaded.
For this, I need to list .txt files in my working directory, which I managed to do.
My issue is that when files arrive in my working folder, they have nonspeaking names that I can't figure out which business it's related to.
There is a RemaneFile1.exe executable that renames files according to some data codes inside my .txt files from something like "Inf320638.txt" to something like "lot_RUHPEG_296_320638" and that is exactly what .exe I would like to run using powershell (I didn't coded it, and I don't know how it works, just that when I manually run it it renames my files just fine).
I've tried those two command lines below, but when I look at my files, they are actually not renamed.
1. &".\INFOCENTRE\LOTS\RenameFile1.exe
=> When I check my file name it's still like "Inf320638.txt".
2. Start-Process ".\INFOCENTRE\LOTS\RenameFile1.exe" => A command prompt shows up for an instant, but when I check my file name it's like "Inf320638.txt".
Any help would be highly appreciated,
Brgs,
Thomas.
Try to run the executable with the following arguments:
Start-Process .\INFOCENTRE\LOTS\RenameFile1.exe -WorkingDirectory .\INFOCENTRE\LOTS -Wait
It might be, that the workingdirectory is what screws it up. The -wait switch lets powershell wait for the programm to finish, you could omit it.
I have a startup task for my webrole that download some executable file from a blob and then proceed to the installation.
From a .cmd file, I start a power shell script that download the files, then I start the file from the .cmd.
The script works fine if I run it manually through RDP after the publishing is done.
But, when running as startup script, it sometimes (often) fail at different points.
The taskType is set to background.
Last time, the error was that the command PowerShell does not exists...
Also, I use powershell -command set-executionpolicy unrestricted before running my PS script, but I read here that other task may reset this setting and make mine fail.
Quite a mess.
So that makes me think that if I could wait for all other task to perform before starting mine, it would eliminate these kinds of problems
I suppose I could check if some process is running and wait for it to finish, but I have no clue wich process to check.
Or maybe there's another solution.
~edit~
I read here that the error about powershell not existing may be caused by the batch file being saved as UTF-8 in visual studio. I re-writed it from scratch in notepad++ and made sure it is save as ANSI. Then, same error. The full message is :
'PowerShell' is not recognized as an internal or external command,
operable program or batch file.
Again, the script run perfectly from command line in remote desktop.
It would be possible to set an environment variable at the end of the script that is required to finish, then in the script which is awaiting the dependencies, loop until the environment variable is set, then kick off its activities.
You could also run everything from a single powershell script and use the '-asjob' switch on your installer statement, use the 'wait-job' cmdlet to block until the task is complete then carry on. Powershell also offers a '?!' operator which ensures the last statement executed properly.
This might be caused by an encoding issue. As mentioned in this answer you should save your file in ASCII to ensure correct interpretation of your script.
From the linked answer:
Open your whatever.cmd file with your VS 2012 Ultimate. Click on File->Save whatever.cmd as -> on the dialog there is little arrow next to the [save] button. It will show up a menu that will have the option Save with Encoding.
Select it. Now choose "US-ASCII Codepage 20127" from the list of available encodings.