PowerShell Examples

Here are a couple examples of how to accomplish tasks with the Nerdio PowerShell module.

Running a scripted action on a VM:

$model = New-NmeRunCustomScriptOnVmRestModel -scriptedActionsIds 609 -activeDirectoryId 1 -restartVm $false

Start-NmeDesktopImageScript -subscriptionId $NmeQaManSub -resourceGroup $NmeQaManRG -name 'eqm-eus-test' -NmeRunCustomScriptOnVmRestModel $model

Running Set as Image with a scripted action:

$Config = New-NmeDesktopImageSetAsImageConfig -ChangeLog 'changed a thing' -PowerOnVm $true -ScriptedActionIds 142 -RestartOnFailure $true -CleanupOnFailure $true
Start-NmeDesktopImageSetAsImage -SubscriptionId $NmeQaManSub -ResourceGroup $NmeQaManRG -Name $DesktopImage -SetAsImageConfig $config

What other ways are you using the PS module? What examples would you like to see?

6

Comments (2 comments)

Avatar
Gavin Connolly

thanks for sharing Chris

1
Avatar
Kris Gillette
(Edited )

Here's an example of setting a host pool (KG-Test) to run scripted action group 1 when VMs are created: 

$onCreateOption = New-NmeScriptedActionOption -Type  "Group" -Id 1

$onCreateConfig = New-NmeHostPoolScriptedActionsConfigRestModel -Enabled $true -ScriptedActions $onCreateOption

$scriptedActions = New-NmeHostPoolScriptedActionsRestModel -OnCreate $onCreateConfig

$Watermarking = New-NmeWatermarkingProperties -Enabled $true -Scale 4 -Opacity 18 -WidthFactor 25 -HeightFactor 15

$hostPoolConfig = New-NmeHostPoolVmDeploymentRestModel `
  -IsAcceleratedNetworkingEnabled $true `
  -ForceVMRestart $false `
  -EnableTimezoneRedirection $true `
  -VmTimezone "Central Standard Time" `
  -InstallGPUDrivers $true `
  -UseAvailabilityZones $true `
  -IsShadowUsersEnabled $false `
  -EnableVmDeallocation $true `
  -InstallCertificates $false `
  -ScriptedActions $scriptedActions `
  -RdpShortpath "ForceEnable" `
  -AlwaysPromptForPassword $true `
  -SecurityType "None" `
  -SecureBootEnabled $true `
  -VTpmEnabled $false `
  -UseDedicatedHosts $false `
  -DedicatedHostGroupId $null `
  -DedicatedHostId $null `
  -EncryptionAtHost $false `
  -DiskEncryptionSetsIds $null `
  -BootDiagEnabled $false `
  -BootDiagStorageAccountsIds $null `
  -Watermarking $Watermarking `
    -RunAppPolicies $null

Update-NmeVmDeploymentConfig `
-SubscriptionId "e0b52e85-7caf-4260-a772-c0d82e56d407" `
    -ResourceGroup "Resource-Group-1" `
    -NmeHostPoolVmDeploymentRestModel $hostPoolConfig `
    -HostPoolName "KG-Test"
 
0

Please sign in to leave a comment.