PowerShell script exchange
Post Reply
g0nzo
Influencer
Posts: 12
Liked: 2 times
Joined: Nov 09, 2019 4:28 pm
Contact:

PS report to CSV not working

Post by g0nzo »

Hello,

I run this on a Veeam 11 backup server just fine, but when I run it on another Veeam 11 we have I get an error, what am I doing wrong?

Code: Select all

using namespace System.Collections.Generic
$jobs = Get-VBRJob
$LastDay =  [List[Object]]@()
foreach($j in $jobs){
     $sess = $j.FindLastSession()
     $objects = Get-VBRJobObject -Job $j
     $JobLastRunDeets = [PSCustomObject]@{
          Name = $j.Name
          Type = $j.JobType
          StartTime = $sess.CreationTime
          Result = $sess.Result
          TargetRepo = $j.GetTargetRepository().Name
          BackupSize = $sess.BackupStats.BackupSize/1024/1024/1024
          Description = $j.Description
          }
     $LastDay.Add($JobLastRunDeets)
}

$LastDay | Export-Csv C:\temp\jobinfo.csv -NoTypeInformation -UseCulture
Error

Code: Select all

using : The term 'using' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.
At line:2 char:1
+ using namespace System.Collections.Generic
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (using:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Unable to find type [List].
At line:4 char:14
+ $LastDay =  [List[Object]]@()
What am I doing wrong here?
chris.childerhose
Veeam Vanguard
Posts: 636
Liked: 154 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

Re: PS report to CSV not working

Post by chris.childerhose »

I ran this on my VBR server in my homelab without issue. Are the versions of PS the same on each of the servers? Is the Veeam version the same on each of the servers? Something to check.
-----------------------
Chris Childerhose
Veeam Vanguard / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: PS report to CSV not working

Post by oleg.feoktistov » 1 person likes this post

@g0nzo, incorporating using statement in a ps script natively requires Powershell v5.0+. Please make sure that you have it installed on the server, where you encountered this error. Thanks!
g0nzo
Influencer
Posts: 12
Liked: 2 times
Joined: Nov 09, 2019 4:28 pm
Contact:

Re: PS report to CSV not working

Post by g0nzo » 1 person likes this post

Good question guys, I didn't think of that, I'll check this.
g0nzo
Influencer
Posts: 12
Liked: 2 times
Joined: Nov 09, 2019 4:28 pm
Contact:

Re: PS report to CSV not working

Post by g0nzo »

Hmm both servers are on the same PS version:

PS C:\Windows\system32> $PSversionTable

Name Value
---- -----
PSVersion 5.1.17763.2803
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.2803
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: PS report to CSV not working

Post by oleg.feoktistov »

Do class and enum statements work on the server, where using is not recognized?
For example:

Code: Select all

class Test {}

enum TestEnum {
 test1
 test2
}
g0nzo
Influencer
Posts: 12
Liked: 2 times
Joined: Nov 09, 2019 4:28 pm
Contact:

Re: PS report to CSV not working

Post by g0nzo »

I'm not sure if I did that right, but I simply copied you code and ran it on both and nothing happens when I execute it.
AlexHeylin
Veteran
Posts: 563
Liked: 173 times
Joined: Nov 15, 2019 4:09 pm
Full Name: Alex Heylin
Contact:

Re: PS report to CSV not working

Post by AlexHeylin »

oleg.feoktistov wrote: May 10, 2022 3:04 pm @g0nzo, incorporating using statement in a ps script natively requires Powershell v5.0+. Please make sure that you have it installed on the server, where you encountered this error. Thanks!
I've seen similar weird behaviour before from PoSh where it's been upgraded by installing a WMF upgrade. It makes PoSh report the version number of the upgraded version but some (all?) of the newer commands don't exist. It's a right PITA, because if you just check the PoSh version in the script the commands will throw exceptions and whatever you do the script won't work. I never found a solution other than to handle the exceptions gracefully, report the likely cause, and exit with error.

Did one of the servers start life with an older PoSh and then get upgraded to run the same PoSh version as the other server?
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests