Powershell scripting - powershell

I want to automate test using powershell. I want to write a script to shutdown the computer, wait for 3minutes and then power on the computer. Is it possible using Powershell? I know that reboot is possible, but I want the system to remain in shutdown stage for 3min and then power on.

If you mean a "real computer" (not a Virtual Machine) so it's not possible. But you can achieve that using Virtual Machine setup. Take look at this documentation: https://technet.microsoft.com/en-us/library/hh848589.aspx

You can shutdown computer with Stop-Computer command
Wait with Start-Sleep
But to poweron PC you need something more complex, take a look at WOL. However there are some difficulties:
It would work only with PCs that allow to be awakened with magic packets
You need to know MAC-address of machine
Target machine should be in the current network subnet of the caller.

Related

Determine if users can RDP after Windows Update

I'm automating windows updates for a set of SQL servers, mostly running on Windows Server 2016. Typically after you install updates you have to reboot, and there is a period of time after rebooting where the server is applying updates and users can't remote into the server. In my automation, I would like to wait until that period of time is over before reporting a successful update. Is there an indicator that I can check remotely through powershell that will determine whether a user can remote in?
I've checked the main RDP services (termservice, SessionEnv and UmRdpService) during this period and they are all running, so if there's some sort of indicator, it isn't them. Maybe there is a field somewhere that states that windows is applying updates? All of the servers are virtualized through VMWare if it matters.
Thanks for reading!
How about testing the port that the remote desktop service listens on?
test-netconnection server -port 3389
I didn't have any luck on ServerFault either, but I did eventually find a solution myself, posting here in case anyone finds this thread looking for help.
The isn't actually a service that changes states when you can RDP back into a server; that's probably determined somewhere in the windows code and there's no way you could find the flag. However, the TIWorker program runs after a reboot to install windows, and in my experience recently, when that exe completes, you can RDP 100% of the time, which is good enough for my automation.
I loop over this piece of code in 5 second intervals until it returns 0 rows, then finish.
Get-Process -ComputerName $server | ? {$_.ProcessName -match 'TiWorker'}

Podcast client with scheduler?

Can anyone suggest a Windows podcast client that includes a scheduler that restricts the hours during which podcasts will be downloaded?
I haven't found a client with a scheduler, but gpodder has a command line version (gpo) that can be run with the Windows Task Scheduler (or cron on *nix systems). For the energy conscious, Wake On Standby can be used to wake a Windows computer from sleep or even hibernate (assuming your bios supports it - pretty common in anything less than about 10 years old).
As far as I can tell, gpo will accept only a single command on the command line, so you'll need to write a script/batch file with the update and download commands. Redirecting input from a file doesn't seem to work.

usb local and remote port configuration via cmd batch

(xpost from superuser with no answers.)
I am trying to reconfigure a known (virtual?) com port on multiple computers on a local network using a batch file.
A USB device we use is installed always as com9 and always comes in as default 9600 baud, and we have to manually reconfigure each station to 57600 baud.
I already have this batch file renaming printers, dns servers, Killing and starting tasks, copying files and a whole lot more, I've experimented with mode, but I'm either not using it properly or it can't do what I want.
I know I can use the GUI, but for the sake of speed, I want the batch to do it.
Sorry if this is a copy, but I'm seeing if anyone has an angle for me, I'm not afraid of personal research, but I'm running into dead ends with no leads.
Ask if you need any clarifications, and thanks in advance.
Powershell is okay too if I know what I need and can still stay in the cmd environment.

Remote Execution of "get-process" Fails, Couldn't Connect to Remote Machine

In my workplace, we administer hospital intensive care PCs (Windows 7 desktop clients) that are meant to be on and running a particular program in near-perpetuity. To that end we've developed a few powershell scripts that run every 5 minutes and alert us whenever the PCs drop off the network or the processes / programs we require crash.
Our program monitoring script relies on the powershell cmdlet "get-process" run remotely by an admin-credentialed account. The script works on all of our PCs except one and we haven't been able to determine what's causing the failure.
At its most basic, the command looks something like
get-process -computername [hostname]
When pointing toward our problem PC we get the error
Get-Process : Couldn't connect to remote machine
Our research indicates that this is likely caused by permissions, firewall, or remote registry service problems. We've triple-checked and on this PC and
the monitoring account has admin privileges, no firewall is active, and remote registry service is on and set to start automatically. The code works when run on the local machine but not when run remotely.
Similar powershell cmdlets run remotely, like "get-service", work with no issues. As noted above "get-process" runs successfully on our other PCs. Any insight into this strange issue would be appreciated.
One thing to note is that the Invoke-Command workaround that has been offered in answer to other, similar questions doesn't work on this PC or any of our others.
Have you tried validating the all RPC services are up?
1.Remote Procedure Call(RPC)
2.Remote Procecure Call(RPC) Locator
3.Remote Registry (You said it's up though)

Powershell – Windows startup procedure monitoring

I want to conduct some specific actions right after Windows startup (when user is logged on) via PowerShell script. However, I do not want to do it by adding my PowerShell script to Windows Startup because in this way my script will run in the middle of Windows Startup procedure. Therefore, some services and applications may not be started yet.
I want to run the script when ALL Windows Services are started, all applications from Windows Startup section are run and HDD is not heavily loaded. Is it possible to detect such Windows state using PowerShell?
I would be grateful for any kind of help, because I am running out of ideas…
Create a Powershell startup script. Set it to monitor system via Perfmon counters and wait untill the system is idle enough. Like so,
$epsilon = 0.2
do { # sleep and loop untill cpu load is low enough
start-sleep -seconds 5
$counter = Get-Counter "\\computer\Process(Idle)\% Processor Time"
} while ($counter.CounterSamples.CookedValue -ge $epsilon)
# The system is now idle enough
# Start the real work after the loop
The proper counter set depends on what you are after. Current disk queue might be of interest too.
The same approach can be used to check service state, running processes and so on.