Scripts to push the ArcGIS Module - Esri/arcgis-powershell-dsc GitHub Wiki

The following appendices provide sample scripts to handle the ArcGIS module after you've downloaded it to your workstation machine.

Appendix A - Prereqs.bat

Use this batch script to copy the ArcGIS module from your workstation machine to the PSModulePath. (Edit DSC_RESOURCE path)

@echo off

if "%1"=="-h" (
  echo The script installs ArcGIS W=Enterprise on the machine using ArcGIS Setups from Fileshare
  echo Usage: Prereqs.bat [build #] 
  echo With no parameters the script uses the latest setups from Fileshare.
  exit /b
)

set DSC_RESOURCE="[... Module FileShare Path ...]"
set DSC_RESOURCE_TARGET="C:\Program Files\WindowsPowerShell\Modules\ArcGIS"


if not exist %DSC_RESOURCE_TARGET% (
  echo Target path not found.
  md %DSC_RESOURCE_TARGET% 
)

xcopy %DSC_RESOURCE% %DSC_RESOURCE_TARGET% /E /Y

PowerShell.exe -Command "& Set-ExecutionPolicy RemoteSigned -Force;winrm quickconfig -quiet; "

Appendix B - Install-PreReqs.ps1

Use this script to push the ArcGIS module from your workstation to the remote machine. (Pass in a comma-separated list of your remote machines in the Deployment and ModuleSourcePath variables on the workstation. If necessary, edit the Version of the Module in the script.)

Install-Prereqs.ps1 -ServerMachines [Comma-separated list of all target machines of the configuration] -ModuleSourcePath [module network address or local path] -UseWinRMSSL -Credential [User Credential]

Note: The -UseWinRMSSL and -Credential parameters are required for WinRM HTTPS connections, otherwise it will default to using WinRM HTTP.

Param(
    [System.Array]
    $ServerMachines,

    [System.String]
    $ModuleSourcePath,

    [Switch]
    $UseWinRMSSL,

    [Parameter(Mandatory=$False)]
    [System.Management.Automation.PSCredential]
    $Credential
)

$DSC_TARGET = "Program Files\WindowsPowerShell\Modules\ArcGIS"
if(Test-Path "$($env:SystemDrive)\$DSC_TARGET"){
    Remove-Item "$($env:SystemDrive)\$DSC_TARGET" -Force -ErrorAction Ignore -Recurse
}
Write-Host "Copying ArcGIS Module to Local Machine"
Copy-Item -Recurse -Path $ModuleSourcePath -Destination "$($env:SystemDrive)\$DSC_TARGET" -Force
Write-Host "Successfully Copied ArcGIS Module to Local Machine"

if($UseWinRMSSL){
    $s = New-PSSession $ServerMachines -UseSSL -Credential $Credential
}else{
    $s = New-PSSession $ServerMachines
}

Invoke-Command -Session $s -ScriptBlock { 
    $DscModulePath = "$($env:SystemDrive)\Program Files\WindowsPowerShell\Modules\ArcGIS"
    if(Test-Path $DscModulePath){
        Start-Job -Name "DeleteArcGISModule" -ScriptBlock {Remove-Item $args[0] -Force -Recurse} -ArgumentList $DscModulePath
        Wait-Job -Name "DeleteArcGISModule"
    }
}

workflow ParallelCopyArcGISDSCModule {
    param (
        [string[]]
        $ServerMachineNames, 
    
        [System.String]
        $ModuleSourcePath
    )
    foreach -parallel ($machineName in $ServerMachineNames) {
        InlineScript {
            if(-not($machineName -ieq $env:computername)){
                $RD = ((Get-WMIObject -class Win32_OperatingSystem -Computername $using:machineName).SystemDrive)
                $RemoteSystemDrive = $RD.trimend(":")
                $DSC_TARGET = "Program Files\WindowsPowerShell\Modules\ArcGIS"
                $ModulePath =  "$RD\$DSC_TARGET"
                Write-Host "Copying ArcGIS Module to $using:machineName"
                Copy-Item $using:ModuleSourcePath -Destination "\\$using:machineName\$RemoteSystemDrive$\$DSC_TARGET" -Recurse -Force
                Write-Host "Successfully Copied ArcGIS Module to $using:machineName"
            }
        }
    }
}

ParallelCopyArcGISDSCModule -ServerMachineNames $ServerMachines -ModuleSourcePath $ModuleSourcePath

Write-Host "Unblocking ArcGIS Module on $ServerMachines"
Invoke-Command -Session $s -Command {
    $DscModulePath = "$($env:SystemDrive)\Program Files\WindowsPowerShell\Modules\ArcGIS"
    if(Test-Path $DscModulePath){
        Start-Job -Name "UnblockArcGISModuleFiles" -ScriptBlock {Get-ChildItem -Path $args[0] -Recurse | Unblock-File} -ArgumentList $DscModulePath
        Wait-Job -Name "UnblockArcGISModuleFiles"
    }
}
Write-Host "Successfully Unblocked ArcGIS Module files on $ServerMachines"
Remove-PSSession $s