├── BackupIPConfig.ps1 ├── ChangeFileTimes.ps1 ├── Checksum.ps1 ├── DotNetFunctions.txt ├── ExcelTest.ps1 ├── ExportXLS.ps1 ├── GetServices.ps1 ├── HelloWorld.ps1 ├── HexDump.ps1 ├── History2Script.ps1 ├── Image2ASCII.ps1 ├── ModifyIP.ps1 ├── MoveTemplate.ps1 ├── MultiThread.ps1 ├── NetTraffic.ps1 ├── NetworkSettings.ps1 ├── Notify.ps1 ├── Packet.ps1 ├── Pass2Hash.ps1 ├── Pipeline.ps1 ├── PlayMedia.ps1 ├── PortScan.ps1 ├── Processing.ps1 ├── ProgressBar.ps1 ├── Prompt4Choice.ps1 ├── Registry.ps1 ├── Resolve.ps1 ├── SendMail.ps1 ├── SetCursorPosition.ps1 ├── Sniffer.ps1 ├── StoreEMailCredentials.ps1 ├── StoreVMwareCredentials.ps1 ├── TcpClient.ps1 ├── Text2Speech.ps1 ├── Threading.ps1 ├── UdpChat.ps1 ├── UdpClient.ps1 ├── UdpServer.ps1 ├── getConfigFromINI.bat ├── getConfigFromINI.ps1 ├── nobugs.ico ├── ps-typeshortcuts.txt ├── sh2ps.txt ├── xxFunctions.ps1 ├── yyFilters.ps1 └── zzFunctions.ps1 /BackupIPConfig.ps1: -------------------------------------------------------------------------------- 1 | ########################################################################################################### 2 | # # 3 | # File: BackupIPConfig.ps1 # 4 | # # 5 | # Purpose: Script for managing ip configuration on remote hosts via wmi # 6 | # - read configuration from system and export to a csv or xml file # 7 | # - import from a csv or xml file and write configuration to system # 8 | # # 9 | # Author: Sven Sperner # 10 | # # 11 | # Last edited: 31.05.2012 # 12 | # # 13 | # Requirements: Microsoft Windows PowerShell 2.0 + enabled WMI on remote host # 14 | # # 15 | # Usage: # 16 | # PowerShell -command C:\{Path2Script}\BackupIPConfig.ps1 # 17 | # # 18 | # Parameter: # 19 | # -command {read|write} read & export OR import & write # 20 | # -hosts {|} comma separated list or a file with a host in each line # 21 | # -backupFile filename to save the settings in, without file extension # 22 | # -fileType {csv|xml} file type and extension for backupFile # 23 | # # 24 | # Usage examples: # 25 | # PowerShell -command ".\BackupIPConfig.ps1 read -hosts hostList.txt -backupFile Saved2012 -fileType csv"# 26 | # --> read hosts from hostList.txt and save settings to Saved2012.csv # 27 | # PowerShell -command ".\BackupIPConfig.ps1 read -hosts serverXY,horst0815,reschna007 -fileType xml" # 28 | # --> read settings from the three hosts and save to .xml (IPConfigList.xml) # 29 | # PowerShell -command ".\BackupIPConfig.ps1 write -backupFile Saved2012" # 30 | # --> import from "Saved2012.csv" (csv is std) and write to every host where settings are present for # 31 | # # 32 | # This program is distributed in the hope that it will be useful, # 33 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # 34 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # 35 | # # 36 | ########################################################################################################### 37 | 38 | PARAM( $command="read", 39 | $hosts="localhost", 40 | $backupFile="IPConfigList", 41 | $fileType="csv", 42 | [Switch]$help ) 43 | 44 | 45 | If( ($help) -OR (($fileType -ne "csv") -AND ($fileType -ne "xml")) ) 46 | { 47 | Write-Host "usage: $($MyInvocation.MYCommand) [-help]" 48 | exit 49 | } 50 | 51 | 52 | # Resolve hostname <=> ip address 53 | Function resolve( [String]$machine="localhost" ) 54 | { 55 | [System.Net.IPAddress]$IPobj = $null 56 | If( [System.Net.IPAddress]::tryparse($machine,[ref]$IPobj) -and $machine -eq $IPobj.tostring() ) 57 | { 58 | $serv,$null,$null,$name,$null = nslookup $machine 2>$null 59 | $name = $name -replace "Name:\s+","" 60 | return $name 61 | } 62 | Else 63 | { 64 | $null,$serv,$null,$null,$ipadr = nslookup $machine 2>$null 65 | $ipadr = $ipadr -replace "Address:\s+","" 66 | return $ipadr 67 | } 68 | } 69 | 70 | 71 | 72 | # Read ip configuration from host ... 73 | If( $command -eq "read" ) 74 | { 75 | If( Test-Path $hosts 2>&1 >$null ) 76 | { $hosts = Get-Content $hosts } 77 | 78 | $confList = @() 79 | ForEach( $hostname in $hosts ) 80 | { 81 | If( $hostname -eq "localhost" ) 82 | { $hostname = $(hostname) } 83 | Write-Host "Getting ip configuration of $hostname" 84 | 85 | $netAdapters = Get-wmiobject -cl "Win32_NetworkAdapter" -comp $hostname -filter ` 86 | "AdapterType = 'Ethernet 802.3' AND NetConnectionStatus = 2" #> 0" 87 | ForEach( $adapter in $netAdapters ) 88 | { 89 | $adpConf = @($adapter.GetRelated('Win32_NetworkAdapterConfiguration'))[0] 90 | If( ($adpConf.IPEnabled) -and ($adpConf.IPAddress -ne "0.0.0.0") ) 91 | { 92 | $confRow = "" | Select Hostname,Resolved,ConfType,AdpId,IPAddress,SubnetMask,Gateway,` 93 | Domain,DNS1,DNS2,DHCP,WINS1,WINS2 94 | $confRow.Hostname = $hostname 95 | [System.Net.IPAddress]$IPobj = $null 96 | If( [System.Net.IPAddress]::tryparse($hostname,[ref]$IPobj) -and $hostname -eq $IPobj.tostring() ) 97 | { $confRow.Resolved = [String]$(resolve("$hostname")) } 98 | Else 99 | { $confRow.Resolved = [String]$(resolve("$hostname.$($adpConf.DNSDomain)")) } 100 | If( $adpConf.DHCPEnabled ) 101 | { $confRow.ConfType = "dynamic" } 102 | Else 103 | { $confRow.ConfType = "static" } 104 | $confRow.AdpId = [String]$adapter.DeviceId 105 | $confRow.IPAddress = [String]$adpConf.IPAddress 106 | $confRow.SubnetMask = [String]$adpConf.IPSubnet 107 | $confRow.Gateway = [String]$adpConf.DefaultIPGateway 108 | $confRow.Domain = [String]$adpConf.DNSDomain 109 | If( $adpConf.DNSServerSearchOrder[0] ) 110 | { $confRow.DNS1 = [String]$adpConf.DNSServerSearchOrder[0] } 111 | Else 112 | { $confRow.DNS1 = [String]$adpConf.DNSServerSearchOrder } 113 | If( $adpConf.DNSServerSearchOrder[1] ) 114 | { $confRow.DNS2 = [String]$adpConf.DNSServerSearchOrder[1] } 115 | Else 116 | { $confRow.DNS2 = "" } 117 | $confRow.DHCP = [String]$adpConf.DHCPServer 118 | $confRow.WINS1 = [String]$adpConf.WINSPrimaryServer 119 | $confRow.WINS2 = [String]$adpConf.WINSSecondaryServer 120 | $confList += $confRow 121 | } 122 | } 123 | } 124 | # ... and export to csv file 125 | If( $confList.Length -gt 0 ) 126 | { 127 | try{ 128 | If( $fileType -eq "csv" ) 129 | { $confList | Export-Csv "$backupFile.$fileType" -noTypeInformation -Delimiter ";" } 130 | ElseIf( $fileType -eq "xml" ) 131 | { $confList | Export-Clixml "$backupFile.$fileType" } 132 | Write-Host "IP Configuration List exported to $backupFile.$fileType" 133 | } 134 | catch{ 135 | Write-Error "$_`nCannot write to file $backupFile.$fileType" 136 | exit -1 137 | } 138 | } 139 | } 140 | # Import from csv file ... 141 | ElseIf( $command -eq "write" ) 142 | { 143 | try{ 144 | If( $fileType -eq "csv" ) 145 | { $confList = Import-Csv "$backupFile.$fileType" -Delimiter ";" } 146 | ElseIf( $fileType -eq "xml" ) 147 | { $confList = Import-Clixml "$backupFile.$fileType" } 148 | Write-Host "IP Configuration List imported from $backupFile.$fileType" 149 | } 150 | catch{ 151 | Write-Error "$_`nCannot read from file $backupFile.$fileType" 152 | exit -1 153 | } 154 | # ... and write configuration to host 155 | ForEach( $confRow in $confList ) 156 | { 157 | Write-Host "Setting ip configuration of $($confRow.Hostname)" 158 | 159 | $netAdapters = Get-wmiobject -cl "Win32_NetworkAdapter" -comp $confRow.Hostname -filter ` 160 | "AdapterType = 'Ethernet 802.3' AND NetConnectionStatus = 2" #> 0" 161 | ForEach( $adapter in $netAdapters ) 162 | { 163 | If( $adapter.DeviceId -eq $confRow.AdpId ) 164 | { 165 | $adpConf = @($adapter.GetRelated('Win32_NetworkAdapterConfiguration'))[0] 166 | If( $confRow.ConfType -eq "static" ) 167 | { 168 | try{ $adpConf.EnableStatic( $confRow.IPAddress, $confRow.SubnetMask ) > $null } 169 | catch{ Write-Host "Could not write IP Address + Subnet Mask for $($confRow.Hostname)" } 170 | try{ $adpConf.SetGateways( $confRow.Gateway ) > $null } 171 | catch{ Write-Host "Could not write standard Gateway for $($confRow.Hostname)" } 172 | try{ $adpConf.SetDNSDomain( $confRow.Domain ) > $null } 173 | catch{ Write-Host "Could not write DNS Domain for $($confRow.Hostname)" } 174 | try{ $adpConf.SetDNSServerSearchOrder( ($confRow.DNS1,$confRow.DNS2) ) > $null } 175 | catch{ Write-Host "Could not write DNS Server(s) for $($confRow.Hostname)" } 176 | try{ $adpConf.SetWINSServer( $confRow.WINS1, $confRow.WINS2 ) > $null } 177 | catch{ Write-Host "Could not write WINS Server(s) for $($confRow.Hostname)" } 178 | } 179 | ElseIf( $confRow.ConfType -eq "dynamic" ) 180 | { 181 | try{ $adpConf.SetWINSServer( $confRow.WINS1, $confRow.WINS2 ) > $null } 182 | catch{ Write-Host "Could not write WINS Server(s) for $($confRow.Hostname)" } 183 | try{ $adpConf.EnableDHCP( ) > $null } 184 | catch{ Write-Host "Could not enable DHCP for $($confRow.Hostname)" } 185 | try{ $adpConf.SetDNSServerSearchOrder( ) > $null } 186 | catch{ Write-Host "Could not write DNS Server(s) for $($confRow.Hostname)" } 187 | } 188 | Else 189 | { 190 | Write-Host "$($confRow.Hostname) is configured $($confRow.ConfType)" 191 | } 192 | } 193 | } 194 | } 195 | } 196 | Else 197 | { 198 | Write-Error "unknown command: $command" 199 | exit -1 200 | } 201 | 202 | -------------------------------------------------------------------------------- /ChangeFileTimes.ps1: -------------------------------------------------------------------------------- 1 | # Change the 'LastWriteTime' attribute of file or folder # if( $($args.count) -lt 2 ) # no parameter given, print usage: { Write-Host "usage: $($MyInvocation.MYCommand) <'01/01/1900 0:00 AM'>" Write-Host " or: $($MyInvocation.MYCommand) <01/01/1900>" Write-Host " or: $($MyInvocation.MYCommand) <0:00>" exit -1 } if( $(Test-Path $args[0]) ) { $item = Get-Item $args[0] } else { Write-Host "File or Folder $($args[0]) not present" exit -1 } if( $(Get-Date $args[1]) ) { $item.CreationTime = Get-Date $args[1] $item.LastWriteTime = Get-Date $args[1] $item.LastAccessTime = Get-Date $args[1] } else { Write-Host "$($args[1]) is not a valid date and/or time" exit -1 } $item -------------------------------------------------------------------------------- /Checksum.ps1: -------------------------------------------------------------------------------- 1 | # Simple checksum calculator 2 | # 3 | # available algorithms ($algo): md5, sha1, sha256, sha512 4 | # 5 | 6 | param( $file, $algo="MD5" ) 7 | 8 | $algo = [System.Security.Cryptography.HashAlgorithm]::Create( $algo ) 9 | $stream = New-Object System.IO.FileStream( $file, [System.IO.FileMode]::Open ) 10 | 11 | $stringBuilder = New-Object System.Text.StringBuilder 12 | $algo.ComputeHash($stream) | % { [void] $stringBuilder.Append($_.ToString("x2")) } 13 | $stringBuilder.ToString() 14 | 15 | $stream.Dispose() 16 | -------------------------------------------------------------------------------- /DotNetFunctions.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sperner/PowerShell/8c661ec4d0914b02095ffabb7c9dcbd8b1f0185a/DotNetFunctions.txt -------------------------------------------------------------------------------- /ExcelTest.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sperner/PowerShell/8c661ec4d0914b02095ffabb7c9dcbd8b1f0185a/ExcelTest.ps1 -------------------------------------------------------------------------------- /ExportXLS.ps1: -------------------------------------------------------------------------------- 1 | function Export-Xls 2 | { 3 | param( 4 | [parameter(ValueFromPipeline = $true,Position=1)] 5 | [ValidateNotNullOrEmpty()] 6 | $InputObject, 7 | [parameter(Position=2)] 8 | [ValidateNotNullOrEmpty()] 9 | [string]$Path, 10 | [string]$WorksheetName = ("Sheet " + (Get-Date).Ticks), 11 | [string]$SheetPosition = "begin", 12 | [PSObject]$ChartType, 13 | [switch]$NoTypeInformation = $true, 14 | [switch]$AppendWorksheet = $true 15 | ) 16 | 17 | begin{ 18 | [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Excel") 19 | if($ChartType){ 20 | [microsoft.Office.Interop.Excel.XlChartType]$ChartType = $ChartType 21 | } 22 | 23 | function Set-ClipBoard{ 24 | param( 25 | [string]$text 26 | ) 27 | process{ 28 | Add-Type -AssemblyName System.Windows.Forms 29 | $tb = New-Object System.Windows.Forms.TextBox 30 | $tb.Multiline = $true 31 | $tb.Text = $text 32 | $tb.SelectAll() 33 | $tb.Copy() 34 | } 35 | } 36 | 37 | function Add-Array2Clipboard { 38 | param ( 39 | [PSObject[]]$ConvertObject, 40 | [switch]$Header 41 | ) 42 | process{ 43 | $array = @() 44 | 45 | if ($Header) { 46 | $line ="" 47 | $ConvertObject | Get-Member -MemberType Property,NoteProperty,CodeProperty | Select -Property Name | %{ 48 | $line += ($_.Name.tostring() + "`t") 49 | } 50 | $array += ($line.TrimEnd("`t") + "`r") 51 | } 52 | else { 53 | foreach($row in $ConvertObject){ 54 | $line ="" 55 | $row | Get-Member -MemberType Property,NoteProperty | %{ 56 | $Name = $_.Name 57 | if(!$Row.$Name){$Row.$Name = ""} 58 | $line += ([string]$Row.$Name + "`t") 59 | } 60 | $array += ($line.TrimEnd("`t") + "`r") 61 | } 62 | } 63 | Set-ClipBoard $array 64 | } 65 | } 66 | 67 | $excelApp = New-Object -ComObject "Excel.Application" 68 | $originalAlerts = $excelApp.DisplayAlerts 69 | $excelApp.DisplayAlerts = $false 70 | if(Test-Path -Path $Path -PathType "Leaf"){ 71 | $workBook = $excelApp.Workbooks.Open($Path) 72 | } 73 | else{ 74 | $workBook = $excelApp.Workbooks.Add() 75 | } 76 | $sheet = $excelApp.Worksheets.Add($workBook.Worksheets.Item(1)) 77 | if(!$AppendWorksheet){ 78 | $workBook.Sheets | where {$_ -ne $sheet} | %{$_.Delete()} 79 | } 80 | $sheet.Name = $WorksheetName 81 | if($SheetPosition -eq "end"){ 82 | $nrSheets = $workBook.Sheets.Count 83 | 2..($nrSheets) |%{ 84 | $workbook.Sheets.Item($_).Move($workbook.Sheets.Item($_ - 1)) 85 | } 86 | } 87 | $sheet.Activate() 88 | $array = @() 89 | } 90 | 91 | process{ 92 | $array += $InputObject 93 | } 94 | 95 | end{ 96 | Add-Array2Clipboard $array -Header:$True 97 | $selection = $sheet.Range("A1") 98 | $selection.Select() | Out-Null 99 | $sheet.Paste() 100 | $Sheet.UsedRange.HorizontalAlignment = [microsoft.Office.Interop.Excel.XlHAlign]::xlHAlignCenter 101 | Add-Array2Clipboard $array 102 | $selection = $sheet.Range("A2") 103 | $selection.Select() | Out-Null 104 | $sheet.Paste() | Out-Null 105 | $selection = $sheet.Range("A1") 106 | $selection.Select() | Out-Null 107 | 108 | $sheet.UsedRange.EntireColumn.AutoFit() | Out-Null 109 | $workbook.Sheets.Item(1).Select() 110 | if($ChartType){ 111 | $sheet.Shapes.AddChart($ChartType) | Out-Null 112 | } 113 | $workbook.SaveAs($Path) 114 | $excelApp.DisplayAlerts = $originalAlerts 115 | $excelApp.Quit() 116 | Stop-Process -Name "Excel" 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /GetServices.ps1: -------------------------------------------------------------------------------- 1 | # Get protocols from "services" file 2 | # 3 | # usage: 4 | # to be sourced in powershell (:> . GetServices.ps1) 5 | # 6 | 7 | function Get-Protocol 8 | { 9 | # CmdletBinding points to a parameter set with no parameters, 'All'. 10 | # Using this trick, it's possible to have a good default behavior with 11 | # no parameters without complex parameter guessing logic 12 | [CmdletBinding(DefaultParameterSetName='All')] 13 | 14 | param( 15 | # Get a named protocol 16 | [Parameter(Mandatory=$true, Position='0', ValueFromPipelineByPropertyName=$true, ParameterSetName='SpecificProtocols')] 17 | [Alias('Name')] 18 | [String[]]$Protocol, 19 | # Get protocols on a port 20 | [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, ParameterSetName='SpecificPorts')] 21 | [int[]]$Port, 22 | # Only return TCP protocols 23 | [switch]$OnlyTCP, 24 | # Only return UDP protocols 25 | [switch]$OnlyUDP 26 | ) 27 | 28 | #region Parse Services File 29 | begin { 30 | $servicesFilePath = "$env:windir\System32\drivers\etc\services" 31 | # / [aliases...] [#] 32 | $lines = [IO.File]::ReadAllText("$env:windir\System32\drivers\etc\services") -split 33 | # filter out all comment lines 34 | ([Environment]::NewLine) -notlike "#*" 35 | 36 | $protocols = foreach ($line in $lines) 37 | { 38 | # not empty lines 39 | if (-not $line) { continue } 40 | 41 | # split lines into name, port+proto, alias+comment 42 | $serviceName, $portAndProtocol, $aliasesAndComments = $line.Split(' ', [StringSplitOptions]'RemoveEmptyEntries') 43 | # split port+proto into port, proto 44 | $portNumber, $protocolName = $portAndProtocol.Split("/") 45 | # filter alias+comment into alias 46 | $aliases = @($aliasesAndComments) -notlike "#*" 47 | # filter alias+comment into comment 48 | $comments = @($aliasesAndComments) -like "#*" 49 | # combine them in a PSObject 50 | $result = New-Object PSObject -Property @{ 51 | ServiceName = $serviceName 52 | Port = $portNumber 53 | Protocol = $protocolName 54 | Aliases = $aliases 55 | Comments = $comments 56 | } 57 | 58 | # hidden typename to make formatting work 59 | $result.PSObject.TypeNames.add("Network.Protocol") 60 | $result 61 | } 62 | } 63 | #endregion 64 | 65 | #region Process Input 66 | process { 67 | $filter = $null 68 | if ($OnlyTCP) { 69 | $filter = { $_.Protocol -eq 'TCP' } 70 | } elseif ($OnlyUDP) { 71 | $filter = { $_.Protocol -eq 'UDP' } 72 | } 73 | 74 | # By checking to see if the filter is defined, 75 | # we can save time and not filter 76 | if ($Filter) { 77 | $filtererdProtocols = $protocols | Where-Object $filter 78 | } else { 79 | $filtererdProtocols = $protocols 80 | } 81 | 82 | # If the Parameter Set is "All", we output all of the protocols 83 | if ($psCmdlet.ParameterSetName -eq 'All') 84 | { 85 | Write-Output $filtererdProtocols 86 | } elseif ($psCmdlet.ParameterSetName -eq 'SpecificPorts') { 87 | # Otherwise, if we're looking for ports, we add another Where-Object 88 | # to find ports, and output that. 89 | $filtererdProtocols | Where-Object { 90 | $Port -contains $_.Port 91 | } | Write-Output 92 | } elseif ($psCmdlet.ParameterSetName -eq 'SpecificProtocols') { 93 | # Otherwise, if we're looking for protcols, we add another Where-Object 94 | # to find ports, and output that. 95 | $filtererdProtocols | Where-Object { 96 | $Protocol -contains $_.ServiceName 97 | }| Write-Output 98 | } 99 | } 100 | #endregion 101 | } 102 | -------------------------------------------------------------------------------- /HelloWorld.ps1: -------------------------------------------------------------------------------- 1 | # Hello World PowerShell-Script 2 | # 3 | 4 | write "Hello World" 5 | sleep 3 6 | -------------------------------------------------------------------------------- /HexDump.ps1: -------------------------------------------------------------------------------- 1 | # Simple HexDump 2 | # 3 | 4 | param( $path, $width=16, $bytes=-1 ) 5 | 6 | $OFS="" 7 | 8 | if( !(Test-Path $path) ) 9 | { 10 | Write-Host "no file at $path" 11 | exit -1 12 | } 13 | 14 | if( $bytes -eq -1 ) 15 | { 16 | $bytes = (Get-Item $path).length 17 | } 18 | 19 | ForEach( $byte in Get-Content -Encoding byte $path -ReadCount $width -totalcount $bytes ) 20 | { 21 | if( ($byte -eq 0).count -ne $width ) 22 | { 23 | $hex = $byte | Foreach-Object { 24 | " " + ("{0:x}" -f $_).PadLeft( 2, "0" ) 25 | } 26 | $char = $byte | Foreach-Object { 27 | if( [char]::IsLetterOrDigit($_) ) 28 | { 29 | [char] $_ 30 | } 31 | else 32 | { 33 | "." 34 | } 35 | } 36 | "$hex $char" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /History2Script.ps1: -------------------------------------------------------------------------------- 1 | # Write shell command history to a scriptfile 2 | # 3 | 4 | param( [String]$filename="history.ps1",[Int]$last=$MaximumHistoryCount ) 5 | 6 | if( $filename -contains "help" ) 7 | { 8 | Write-Host "usage: $($MyInvocation.MYCommand) <[-filename] filename> {<[-last] numberOfLastEntries>}" 9 | exit 10 | } 11 | 12 | $history = $(Get-History -count $last) 13 | $linecount = 0 14 | ForEach( $line IN $history ) 15 | { 16 | Add-Content $filename $line.CommandLine 17 | $linecount++ 18 | } 19 | 20 | Write-Host "Historys last $linecount commands written into $filename" -------------------------------------------------------------------------------- /Image2ASCII.ps1: -------------------------------------------------------------------------------- 1 | # Image to ascii art converter 2 | # 3 | 4 | param( 5 | [string]$path = $(throw "Supply an image path"), 6 | [int]$maxwidth, 7 | [string]$palette="ascii", 8 | [float]$ratio = 1.5 9 | ) 10 | 11 | $path=(resolve-path -erroraction "stop" $path).path 12 | 13 | $palettes = @{ 14 | "ascii" = " .,:;=|iI+hHOE#`$" 15 | "shade" = " " + [char]0x2591 + [char]0x2592 + [char]0x2593 + [char]0x2588 16 | "bw" = " " + [char]0x2588 17 | } 18 | $c = $palettes[$palette] 19 | if (-not $c) { 20 | write-warning "palette should be one of: $($palettes.keys.GetEnumerator())" 21 | write-warning "defaulting to ascii" 22 | $c = $palettes.ascii 23 | } 24 | [char[]]$charpalette = $c.ToCharArray() 25 | 26 | # we need the drawing assembly 27 | #$dllpath=(get-command "system.drawing.dll").definition #fixed with next two lines 28 | $drawfile= Get-ChildItem -Path "$((Get-ChildItem Env:\windir).Value)\assembly" -Filter *drawing.dll -Recurse 29 | $dllpath=(Get-Command $($drawfile.Fullname)).definition 30 | [Reflection.Assembly]::LoadFrom($dllpath) | out-null 31 | # load the image 32 | $image = [Drawing.Image]::FromFile($path) 33 | if ($maxwidth -le 0) { [int]$maxwidth = $host.ui.rawui.WindowSize.Width - 1} 34 | [int]$imgwidth = $image.Width 35 | [int]$maxheight = $image.Height / ($imgwidth / $maxwidth) / $ratio 36 | $bitmap = new-object Drawing.Bitmap ($image,$maxwidth,$maxheight) 37 | [int]$bwidth = $bitmap.Width; [int]$bheight = $bitmap.Height 38 | # draw it! 39 | $cplen = $charpalette.count 40 | for ([int]$y=0; $y -lt $bheight; $y++) { 41 | $line = "" 42 | for ([int]$x=0; $x -lt $bwidth; $x++) { 43 | $colour = $bitmap.GetPixel($x,$y) 44 | $bright = $colour.GetBrightness() 45 | [int]$offset = [Math]::Floor($bright*$cplen) 46 | $ch = $charpalette[$offset] 47 | if (-not $ch) { $ch = $charpalette[-1] } #overflow 48 | $line += $ch 49 | } 50 | $line 51 | } 52 | 53 | -------------------------------------------------------------------------------- /ModifyIP.ps1: -------------------------------------------------------------------------------- 1 | # Modifying IPs 2 | # 3 | 4 | param( [parameter(Mandatory=$true)][String]$address, [int]$oktett=4, [parameter(Mandatory=$true)][int]$newVal, [switch]$Help ) 5 | 6 | if( $Help ) 7 | { 8 | Write-Host "usage: $($MyInvocation.MYCommand) -address [-oktett ] -newVal [-help]" 9 | exit -1 10 | } 11 | 12 | $ip4change = $address.split(".") 13 | 14 | if( $ip4change.count -lt 4 ) 15 | { 16 | Write-Host "Not a valid IP-Address - to short" 17 | exit -1 18 | } 19 | elseif( $ip4change.count -gt 4 ) 20 | { 21 | Write-Host "Not a valid IP-Address - to long" 22 | exit -1 23 | } 24 | 25 | $ip4change[$oktett-1] = $newVal 26 | $newIP = $ip4change -join "." 27 | Write-Host $newIP -------------------------------------------------------------------------------- /MoveTemplate.ps1: -------------------------------------------------------------------------------- 1 | # Move a vmware virtual machine template to another host and/or datastore 2 | # work in progress... 3 | # working, but convert and move lines are commented out for testing 4 | # 5 | 6 | param( [string]$template, ` 7 | [string]$destHost, ` 8 | [string]$srcHost, ` 9 | [string]$datastore, ` 10 | [Switch]$allLinux, ` 11 | [Switch]$allWindows, ` 12 | [Switch]$help) 13 | 14 | if( ((!$template -or (!$destHost -and !$datastore)) -and !($allLinux -or $allWindows)) -or $help ) 15 | { 16 | Write-Host "usage: $($MyInvocation.MYCommand)