Displaying PSComputerName in Workflow Script

This topic contains 6 replies, has 4 voices, and was last updated by Profile photo of Tim Curwick Tim Curwick 7 months, 2 weeks ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #35104
    Profile photo of Przemek Kozak
    Przemek Kozak
    Participant

    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
    Profile photo of Wilfredo Perez
    Wilfredo Perez
    Participant

    What's in computers.txt file?

    #35127
    Profile photo of Przemek Kozak
    Przemek Kozak
    Participant

    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
    Profile photo of Bob McCoy
    Bob McCoy
    Participant

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

    #35131
    Profile photo of Przemek Kozak
    Przemek Kozak
    Participant

    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
    Profile photo of Wilfredo Perez
    Wilfredo Perez
    Participant

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

    #35139
    Profile photo of Tim Curwick
    Tim Curwick
    Participant

    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.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.