Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aadennis
Created February 25, 2017 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aadennis/82e7fedf584a6bba178bfdbe36d5e6d8 to your computer and use it in GitHub Desktop.
Save aadennis/82e7fedf584a6bba178bfdbe36d5e6d8 to your computer and use it in GitHub Desktop.
Creates a folder using DSC going from one Azure VM (effectively a Push Server) to another on the same subnet.
$sandbox = "C:\sandbox\PowerShell"
#$node = "backendvm1.uksouth.cloudapp.azure.com"
$node = "10.0.2.5"
$folderToCreate = "c:\TheDemo05"
$userName = "adguy"
if (-not ( Test-Path $sandbox)) {
New-Item -Type directory $sandbox
}
cd $sandbox
Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value $node
#By this point we expect Test-wsman to return a result...
$testWsmanResult = Test-WSMan -ComputerName $node
$testWsmanResult
if ($testWsmanResult -eq $null) {
Write-Error "WsMan connection to [$node] could not be made."
throw
}
Configuration BasicDscConfig {
Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
node $node {
File MyRandomDir {
DestinationPath = $folderToCreate
Type = "Directory"
Recurse = $false
}
}
}
BasicDscConfig -InstanceName $node
if ($cred -eq $null) {
$cred = Get-Credential -UserName $userName -Message "Enter password"
}
Start-DscConfiguration -Path .\BasicDscConfig -Wait -Verbose -Force -Credential $cred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment