Skip to content

Instantly share code, notes, and snippets.

@ploegert
Created June 18, 2014 20:26
Show Gist options
  • Select an option

  • Save ploegert/b1919f0f31c544707bfc to your computer and use it in GitHub Desktop.

Select an option

Save ploegert/b1919f0f31c544707bfc to your computer and use it in GitHub Desktop.
PSRemote-CopyFiles
#Get the Remote URL
$uri = Get-AzureWinRMUri -ServiceName $AzureServiceName -Name $AzVM
srvuser = "DOMAIN\USER"
$srvpass = "Password"
#create the credential for the remote service
$log.debug("Creating credential for the Remote Session..")
$passwordCred = ConvertTo-SecureString -AsPlainText $srvpass -Force
$credentials = New-Object System.Management.Automation.PSCredential ($srvuser, $passwordCred)
$list = @{ "C:\Posh\Assert-BaseImagePreReqs.ps1" = Get-Content "C:\posh\Deploy-Base\scripts\Assert-BaseImagePreReqs.ps1";
"C:\Posh\azure.qa.xml" = (Get-Content "C:\posh\Deploy-Base\azure.qa.xml");
"C:\Tools\Get-PanoptixInstall.ps1" = (Get-Content "C:\posh\Deploy-Base\scripts\Get-PanoptixInstall.ps1")}
Invoke-Command -ConnectionUri $uri -Credential $credentials -ArgumentList $list -ScriptBlock {
param($list)
$WorkingDirectory = "C:\Posh"
if(!(test-path $WorkingDirectory))
{ New-Item c:\Posh -type directory }
else
{ write-host "Directory Already Exists."}
if(!(test-path "c:\Tools"))
{
New-Item c:\Tools -type directory;
New-Item c:\Tools\_deploy -type directory;
}
foreach ($i in $list.GetEnumerator())
{
Write-host "Key: $($i.Name)"
$destPath = $($i.Name)
$destContent = $($i.Value)
Set-Content -Path $destPath -Value $destContent
if (!(Test-path $destPath))
{Throw "Could not copy $destPath!!!"}
}
write-host "Invoking Command..."
set-location $WorkingDirectory
#. (join-path $WorkingDirectory "Assert-BaseImagePreReqs.ps1") -envConfigFile (join-path $WorkingDirectory "azure.qa.xml")
$env:COMPUTERNAME
write-host "End of Execution" -foregroundcolor yellow
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment