Get-Childitem -Include *HSG* -File -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -ge $FindDate }
Get-ChildItem -Filter *.log -Recurse | Select-String "Contoso"
Remove-Item $folderPath -Force -Recurse -ErrorAction SilentlyContinue
gci Env:* | sort name
$Env:AWS_REGION='eu-central-1'
[xml]$doc = Get-Content c:\temp\mystuff.nuspec -Encoding UTF8
$id = $doc.package.metadata.id
$el = $doc.CreateElement('releaseNotes', $doc.package.metadata.NamespaceURI)
$el.InnerText = 'Fixed some bugs.'
$doc.package.metadata.AppendChild($el) | Out-Null # Pipe to null to avoid dumping large output to console
$defaultNamespace = $doc.DocumentElement.NamespaceURI
[System.Xml.XmlNamespaceManager] $nsMgr = New-Object -TypeName System.Xml.XmlNamespaceManager -ArgumentList $xmlDoc.NameTable
$nsMgr.AddNamespace("ns", "http://schemas.microsoft.com/developer/msbuild/2003");
$rpNodes = $xmlDoc.SelectNodes("/ns:Project/ns:PropertyGroup/ns:RestorePackages", $nsMgr);
Import-Module .\MyModule.psm1
# use the module..., then:
Remove-Module MyModule
Given this function, saved in Get-CountX.ps1
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[System.IO.FileInfo]$Path
)
begin {
Write-Host 'Begin'
$prefix = '-felix-'
}
process {
Write-Host "$prefix $($Path.FullName.Length)"
}
end {
Write-Host 'End'
}
...you can run this:
Get-ChildItem | .\Get-CountX.ps1
...and get a result like this:
Begin
-felix- 27
-felix- 37
-felix- 42
End
Or you can run this:
.\Get-CountX.ps1 -Path c:\temp\goofy.txt
...and get a result like this:
Begin
-felix- 17
End