remote powershell script

Dear Experts,

I have windows 10 enterprise edition and my users are on win7.

I need to run PowerShell command on few specific workstations to enable windows feature remotely so that I do not need to do floor walking for each machine.

Could someone please validate this script;

Invoke-Command -ComputerName,, -ScriptBlock { Enable-WindowsOptionalFeature -online  -FeatureName "ServicesForNFS-ClientOnly" } -credential my username
thank you
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ben Personick (Previously QCubed)Lead Network EngineerCommented:
I didn't notice that you hadn't looked into the actual way to install a feature until I was wondering why you were using invoke the command and realized you wanted Windows 7 machines which only support DISM if you want to run this on windows 7 machines.

  Thankfully, unlike the option you chose which is only workable on windows 2012 and 2016, DISM works across versions because it's a cmd.

#Create Array of Computers
$Computers=@("", "", "")

#Get your credential from a pop-up on the Local Windows GUI (Enter Your Domain\Username and Password)
$Credential = Get-Credential

#Loop Computers and Invoke command
Foreach $Computer in $Computers {
     Invoke-Command -ComputerName $Computer -ScriptBlock { 
          & dism /Online /enable-feature /FeatureName:ClientForNFS-Infrastructure
     } -credential $Credential

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kuzumAuthor Commented:
Hi Ben,
thanks for your time. I just had a chance to test this and had below error?

At line:8 char:8
+ Foreach $Computer in $Computers {
+        ~
Missing opening '(' after keyword 'foreach'.
At line:8 char:19
+ Foreach $Computer in $Computers {
+                   ~~
Unexpected token 'in' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword
kuzumAuthor Commented:
I think you it is a typo error as I passed this stage by Foreach ($Computer in $Computers)

I am having another issue with it wondering if you could help please.

[10.x.x.x] Connecting to remote server failed with the following error message : The WinRM client cannot process
the request. Default authentication may be used with an IP address under the following conditions: the transport is HTTPS or the
destination is in the TrustedHosts list, and explicit credentials are provided. Use winrm.cmd to configure TrustedHosts. Note that
computers in the TrustedHosts list might not be authenticated. For more information on how to set TrustedHosts run the following
command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: ( [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotUseIPAddress,PSSessionStateBroken
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

kuzumAuthor Commented:
Hi Ben,

apologies for multiple threads, it seems issue was caused by IP address and not using the hostname. I managed to resolve it by
using the hostname and now ended with this

Error: 50

The operation is complete but ClientForNFS-Infrastructure feature was not enabled.
A required parent feature may not be enabled. You can use the /enable-feature /all option to automatically enable each parent feature
from the following list. If the parent feature(s) are already enabled, refer to the log file for further diagnostics.

The DISM log file can be found at C:\WINDOWS\Logs\DISM\dism.log
kuzumAuthor Commented:
Hi Ben,

after few hours of troubleshooting I manage to get this script partially working. It does now tick the box but it leaves the sub box expty. How do I force it to select the box I need?
I attached the screenshot and this is where I am now.

kuzumAuthor Commented:
with attachment
kuzumAuthor Commented:
I resolved this running 2 steps.

using the provided script from Ben, first run  dism /Online /Enable-feature /FeatureName:ServicesForNFS-ClientOnly /norestart
and secondly run dism /Online /Enable-feature /FeatureName:ClientForNFS-Infrastructure
kuzumAuthor Commented:
thanks Ben, it was helpful.
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Glad to help, sorry I missed your messages, last night we welcomed our second child into the world. :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.