Run dos command in powershell from domain controller
hi, have issue:
run powershell script form domain controller.the script is:
clear-host $domainuser = "$env:userdnsdomain\administrator" $domainpassword = 'credential'| convertto-securestring -asplaintext -force $domaincredentials = new-object system.management.automation.pscredential ($domainuser, $domainpassword) $computers = get-adcomputer -filter * -searchbase “ou=lab-users,dc=lab,dc=local” | foreach-object {$_.name} $remotepath = '\\192.168.10.71\temp' foreach($computer in $computers) { invoke-command -computername $computer -credential $domaincredentials -scriptblock { new-psdrive -name uncpath -psprovider filesystem -root $using:remotepath -credential $using:domaincredentials copy-item uncpath:\win8.1andw2k12r2-kb3191564-x64.msu c:\temp set-location c:\temp cmd.exe /c wusa.exe win8.1andw2k12r2-kb3191564-x64.msu /quiet /restart write-host -foregroundcolor magenta $env:computername } }
write script install windows managment framework 5.1 in every computer in ou.
run in dc windows server 2012 r2 powershell v5.1.
in environment have 1 dc , 3 computer client windows 8.1 x64(with powershell 4).
script run in every single machine, when use script domain controller installation of msu file not run.
me please
hi luca,
try thing (make sure can execute scripts on domain controllers):
#requires -version 2.0 -modules activedirectory clear-host $domainuser = "$env:userdnsdomain\administrator" $domainpassword = 'credential'| convertto-securestring -asplaintext -force $domaincredential = new-object -typename system.management.automation.pscredential -argumentlist ($domainuser, $domainpassword) $computers = get-adcomputer -filter * -searchbase 'ou=lab-users,dc=lab,dc=local' | select-object -expandproperty name $remotepath = '\\192.168.10.71\temp' $packagename = 'win8.1andw2k12r2-kb3191564-x64.msu' foreach($computer in $computers) { invoke-command -computername $computer -credential $domaincredential -scriptblock { param( [parameter(mandatory = $true,position = 0)] [string]$remotepath, [parameter(mandatory = $true,position = 1)] [pscredential]$domaincredential, [parameter(mandatory = $true,position = 2)] [string]$packagename ) new-psdrive -name uncpath -psprovider filesystem -root $remotepath -credential $domaincredential copy-item -path uncpath:\$packagename -destination $env:temp -force set-location -path $env:temp cmd.exe /c "wusa.exe $packagename /quiet /restart" write-host -foregroundcolor magenta -object $env:computername } -argumentlist $remotepath, $domaincredential, $packagename }
Windows Server > Windows PowerShell
Comments
Post a Comment