Displaying PSComputerName in Workflow Script

Welcome Forums General PowerShell Q&A Displaying PSComputerName in Workflow Script

This topic contains 6 replies, has 4 voices, and was last updated by

 
Participant
2 years, 10 months ago.

  • Author
    Posts
  • #35104

    Participant
    Points: 0
    Rank: Member

    Hi,
    I run script on remote computers and this is what I get:

    ProductVersion FileVersion FileName PSComputerName
    ————– ———– ——– ————–
    1.16.03 1.16.03 C:\Program Files\DGT\Stanowisko Wsparcia\Awizo.exe localhost
    1.16.03 1.16.03 C:\Program Files\DGT\Stanowisko Wsparcia\Awizo.exe localhost
    1.16.03 1.16.03 C:\Program Files\DGT\Stanowisko Wsparcia\Awizo.exe localhost
    1.16.03 1.16.03 C:\Program Files\DGT\Stanowisko Wsparcia\Awizo.exe localhost
    1.16.03 1.16.03 C:\Program Files\DGT\Stanowisko Wsparcia\Awizo.exe localhost

    The script is working OK, I get the actual data from computers but why don't I get the proper ComputerName ?

    Here is my script:

    workflow foreachptest
    {
    	[string[]]$servers = Get-Content "C:\computers.txt"
    	$pass = cat C:\Pass.txt |ConvertTo-SecureString
    	$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "Administrator",$pass
    	
    	ForEach -Parallel($server in $servers)
    	{
    		InlineScript
    		{
    		   Invoke-Command -ComputerName $USING:server -Credential $USING:mycred -ScriptBlock {Get-Process Awizo -ErrorAction silentlycontinue -fileversioninfo}						 
    		}	
    	}
    }
    foreachptest
    
  • #35107

    Participant
    Points: 0
    Rank: Member

    What's in computers.txt file?

  • #35127

    Participant
    Points: 0
    Rank: Member

    txt file contains computers ip, like this:

    192.168.1.1
    192.168.1.2
    192.168.1.3

    It works ok in normal script, problem accur when I use Workflow.

  • #35129

    Participant
    Points: 0
    Rank: Member

    Because you are invoking the command remotely, the gwmi cmdlet is technically being run on the localhost, and is thus reporting so.

  • #35131

    Participant
    Points: 0
    Rank: Member

    Bob, your thinking makes sense but...

    When I do the same thing but not in workflow I get output with computers ip.

    Script

    	[string[]]$servers = Get-Content "C:\computers.txt"
    	$pass = cat C:\Pass.txt |ConvertTo-SecureString
    	$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "Admininistrator",$pass
    	
    	ForEach ($server in $servers)
    	{
    		Invoke-Command -ComputerName $server -Credential $mycred {Get-Process Awizo -ErrorAction silentlycontinue -fileversioninfo}				 
    	}
    

    ^^Above script give me:

    ProductVersion FileVersion FileName PSComputerName
    ————– ———– ——– ————–
    1.16.03 1.16.03 C:\Program Files\DG... 192.168.1.1
    1.16.03 1.16.03 C:\Program Files\DG... 192.168.1.2

  • #35137

    Participant
    Points: 0
    Rank: Member

    [Net.DNS]::GetHostEntry($Server)
    will take the ip address and get the hostname

  • #35139

    Participant
    Points: 5
    Rank: Member

    Przemek,

    Code within a PowerShell workflow is not run by PowerShell. When you define a workflow, PowerShell converts the code to XAML to be run in Windows Workflow.

    Do not expect anything to behave exactly the same in a Workflow as it does in PowerShell. Most things do, most of the time, but not everything, and not all of the time. Test everything.

The topic ‘Displaying PSComputerName in Workflow Script’ is closed to new replies.