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 (4 comments)

1
Avatar
Gavin Connolly

thanks for sharing Chris

0
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
Avatar
Phil Hurley

Does anyone have an example of assigning the “End-user” RBAC role to an Intune group for a host pool? I’m deploying the Nerdio Self-Service Portal across 100+ host pools and need to apply this in bulk. Thanks in advance!

0
Avatar
Kris Gillette

Example for restarting a session host

Import-Module NerdioManagerPowerShell
$subID = "df3fb09b-9030-411e-a2d3-5a7184ed77e7"
$rg = "TAM-AVD"
$hp = "KG-Multi"
$host = "KG-Multi-01.nerdiotams.com"
$extension = New-NmePowerStateCommandExtensions -Hibernation $false
$payload = New-NmePowerStateCommandPayload -Command Restart -Extensions $extension
$failurePolicy = New-NmeJobFailurePolicy -Restart $true -Cleanup $true
$request = New-NmePowerStateCommandRequest -JobPayload $payload -FailurePolicy $failurePolicy
Set-NmeSessionHostPowerState -SubscriptionId $subID -ResourceGroup $rg -HostPoolName $hp -Hostname $host -NmePowerStateCommandRequest $request 

Please sign in to leave a comment.