Difference between revisions of "Powershell"
From Richard's Wiki
(→Powershell V2) |
(→Powershell V2) |
||
| Line 51: | Line 51: | ||
===== Powershell V2 ===== | ===== Powershell V2 ===== | ||
| − | * [http://support.microsoft.com/kb/968929 Microsoft | + | * [http://support.microsoft.com/kb/968929 Microsoft PowerShell 2.0 download page] |
* [http://www.johndcook.com/blog/2009/11/02/powershell-2-0-for-windows-xp-etc/ PowerShell 2.0 for Windows XP etc.] | * [http://www.johndcook.com/blog/2009/11/02/powershell-2-0-for-windows-xp-etc/ PowerShell 2.0 for Windows XP etc.] | ||
* [http://www.microsoft.com/downloads/details.aspx?FamilyId=60cb5b6c-6532-45e0-ab0f-a94ae9ababf5 PowerShell 2.0 for Windows XP Download] | * [http://www.microsoft.com/downloads/details.aspx?FamilyId=60cb5b6c-6532-45e0-ab0f-a94ae9ababf5 PowerShell 2.0 for Windows XP Download] | ||
* [http://technet.microsoft.com/en-us/magazine/2009.08.windowspowershell.aspx Running remote commands in Powershell V2] | * [http://technet.microsoft.com/en-us/magazine/2009.08.windowspowershell.aspx Running remote commands in Powershell V2] | ||
Revision as of 17:41, 19 January 2010
Contents
GUI IDE
A useful Powershell GUI IDE (with debugger) is available at http://powergui.org/
Recursive delete of files
get-childitem . -include *scc,bin,obj -recurse | foreach ($_) {remove-item -recurse -force $_.fullname}
Periodically poll a website and log response times
$url="http://xml.weather.yahoo.com/forecastrss?p=10036" $web = new-object system.net.webclient $datetime = new-object system.datetime $log = "log.txt" while (1) { $start = [DateTime]::Now $zz = $web.DownloadString($url) $end = [DateTime]::Now $duration = $end - $start "" + [DateTime]::Now + ": Duration " + $duration >> $log sleep 60 }
Open Enterprise Architect Repository
$rep = new-object -COM EA.Repository
$rep.OpenFile("C:\eATEST.eap")
Parse Enterprise Architect XML Files in a directory
## An example script that will look at all the xml files
## in the specified directory, assume they are valid
## Enterprise Architect export files, and try to list
## the names of all the packages in each file
param(
$folderPath = $(throw 'folderPath must be supplied')
)
$xmlFiles = (resolve-path "$folderPath\*.xml")
foreach ($xmlFile in $xmlFiles) {
$xmlFile = $xmlFile.Path
$xmlDoc = new-object system.xml.xmldocument
$xmlDoc.Load($xmlFile);
$nsMgr = New-Object system.xml.XmlNamespaceManager $xmlDoc.get_NameTable()
$nsmgr.AddNamespace("UML", "omg.org/UML1.3")
if ($xmlDoc.XMI) {
$packages = $xmlDoc.XMI.SelectNodes("//UML:Package", $nsMgr)
if ($packages.Count -gt 0) {
Write-Host $xmlFile ":"
foreach ($package in $packages) {
Write-Host $package.name
}
}
}
}