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 10.0.0.22, 10.0.0.23, 10.0.0.24 -ScriptBlock { Enable-WindowsOptionalFeature -online  -FeatureName "ServicesForNFS-ClientOnly" } -credential my username
thank you
kuzumAsked:
Who is Participating?
 
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=@("10.0.0.22", "10.0.0.23", "10.0.0.24")

#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

1
 
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
0
 
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 10.215.235.14 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: (10.215.235.14:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotUseIPAddress,PSSessionStateBroken
0
WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

 
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.
ServicesForNFS-ClientOnly

The DISM log file can be found at C:\WINDOWS\Logs\DISM\dism.log
0
 
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.

thanks
0
 
kuzumAuthor Commented:
with attachment
Capture.PNG
0
 
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
0
 
kuzumAuthor Commented:
thanks Ben, it was helpful.
0
 
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. :)
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.