0

I created a VM using Windows Server 2012 R2. Now trying to acquire the image name for the newest image of Windows Server 2012 R2 Datacenter using following `PS 5.0`` script. But it gives the following error:

PS script:

Get-AzureVMImage | where {$_.ImageFamily -eq "Windows Server 2012 R2
Datacenter" | sort PublishedDate -Descending } | select -Last 1 | Select
PublishedDate,ImageFamily,ImageName | FL

Error:

At line:3 char:14
+ PublishedDate,ImageFamily,ImageName | FL
+              ~
Missing argument in parameter list.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingArgument
Jason Ye
  • 2,399
  • 1
  • 8
  • 10
nam
  • 217
  • 1
  • 11
  • Double check line breaks in your syntax (those are generally allowed after a `|` pipe). Check also condition in `Where-Object` script block. I dare say that `| sort PublishedDate -Descending` should be moved out of `where {$_.ImageFamily -eq "Windows Server 2012 R2 Datacenter"}` – JosefZ Nov 19 '17 at 08:56

1 Answers1

0

Your script works for me, my powershell version is 4.4.1:

PS C:\Users\jason> Get-Module -ListAvailable -Name Azure -Refresh


    Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   4.4.1      Azure                               {Get-AzureAutomationCertificate, Get-AzureAutomationConnection, New-AzureAutomationConnection, Remove-AzureAutomationConnection...}

Here is the output of that script:

PS C:\Users\jason> Get-AzureVMImage | where { $_.imagefamily -eq "Windows Server 2012 R2 Datacenter" } | sort Publicsheddate -Descending | select -Last 1 | select PublishedDate,ImageFamily,ImageName | fl


PublishedDate : 5/10/2017 3:00:00 PM
ImageFamily   : Windows Server 2012 R2 Datacenter
ImageName     : a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-20170510-en.us-127GB.vhd

Please check your Azure PowerShell version and test that script again.

We can find Azure PowerShell version information here.

Hope this helps:)

Jason Ye
  • 2,399
  • 1
  • 8
  • 10