I cannot find any PS script to restart splunk services.
I just wonder whether it can be doable to restart splunk service.
Usually it is run in command and change to splunk folder first
C:\program files\splunkuniversalforwarder\bin --then run command as below:
splunk restart
I would try one of the following:
Invoke-Expression "C:\program files\splunkuniversalforwarder\bin\splunk.exe restart"
OR
& "C:\program files\splunkuniversalforwarder\bin\splunk.exe restart"
Related
I want to restart docker for windows (now known as Docker Desktop) in powershell.
I would like to do it with one command in PowerShell.
May I implement it?
When using Restart-Service *docker*:
Kill and restart the docker process:
$processes = Get-Process "*docker desktop*"
if ($processes.Count -gt 0)
{
$processes[0].Kill()
$processes[0].WaitForExit()
}
Start-Process "C:\Program Files\Docker\Docker\Docker Desktop.exe"
In the if clause I check if any running docker process has been found. There should never be more than 1 instance of "Docker Desktop" running so you can then kill the first one in the list.
To restart you need to know the full path of the "Docker Desktop.exe" file on your computer.
You can user in powershell:
restart-service *docker*
Or int the Docker QuickStart Terminal:
docker-machine restart
On windows, open Docker desktop and click on the debug icon then restart. You can also consider "reset to factory defaults"
Similar to Sebastian L's comment above, but slightly cleaner & faster if you know whether you are currently running Linux or Windows containers.
If running Linux Containers
Stop-Service *docker*
Start-Service *docker*
&$Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchLinuxEngine
If running Windows Containers
Stop-Service *docker*
Start-Service *docker*
&$Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchWindowsEngine
-SwitchDaemon toggles from one to the other (Linux to Windows or Windows to Linux) which is why you have to do it twice.
Is there a way to reset an existing dev cluster with powershell similar how the Service Fabric tray tool is doing it?
There sure is (requires Admin privileges):
& "C:\Program Files\Microsoft SDKs\Service Fabric\ClusterSetup\DevClusterSetup.ps1" -PathToClusterDataRoot c:\SfDevCluster\data -PathToClusterLogRoot c:\SfDevCluster\log
You can change the path to \data and \log to where ever you want. Also, if you want the new 1-node dev cluster, add the -CreateOneNodeCluster option.
& "C:\Program Files\Microsoft SDKs\Service Fabric\ClusterSetup\DevClusterSetup.ps1" -PathToClusterDataRoot c:\SfDevCluster\data -PathToClusterLogRoot c:\SfDevCluster\log -CreateOneNodeCluster
Note that when you run this, any existing cluster will be removed and replaced.
I have a cloud service with the following line of code in startup.cmd:
net use n: \\<storage-account>.file.core.windows.net\scorm /u:<storage-account> <storage-password>
This successfully creates the mapped drive to point to the Azure File Services share, but it shows in Windows explorer as a disconnected drive and any attempt to remove it using the 'Disconnect' option results in a "This network connection does not exist" although if I double click the folder I am successfully able to access the files.
If I run the same command through a cmd prompt the drive shows as connected with the name of the share and the path displayed. Do I need to do anything different in the PowerShell startup command to render the same results as the cmd line prompt?
The "net use" command only connects to the share in the context you are running. So you will have to run the "net use" in the same context your role will run.
For web roles this will be "NT AUTHORITY\NETWORK SERVICE". To run "net use" in that context, you need a tool like psexec.exe, which you can download from Windows Sysinternals.
Place psexec.exe into your role's bin directory, and set up an elevated startup script with this command:
psexec -accepteula -u "NT AUTHORITY\NETWORK SERVICE" net use n: \\<storage-account>.file.core.windows.net\test /u:<storage-account> <storage-password>
Drives are mapped to your user token, and administrators have two tokens. Limited and elevated. Make sure you are using consistent tokens. I.e. if mapped while Run As Aministrator then only programs running elevated can access that mapping.
Can we capture logs if we run a job from power shell . As we are trying to run a control-m job from windows servers 2008 and its getting failed so we tried to run it from power shell . Is there any way to capture logs as job is failing in power shell also ?
You could use Start-Transcript for logging the actions/output of a script. You need to make sure the user running the script has write access to the output location.
Start-Transcript -Path 'C:\path\to\transcript.log' -Append
# production code here
Stop-Transcript
I'm trying (under Windows 7) to use the runas command to stop then restart a service. (Win7 requires admin privs to do this; thus the use of runas.)
Stopping the service works fine, but starting it does not. Here's the command I'm using for stopping the service:
runas /user:myDomain\myUserId "net stop serviceName"
Here's the command for starting the service:
runas /user:myDomain\myUserId "net start serviceName"
When I run the above command another command window opens, but flashes away before I can see anything in it; thus I have no idea what's going wrong.
So, my question is: How might I capture stdout and/or stderr from the net start command when run via runas? I've tried just using redirection but just get an empty file. Another solution would be to get the window opened by runas for the subtask to remain open.
Thanks in advance.
Launch cmd.exe instead with the command to run, and specify that the output be written to a file.
runas /user:myDomain\myUserId "cmd.exe /c net stop serviceName > output.txt"
You can use 2> for error output from net stop.
Also, if you don't want to bother with the output file, you can use cmd.exe /k instead of /c to launch the command and it will leave the session window open for you. Might be easier/quicker if you just want a quick peek.
Try gsudo and run the command:
gsudo net stop serviceName