How

Avoid truncated property, add "–ExpandProperty" before the property you want to expand. E.g.,

Find-PackageProvider | Select –ExpandProperty Name

Get PowerShell version information

$PSVersionTable

Get installed modules

Get-InstalledModule

Update all installed modules

Update-Module

Get a installed module information

Get-Module <module name> -ListAvailable

Get commands in a module

Get-Command -Module <module name>

Path Manipulation

Join paths

$SourceFolder = "\\tsclient\U\Projects\PON\Data"
$SourceFile = "MTO data.txt"

$SourcePath = Join-Path $SourceFolder $SourceFile

Files Manipulation

PowerShell Data Basics: File-Based Data

General

Test if file exists

$strFileName="c:\filename.txt"
If (Test-Path $strFileName){
  # // File exists
}Else{
  # // File does not exist
}

UNC Folders/Files

Access File/Folder with UNC

 $SourcePath = "FileSystem::\\ent\prp\Userdata3\N1140\Projects\PON\Data\MTO data.txt"

if (Test-Path $SourcePath) {
    "$SourcePath exists"
} else {
    "$SourcePath not exists"
}

Text Files

CSV Files

Export CSV Files

PS C:\> Get-Process | Export-Csv Processes.csv

Import CSV Files

PS C:\> Get-Process | Export-Csv Processes.csv
PS C:\> $P = Import-Csv Processes.csv

Fixed-Length Text Files

Get-Content .\fixedwidth.log | #read each line as a separate object
   select -Property @{name='ID';expression={$_.Substring(17).Trim()}}, #first column
                    @{name='FirstName';expression={$_.Substring(0,7).Trim()}}, #2nd 
                    @{name='LastName';expression={$_.Substring(7,10).Trim()}} #3rd
Use PowerShell to Read Fixed-Length Text Files

The script uses VB.Net 'My' Namespace and its TextFieldParser class to read a fixed-length text file.

$Parser = New-Object Microsoft.VisualBasic.FileIO.TextFieldParser( 
    'C:\Scripts\FixedLength.txt') 

$Parser.TextFieldType = 'FixedWidth' 
$Parser.TrimWhiteSpace = $True 
$Parser.FieldWidths = @(7, 10, 3) 

while(!$Parser.EndOfData) 
{ 
    try 
    { 
        Write-Host $Parser.ReadFields() 
    } 
    catch [Microsoft.VisualBasic.FileIO.MalformedLineException] 
    { 
        Write-Host "Error, line $($_.Exception.LineNumber): $($Parser.ErrorLine)" 
    } 
}
How Can I Import a Fixed-Width Data File into Microsoft Excel?

The script uses Microsoft Excel object to read a fixed-length text file.

Const xlFixedWidth = 2
Const xlTextFormat = 2

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

objExcel.Workbooks.OpenText "C:\Scripts\Test.txt",,3,xlFixedWidth,,,,,,,,, _
    Array(Array(0, xlTextFormat),Array(51, xlTextFormat),Array(102, xlTextFormat))
How to Import a Powershell Module from a Remote Computer

http://supersysadmin.com/91/how-to-import-a-powershell-module-from-a-remote-computer/

IIS

How to get IIS version
get-itemproperty HKLM:\SOFTWARE\Microsoft\InetStp\  | select setupstring,versionstring

results matching ""

    No results matching ""