I'm trying to run this script on a list of computers but it is very slow... do you know a way to speed it up? Can anyone help me?
Thanks
psexec #C:\computers.txt reg query "HKEY_LOCAL_MACHINE\SOFTWARE\etc\etc" >> C:\output.csv
psexec #C:\computers.txt reg query "HKEY_LOCAL_MACHINE\SOFTWARE\etc\etc" >> C:\output.csv
This script works fine but it takes hours to end..
Related
I have a powershell script that uses azure cli to log in and do a bunch of other stuff. At the beginning I set
$ErrorActionPreference = "Stop"
When I run the script in the ps ISE and the azure login fails the error is displayed and execution stops, just as expected. But when I run the script from the ps command line (or from a batch that calls the script) the error is displayed - and execution continues?!
I tried with a try/catch, same thing there, the catch is only hit in the ISE but not from the command line.
This seems VERY strange to me. Anyone has an idea what causes this and how I can get around of it? Rebooting didn't help :-)
this answer might be a little to late, but i had the same problem with a connection to EWS.
It worked fine with the Powershell ISE, but it didnt work with the Powershell.exe.
After hours of testing i finally figured out that there is a difference between Powershell and the ISE in how they handle errors.
$errorlength = $Error.Count
$EmailAddress= Get-Mailbox -Identity $shortname.SamAccountName| Select-Object WindowsEmailAddress
if($errorlength -lt $Error.Count){
throw "Bad thing happened"
}
My problem was that there where some Mailboxes in our adress list which are in the office365 cloud an some on the Exchange server.
Somehow Powershell ISE terminated on the error and Powershell itself did not.
If your error also occures at the excact same position all the time this should work for you too.
It forces the program to terminate if the errorcounter goes up.
Steps:
1. I have created a file known as: "test.vbs" under temp folder in machine B and in that script i have msgbox "hi"
2. From machine A - my goal is execute to test.vbs in machine B
3. In machine A. i did the following steps but i didnt get remote script executed. Can anyone please help me.
ps c:/> $s=new -pssession -computername machineB
ps c:/> Invoke-Command -Session $s-ScriptBlock{$filecount=(Get-ChildItem c:\temp\test.vbs -Recurse)}
ps c:/> Invoke-Command -Session $s-ScriptBlock{$filecount}
i received directory c:\temp and a file name as test.vbs
Now i want to execute test.vbs
ps c:/> Invoke-Command -ComputerName MachineB{& "C:\Temp\test.vbs"}
After executing the above command i dont see the test.vbs not executing remotely.
my expectation is to get hi messagebox.
I am not understanding if it got executed or not.
can anyone please help me to execute remote script locally using power shell.
thanks inadvance.
If my understanding to your question is correct, you want to execute test.vbs against machine B from machine A, I don't think it's possible in PowerShell.
I faced the same issue some time ago. Neither Enter-PsSession nor Invoke-Command can do it for you probably just because they are not designed for this purpose. They are working totally fine if you run any PowerShell cmdlets remotely e.g. Get-Item you can easily get items on machine B. But once if you try to do something beyond the PowerShell remote session, like run a vbs script which will start a new CScript.exe process, it just won't work. It's due to some reason in underlying implementation of this PowerShell remoting.
If you do need to do that, I got two workarounds
PsExec can be the best solution. It was designed to do this kind of work originally and it can easily accomplish what you want with a bunch of advanced features.
Create a scheduled task on machine B by using New-ScheduledTask and let it trigger itself on machine B locally.
If you have SCCM installed, it also provides this kind of functionality, check out this blog.
I work on my computer A.
I would like to run a batch script.bat on my computer B (C:\Documents\script.bat). The password of the admin session of B is PASSWORD.
This is my command to execute my batch from computer B :
start C:\Documents\script.bat
Now, I would like to run it with this argument : 3.2.16
I've tried these 3 commands but it says "incorrect caracter"
start C:\Documents\script.bat "3.2.16"
start C:\Documents\script.bat '3.2.16'
start C:\Documents\script.bat 3.2.16
Also, I would like to run it from my computer A.
Can you help me please ? Thank you in advance.
If you want to run a process remotely, you'll either need to use Sysinternals psexec, or wmic. The difference is that psexec diverts its output to the computer it's invoked from; whereas wmic displays a window on the remote PC.
If you're curious, the wmic command syntax is as follows:
wmic /node:remotePC /user:remotePC\user /password:password process call create 'cmd /c "c:\path\to\script.bat" "arg1" "arg2"'
If you need to view the output of script.bat, redirect the output remotely to a text file, then read the text file.
wmic /node:remotePC /user:remotePC\user /password:password process call create 'cmd /c blah ^>c:\output.txt'
net use z: \\remotePC\c$ /user:remotePC\user password
type z:\output.txt
del z:\output.txt
net use z: /delete
...for example. But it's probably easier just to download and use psexec.
I am stuck badly into this.
I am trying to execute following batch command which runs successfully on my system present on same network as remote server,
typeperf "\192.168.1.247\Processor(_Total)\% Processor Time" -sc 2
But if I try to run the same command on another remote server present on same network,
typeperf "\192.168.1.241\Processor(_Total)\% Processor Time" -sc 2
this gives me Error: No valid counters.
Please let me know what could be the issue and what could be the possible solution to this.
Regards,
Suvojit
Try refreshing WMI with this command:
winmgmt /resyncperf & wmiadap /f
Make sure that the WMI service is running, or restart it:
net start winmgmt
Run this command to ensure that the disable key doesnt exist, or its value is 0 if it exists.
REG query HKLM\SYSTEM\CurrentControlSet\Services\PerfProc\Performance /v "Disable Performance Counters"
Try rebuilding the performance registry with the LODCTR /R command.
If nothing else works, you can try to manually rebuild Performance Counter library values as a last resort.
So i have fairly easy powershell script that contains following:
import-module activedirectory
Get-ADUser -Filter *
remove-module activedirectory
If i run it from powershell it runs OK, but when i try to call it from CMD nothing happens, it just opens powershell and thats it. I am using following command to run it:
powershell.exe -file "D:\test.ps1"
I noticed also following thing, 2 powershell.exe processes run after i execute this. If i exit from CMD from one powershell then i start seeing lists that this PS query should be returning. Is there a way to get this working since i am trying to run ps script as scheduled job. The crucial part here is import module when i run it over cmd which is not happening for some reason.
It's powershell 2.0 running on Windows 2008R2. I tried this script on win 2012r2, works fine from CMD... Looks like ps 2.0 limitation?
Could be a couple of things going on here. Since your windows opens and closes you wont get to see any errors that might be occurring. What is your ExecutionPolicy set to? Get-ExecutionPolicy
When I make scheduled tasks of my scripts I usually set up my action as such
Program/Script = %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
Arguments = -ExecutionPolicy Unrestricted -NoProfile -File C:\data\script.ps1
Start In = %SystemRoot%\system32\WindowsPowerShell\v1.0
Also, I don't believe it matters in this case but be sure you have the script "Running with highest privilege" if required.