Sunday, 9 April 2017

PowerShell remoting - create folder on remote servers

Preparation

Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File C:\Scripts\<username>\<username>_pwd.txt

Variables

$SPserver = "<servername>"

$username = "\"
$password = Get-Content C:\Scripts\<username>\<username>_pwd.txt | ConvertTo-SecureString

Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $password

Connection

#Create remote session to SP server
$session=New-PSSession -ComputerName $SPserver -Credential $credentials

Create DIR

Invoke-Command -Session $session -ArgumentList $output -ScriptBlock  { mkdir E:\<FolderName> }

#Removing remote sessions
Get-PSSession |Remove-PSSession

No comments:

Post a Comment