Wednesday, August 22, 2012


Powershell Scripting 


we should follow some steps In order to connect to remote machine and execute batch file or copy file from the client machine through powershell script.

Remote machine:

Steps need to be followed in the remote machine in order to connect from remote through Powershell.

Open the command prompt and type “powershell” and enter. It will open the powershell prompt.

 To allow other machine to access remotely from poweshell scripting , We should create some listeners in the remote machine, so in order to create listener ,execute below command and it will ask user for the input, enter “y”.

1.       winrm quickconfig

We also need to increase the memory of  “Memory per shell”, so  execute the  below command
(From command prompt…not from PowerShell prompt)

1.       winrm set winrm/config/winrs @{MaxMemoryPerShellMB="1000"}
  

Client Machine :

From the client machine execute the below command to execute batch file of remote machine.

$SecPass = convertto-securestring -asplaintext -string "Password" -force
 $Creds = new-object System.Management.Automation.PSCredential -argumentlist " domain\user ",$SecPass
Invoke-Command -ComputerName ComputerName -cred $Creds { C:\foldername\test..bat}


Copy file from client to remote machine using powershell:


Execute the below command with the proper user credentials and source and destination path of the files need to copied.

Note: The folder in the remote machine should be shared before copying or pasting file.

Import-Module bitstransfer
$SecPass = convertto-securestring -asplaintext -string "password" -force
$cred = new-object System.Management.Automation.PSCredential -argumentlist "domain\user",$SecPass
$sourcePath ="C:\folder\testXML.xml"
$destPath ="\\remoteComputerIP\Test_Copy_File_From_Remote"
Start-BitsTransfer -Source $sourcePath -Destination $destPath -Credential $cred -DisplayName "TransferSOAPScript"



Copy file from remote to client machine using powershell:


Execute the below command with the proper user credentials and source and destination path of the files need to copied.

Note: The folder in the remote machine should be shared before copying or pasting file.

Import-Module bitstransfer
$SecPass = convertto-securestring -asplaintext -string "password" -force
$cred = new-object System.Management.Automation.PSCredential -argumentlist "domain\user",$SecPass
$sourcePath ="\\remoteComputerIP\Test_Copy_File_From_Remote\sample.txt"
$destPath ="C:\folder"
Start-BitsTransfer -Source $sourcePath -Destination $destPath -Credential $cred -DisplayName "TransferSOAPScript"


No comments:

Post a Comment