Kaseya Community

Powershell execution procedure issues

This question is not answered

Am trying to create a K procedure that will allow me to promtp the End user to select a drive letter and then take this drive and create a Windows File Share on it.

Thus allowing me to set a BURD Image location to \\localhost\Budr.  (This is mainly to deal with Roaming users for local backups)

When i Run this test procedure the results are

Test powershell Comman... 3:02:42 pm 7-Jul-11 Pending administrator
Execute Powershell Com... 3:02:53 pm 7-Jul-11 Success THEN administrator
Execute Powershell Com... 3:02:53 pm 7-Jul-11 Success THEN administrator
Execute Powershell Com... 3:02:53 pm 7-Jul-11 Success THEN administrator
Execute Powershell Com... 3:02:53 pm 7-Jul-11 Success ELSE administrator
Execute Powershell Com... 3:02:53 pm 7-Jul-11 Success THEN administrator
Execute Powershell Com... 3:02:53 pm 7-Jul-11 Success THEN administrator
Execute Powershell Com... 3:02:53 pm 7-Jul-11 Success THEN administrator
Execute Powershell Com... 3:02:53 pm 7-Jul-11 Success THEN administrator

The Agent gets the .ps1 file ok but the procedure seems to stop there and remains as Pending.

Checked the txt file that the powershell exports to but it is blank.

Don't know what i have missed.

Help please..Sorry if it is obvious (first steps into powershell)

 

 

Created a powershell script to promtp the user to select the drive letter.

$caption = "Please select the USB drive to backup too"
$message = "Select drive letter"
$choices = [System.Management.Automation.Host.ChoiceDescription[]] `
@("&C:", "&D:", "&E", "&F:", "&G:", "&H:", "&I:", "&J:", "&K:", "&L:", "&M:", "&N:", "&O:", "&P:", "&Q:", "&R:", "&S:", "&T:", "&U:", "&V:", "&W:", "&X:", "&Y:", "&Z:",)
[int]$defaultChoice = 2
$choiceRTN = $host.ui.PromptForChoice($caption,$message, $choices,$defaultChoice)
switch($choiceRTN)
{
 0    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'c:'"  }
 1    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'd:'"  }
 2    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'e:'"  }
 3    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'f:'"  }
 4    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'g:'"  }
 5    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'h:'"  }
 6    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'i:'"  }
 7    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'j:'"  }
 8    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'k:'"  }
 9    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'l:'"  }
 10    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'm:'"  }
 11    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'n:'"  }
 12    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'o:'"  }
 12    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'p:'"  }
 14    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'q:'"  }
 15    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'r:'"  }
 16    { Get-WmiObject -class Win32_Volume -filter "driveletter = 's:'"  }
 17    { Get-WmiObject -class Win32_Volume -filter "driveletter = 't:'"  }
 18    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'u:'"  }
 19    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'v:'"  }
 20    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'w:'"  }
 21    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'x:'"  }
 22    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'y:'"  }
 23    { Get-WmiObject -class Win32_Volume -filter "driveletter = 'z:'"  }
 }

 

 Then a Kaseya procedure to write the file to   #vAgentConfiguration.agentTempDir#\PromptForChoiceQueryDrive

Then execute the Powershell Command.

Followed by a "Create file Share":   #global:psresults#\Budr

 

 

All Replies
  • Firstly....does the PS script  work if you run the Powershell script outside of  Kaseya?

    I have always had issues using the Execute Powershell procedure option....rather I use the Execute Command procedure option and then call powershell.exe myscript.ps1

    Also, make sure your execution policy is set correctly...otherwise scripts wont run on your machines.

    I use this before my script...

    powershell.exe Set-ExecutionPolicy Bypass

    Then this after my Script

    powershell.exe Set-ExecutionPolicy RemoteSigned

    (this returns it to default)

    Hope this helps

    Josh

  • Josh, doesn't the command "set-executionpolicy" expect the user to interact to confirm?