Kaseya Community

Get Shares

  • Im running a simple WMI query to get shares, but im fighting with the procedure.... Really more than trying achieve what i need, im trying to understanding the proper method to run PS in this (legacy half-functioning - IMO) kaseya procedures.

    If i just run the command:
    (Get-WmiObject -Query "SELECT * FROM Win32_Share WHERE Type='0' and name != 'print$'" | Select-Object -ExpandProperty path) -join ' - ' 

    I get:

    Get-WmiObject : A positional parameter cannot be found that accepts argument '*'.At line:1 char:15 + (Get-WmiObject <<<< -Query SELECT * FROM Win32_Share WHERE Type='0' and name != 'print$' | Select-Object -ExpandProperty path) -join ' - ' + CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ParameterB indingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell 


    If i drop my commands into a PS1, send down the file, and run in, i get nothing. I get the ps1, but it isnt running, simply because i dont get the output. No proc errors

    GetShares.ps1
    (Get-WmiObject -Query "SELECT * FROM Win32_Share WHERE Type='0' and name != 'print$'" | Select-Object -ExpandProperty name) -join ' - ' >ShName.txt
    (Get-WmiObject -Query "SELECT * FROM Win32_Share WHERE Type='0' and name != 'print$'" | Select-Object -ExpandProperty path) -join ' - ' >ShPName.txt



    update
    [edited by: Joe at 5:12 PM (GMT -7) on Apr 17, 2019]
  • I suspect your first version isn't working because of the double quotes. Kaseya automatically passes your whole command within double quotes - when powershell tries to process this it can't work out which sets of double quotes go together and it ends up running a broken command. Really I think what Kaseya should be doing is passing the command surround by (brackets) instead of double quotes, but good luck getting them to change that.

    In my experience if you can write your powershell without needing double quotes you will have better success.

    In this case try something like: gwmi win32_Share | where {$_.Type -eq 0 -and $_.Name -ne 'print$'}

  • The other thing to note is the use of '>' in any script, you need to double them up '>>' or, when working with PoSh use " | Out-file -Path '#vAgentConfiguration.AgentTempDir#\whatever.txt' " or use the PoSh to variable and look at the output from it.



    Corrected spelling and highlighted command
    [edited by: PedroPolakoff3 at 5:54 AM (GMT -7) on Apr 18, 2019]
  • Thanks both... So i guess it comes down to avoiding quotes. Pedro, would i also need double greater-than's even im running a local PS1 file?

    In an (un)related question, whats the deal with running user based queries. Im looking to get network connections such as the query below as Powershell64BitUser, but it returns blank.

    Get-WmiObject win32_networkconnection | where {$_.RemoteName -notlike '*$' -and $_.Username -ne ''}



    corrected typos
    [edited by: Joe at 12:51 PM (GMT -7) on Apr 18, 2019]