dimanche 17 novembre 2019

Using PowerShell to identify a machine as a server or PC

I'm trying to write a PowerShell script that will give me a list if of roles and features if run on a server but if run on a client machine will say "Only able to execute command on a server."

I've played around with this script a lot and can get it to run on either a client machine or server (depending on what I've tweaked) but not both. Here's the latest iteration:


$MyOS="wmic os get Caption"
if("$MyOS -contains *Server*") {
    Get-WindowsFeature | Where-Object {$_. installstate -eq "installed"
}}else{
    echo "Only able to execute command on a server."}

Can you see what I'm doing wrong? Thank you for any and all help!

Aucun commentaire:

Enregistrer un commentaire