Share via

How powershell 7 64 bits single script instance

Moisey Oysgelt 1 Reputation point
Dec 31, 2021, 12:37 AM

Using PowerShell 5.1 i use function Function Test-IfAlreadyRunning
This function has 32-bit calls

Result is

get-wmiobject: C:\Program Files\PowerShell\7\profile.ps1:181
Line |
181 | $PsScriptsRunning = get-wmiobject win32_process | where { $_.proc …
| ~~~~~~~~~~~~~
| The term 'get-wmiobject' is not recognized as a name of a cmdlet, function, script file, or executable
| program. Check the spelling of the name, or if a path was included, verify that the path is correct

| and try again.

Is there a library or method with can check if my script instance is running already

Thank you

Moisey O

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,628 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Andreas Baumgarten 119.5K Reputation points MVP
    Dec 31, 2021, 1:00 AM

    Hi @Moisey Oysgelt ,

    Get-WmiObject isn't available in PowerShell 7. But you can try Get-CimInstance instead.

    PowerShell 5.x: Get-WmiObject win32_process
    PowerShell 7.x: Get-CimInstance -ClassName Win32_Process

    https://learn.microsoft.com/en-us/powershell/module/cimcmdlets/get-ciminstance?view=powershell-7.2

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.
    0 comments No comments

  2. Limitless Technology 39,846 Reputation points
    Jan 4, 2022, 10:05 AM

    Hello MoiseyOysgelt

    get-wmiobject is deprecated, and instead you should use Get-CIMInstance: https://learn.microsoft.com/en-us/powershell/module/cimcmdlets/get-ciminstance?view=powershell-7.2#syntax

    More details: https://learn.microsoft.com/en-us/powershell/scripting/learn/ps101/07-working-with-wmi?view=powershell-7.2

    -----------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.