In PowerShell the most common method of storing data is to store it in an ‘Array’.Arrays can be initialized using a simple syntax: Array
#Initialize the array
$myarray = @()
#add an integer to the array
$myarray = $myarray + 1
#add a string
$myarray = $myarray + 'Hello World'
#add a datetime object
$myarray = $myarray + (Get-Date)
as you can see we can store just about any type of data in an array which can be good and bad. This can lead to errors in situations where […]
Create an Inventory of the Local Computer Getting Computer Services
[sourcecode language='powershell' ]
#Define the ComputerName
$computer = 'Localhost'
#Define the Excel fillename and the worksheetname
$Filename = 'Localhost-Inventory.xlsx'
$WorkSheetName = 'Services'
#Create a New Document held in computer memory
$Doc = New-SLDocument
#Generate the Service Information
Get-Service -ComputerName $computer |
Export-SLData -WorkBookInstance $doc -WorksheetName $WorkSheetName |
Set-SLTableStyle -TableStyle Medium15 -Verbose |
Save-SLDocument -Path (Join-Path 'c:\temp\excel' -ChildPath $Filename) -Verbose
The Output should look like this PS C:\> VERBOSE: Select-SLWorkSheet : Worksheet ‘Services’ is now selected VERBOSE: Set-SLTableStyle : Setting TableStyle ‘Medium15′ on CellRange – StartRow/StartColumn ‘5’:’2′ & EndRow/EndColumn ‘184’:’16’ VERBOSE: Save-SLDocument : Document has been Saved to ‘c:\temp\excel\Localhost-Inventory.xlsx’ Check […]
CMDLET Name : Get-Help What it does: Displays information about how to use a particular cmdlet or function. Most people when they start out with PowerShell are not aware of the extensive help that PowerShell ships with and as such may perceive PowerShell to be a difficult language. In reality the truth couldn’t be any […]
In the last article we learnt how to extend a Type with Update-TypeData today we will learn how to get the output to look just the way we want using Update-FormatData CMDLET Name : Update-FormatData What it does: This cmdlet lets you update the formatting data without restarting Windows PowerShell. When you run Get-Service without […]
CMDLET Name : Update-TypeData What it does: Let’s you add new properties, modify existing properties, add new methods, define a key property to sort databy, define exactly what properties you want to see when the cmdlet is typed without any select statements. Every object in PowerShell has a Type associated with it that defines the object. […]
In Part –1 we learnt how to obtain and install the ‘WMIX’ module. In this part we will spend some time using some of the functions from the module. Get-ComputerSystem PS C:\> Get-ComputerSystem Domain : WORKGROUP Manufacturer : VMware, Inc. Model : VMware Virtual Platform Name : VM1 PrimaryOwnerName : Kiran TotalPhysicalMemory […]