Execute batch file on remote computer - powershell

I am on host_computer and attempting to execute batch file on remote_computer (part of WORKGROUP) to enable psremoting and use winrm to add trustedhosts.
Based on http://social.technet.microsoft.com/Forums/scriptcenter/en-US/732495c0-114c-4a1e-bbe1-5a7a3b84012d/execute-a-batch-file-on-a-remote-pc?forum=ITCG
I tried creating a process, i.e.
$server = "remote_computer"
$process = [WMICLASS]"\\$server\ROOT\CIMV2:win32_process"
But I get error
Cannot convert value "\\remote_computer\ROOT\CIMV2:win32_process" to type "System.Management.ManagementClass". Error: "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" At line:1 char:1
+ $process = [WMICLASS]"\\$server\ROOT\CIMV2:win32_process"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvalidCastToWMIClass
Then I tried using psexec
PsExec.exe \\remote_computer -u username -p password 'C:\share\enable.bat'
And get error
D:\pstools\PsExec.exe : At line:1 char:1
+ D:\pstools\PsExec.exe \\remote_computer -u username -p password 'C:\share\ena ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError PsExec v2.0 - Execute processes remotely Copyright (C) 2001-2013 Mark Russinovich Sysinternals - www.sysinternals.com The handle is invalid. Connecting to remote_computer...Couldn't access remote_computer: Connecting to remote_computer...
And this batch script is to enable psremoting and add trusted hosts using winrm
#echo off
C:\share\remote.ps1
winrm set winrm/config/client/auth #{Basic="true"}
winrm set winrm/config/client #{AllowUnencrypted="true"}
winrm set winrm/config/client #{TrustedHosts="host_computer"}

Related

get NativeCommandError when running powershell script

I'm looking some help. I have batch file on remote PC like this (Path on remote PC = C:\temp\silentsophos.bat) :
\\svr-sophos\SophosUpdate\CIDs\S000\SAVSCFXP\Setup.exe -mng yes -updp \\svr-sophos\SophosUpdate\CIDs\S000\SAVSCFXP -ouser <USERNAME> -opwd <PASSWD> -s -ni
and I tryin to execute that with powershell, which is the script is :
invoke-command -computername PC01 -scriptblock {(&C:\windows\system32\cmd.exe /c C:\temp\silentsophos.bat)}
and the result i get is :
Access is denied.
+ CategoryInfo : NotSpecified: (Access is denied.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : PC01
already tried with "2> $null", the error message is not showing up but on the remote PC seems nothing being executed or started.
Am I doing it wrong?

Installing CCM client on PC via powershell

I'm trying to speed up how soon SCCM recognises a device on the domain and starts the process of installing applications.
I have the below in powershell
$CCMInstallerPath = "\\ServerFQDN\SMS_MAN\Client\ccmsetup.exe"
$args = "/mp:MPServer", "/LOGON", "/UsePKICert", "SMSSLP=SMSSLPServer", "SMSSITECODE=MAN"
& $CCMInstallerPath $args
I get the below error:
Program 'ccmsetup.exe' failed to run: Access is deniedAt line:1 char:5
+ & $CCMInstallerPath $args
+ ~~~~~~~~~~~~~~~~~~~~~~~~~.
At line:1 char:5
+ & $CCMInstallerPath $args
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException
+ FullyQualifiedErrorId : NativeCommandFailed
I have read and execute access to this file, both by group and directly by name
I have also tried:
Start-Process -FilePath \\ServerFQDN\SMS_MAN\Client\ccmsetup.exe -ArgumentList "/mp:MPServer", "/logon SMSSITECODE-MAN", "/UsePKICert"
and get the error
Start-Process : This command cannot be run due to the error: Access is denied.
At line:1 char:5
+ Start-Process -FilePath \\ServerFQDN\SMS_MAN\Client\c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
ServerFQDN is a replacement for one of our NM servers
I can fully connect to the folder and run the exe manually
I am running elevated powershell
Issue was caused by incorrect share permissions found in effective access.
Permission was granted to run the file but effective access was showing differences

Windows cmdlet over powershell passes but gives access denied over winrm for Cluster aware updating

I am executing Invoke-CACURun for windows cluster aware updating on domain controller as an administrator. While that works on powershell, it is failing over ansible with ntlm transport and same credentials.
The command executed
ansible domain_controller -i ansible_hosts -m win_shell -a 'whoami;Invoke-CauRun -ClusterName "xyzWFC
The error I get is
Invoke-CauRun : Could not open cluster "xyzWFC": (Win32Exception) Access is denied
At line:1 char:72
+ ... .UTF8Encoding $false; whoami;Invoke-CauRun -ClusterName "xyzWFC";
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (:) [Invoke-CauRun], CauAccessDeniedException
+ FullyQualifiedErrorId : OpenClusterAccessDenied,Microsoft.ClusterAwareUpdating.Commands.InvokeCauRunCommandnon-zero return code
Any help on this?

unable to execute winrm quickconfig

I am unable to get around the following Powershell remoting error in my Windows 10 Machine.
Firstly I am attempting to execute the following.
PS: >Start-DscConfiguration -Wait -Verbose -Force -Path $outPath
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConf
igurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting
requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the
destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm
quickconfig".
+ CategoryInfo : ConnectionError: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : HRESULT 0x80338012
+ PSComputerName : localhost
so I do what it suggests by executing this.
PS: >winrm quickconfig
WinRM service is already running on this machine.
winrm : WSManFault
At line:1 char:1
+ winrm quickconfig
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (WSManFault:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Message
ProviderFault
WSManFault
Message = More data is available.
Error number: -2147024662 0x800700EA
More data is available.
Thanks for the help

Azure PowerShell will not connect

I have downloaded and installed the Azure Powershell by following the MS instructions:
https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/
Using the Windows Powershell ISE I run the command:
Login-AzureRmAccount
which returns the the error:
Login-AzureRmAccount : The 'Login-AzureRmAccount' command was found in the module 'AzureRM.Profile', but the module could not be loaded. For more information, run 'Import-Module AzureRM.Profile'. At line:1 char:1
+ Login-AzureRmAccount
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Login-AzureRmAccount:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
Import-Module AzureRM.Profile
Returns this error:
Import-Module : File C:\Program Files (x86)\Microsoft
SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Profile\CheckVersions.ps1 cannot be loaded
because running scripts is disabled on this system. For more information, see about_Execution_Policies at
http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ Import-Module AzureRM.Profile
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [Import-Module], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
Why is it so difficult to connect to Azure, what could be wrong?
From the command prompt run:
powershell Set-ExecutionPolicy RemoteSigned