Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell if/else statement

$
0
0

Hi,

I hope this is the correct forum for my question. I am trying to write a script that tells me what the status of a hyper-v integration service is on a VM and then disable the service if it is true. Here is my script so far. I get as far as the if statement but it doesn't go to the else statement.

Currently timesync is set to true.

$timesync = get-vmintegrationservice -vmname <VNname> -name "Time Synchronization"
$status = $timesync.enabled
if ($status -eq "False") {write-host "time service disabled"}
Else {write-host "time is enabled"}

My end script I want it to actually do something like this:

$timesync = get-vmintegrationservice -vmname <VMname> -name "Time Synchronization"
$status = $timesync.enabled
if ($status -eq "False") {write-host "time service disabled"}
ELSE {disable-vmintegrationservice -vmname <VMName>"Time Synchronization"}

Any help with where I am going wrong is greatly appreciated.

Thanks,
Georgi


Georgi


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>