简体   繁体   中英

AnyDesk CMD to PS1

Im trying to convert this to a.ps1 so i can run with intune, however cant seem to get it to work right.

Any ideas?

@echo off
cmd for /f "delims=" %%i in ('"C:\Program Files (x86)\AnyDeskMSI\AnyDeskMSI.exe" --get-id') do set ID=%%i 
echo AnyDesk ID is: %ID%
pause

The idea is it will put the ID, after that i can manipulate it no worries

As per my comment:

powershell /?

PowerShell[.exe] [-PSConsoleFile <file> | -Version <version>]
    [-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive]
    [-InputFormat {Text | XML}] [-OutputFormat {Text | XML}]
    [-WindowStyle <style>] [-EncodedCommand <Base64EncodedCommand>]
    [-ConfigurationName <string>]
    [-File <filePath> <args>] [-ExecutionPolicy <ExecutionPolicy>]
    [-Command { - | <script-block> [-args <arg-array>]
                  | <string> [<CommandParameters>] } ]


EXAMPLES
    PowerShell -PSConsoleFile SqlSnapIn.Psc1
    PowerShell -version 2.0 -NoLogo -InputFormat text -OutputFormat XML
    PowerShell -ConfigurationName AdminRoles
    PowerShell -Command {Get-EventLog -LogName security}
    PowerShell -Command "& {Get-EventLog -LogName security}"

It's the last two sample entries that you should target for your use case.

If you are to do this in a PowerShell Script, then you'd wrap that command in a Start-Process code block.

Get-Help -Name Start-Process -Examples

NAME
    Start-Process
    
SYNOPSIS
    Starts one or more processes on the local computer.
    
    
    ----- Example 1: Start a process that uses default values -----
    
    Start-Process -FilePath "sort.exe"
    
    
    ----------------- Example 2: Print a text file -----------------
    
    Start-Process -FilePath "myfile.txt" -WorkingDirectory "C:\PS-Test" -Verb Print
    
    
    ---- Example 3: Start a process to sort items to a new file ----
    
    $processOptions = @{
        FilePath = "sort.exe"
        RedirectStandardInput = "TestSort.txt"
        RedirectStandardOutput = "Sorted.txt"
        RedirectStandardError = "SortError.txt"
        UseNewEnvironment = $true
    }
    Start-Process @processOptions
    
    This example uses splatting to pass parameters to the cmdlet. For more information, see about_Splatting (../microsoft.powershell.core/about/about_splatting.md).
    ------- Example 4: Start a process in a maximized window -------
    
    Start-Process -FilePath "notepad" -Wait -WindowStyle Maximized
    
    
    ------- Example 5: Start PowerShell as an administrator -------
    
    Start-Process -FilePath "powershell" -Verb RunAs
    
    
    ----- Example 6: Using different verbs to start a process -----
    
    $startExe = New-Object System.Diagnostics.ProcessStartInfo -Args PowerShell.exe
    $startExe.verbs
    
    open
    runas
    runasuser
    
    The example uses `New-Object` to create a System.Diagnostics.ProcessStartInfo object for PowerShell.exe , the file that runs in the PowerShell process. The Verbs property of the 
    ProcessStartInfo object shows that you can use the Open and RunAs verbs with `PowerShell.exe`, or with any process that runs a `.exe` file.
    -------- Example 7: Specifying arguments to the process --------
    
    Start-Process -FilePath "$env:comspec" -ArgumentList "/c dir `"%systemdrive%\program files`""
    Start-Process -FilePath "$env:comspec" -ArgumentList "/c","dir","`"%systemdrive%\program files`""

For example, calling cmd.exe and getting it's process Id.

Start-Process 'C:\Windows\System32\cmd.exe' -PassThru
# Results
<#
Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
     18       5     1532       2536       0.00   7956   1 cmd 
#>

# Or
Start-Process 'C:\Windows\System32\cmd.exe' -PassThru | 
Select-Object -Property Id
# Results
<#
  Id
  --
2556
#>

# Or 

(Start-Process 'C:\Windows\System32\cmd.exe' -PassThru).Id
# Results
<#
8996
#>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM