Help me to better understand powershell code/snippet.
hello,
could me better understand following highlighted in provided code snippet,
1) code there variable ' $htmlheader = @" ' what means ?
2) variable ' $servicesreport = @() ' means ?
3)and below statement ?
$row = new-object -type psobject -property @{ .... }
appreciate if suggest books advanced powershell programming.
code:
$htmlheader = @" <!doctype html public "-//w3c//dtd html 4.01 frameset//en" "http://www.w3.org/tr/html4/frameset.dtd"> <html><head><title>my systems report</title> <style type="text/css"> <!-- body { font-family: verdana, geneva, arial, helvetica, sans-serif; } #report { width: 835px; } table{ border-collapse: collapse; border: none; font: 10pt verdana, geneva, arial, helvetica, sans-serif; color: black; margin-bottom: 10px; } </style> </head> <body> "@ $servicesreport = @() $services = get-wmiobject -class win32_service -computername $computer | {($_.startmode -eq "auto") -and ($_.state -eq "stopped")} foreach ($service in $services) { $row = new-object -type psobject -property @{ name = $service.name status = $service.state startmode = $service.startmode } $servicesreport += $row }
thanks
1) code there variable ' $htmlheader = @" ' what means ?
the @" "@ convenient way of defining long string constant on many lines.
2) variable ' $servicesreport = @() ' means ?
@() defining new empty array.
the += operator in " $servicereport += $row " adding new element array.
3)and below statement ?
$row = new-object -type psobject -property @{ .... }
creating powershell object, properties , values defined in hashtable
@{} defines hashtable,
powershell objects different traditional objects in properties of object defined / constructed @ run-time vs other objects / classes defined @ compile time.
to learn powershell check out courses @ microsoft virtual academy.
getting started powershell 3.0 jump starthttp://www.microsoftvirtualacademy.com/training-courses/getting-started-with-powershell-3-0-jump-start
advanced tools & scripting powershell 3.0 jump start
http://www.microsoftvirtualacademy.com/training-courses/advanced-tools-scripting-with-powershell-3-0-jump-start
Windows Server > Windows PowerShell
Comments
Post a Comment