Skip to content

Instantly share code, notes, and snippets.

View rysstad's full-sized avatar

Tor Arne Rysstad rysstad

View GitHub Profile
$TranscriptFile = $env:TEMP + "\PowershellTranscript-" + (Get-Date -Format yyyy-MM-dd_HH-mm).ToString() + ".log"
Start-Transcript $TranscriptFile -Verbose
$hostnameFQDN = [System.Net.Dns]::GetHostByName(($env:computerName)).HostName
################################################################################
# PowershellGenerateRandomPassword
#
# Description: Generate random password consisting of only upper and lower case letters and numbers.
# Adding non-letter characters would increase the password complexity, but would add
# potential problems related to SQL server, ODBC etc.
#
# Author name: Tor Arne Rysstad
# Created date: 2013.10.29
# Version: 0.02
Get-WMIObject Win32_LogicalDisk | ForEach-Object {Write-Host $_.DeviceID "Size: " ("{0:N2}" -f ($_.Size / 1GB)) "Gb `t Free:" ("{0:N2}" -f ($_.freespace / 1GB)) "Gb" }
# Create object reference to Get-Host
$pshost = get-host
# create reference to the console’s UI.RawUI child object
$pswindow = $pshost.ui.rawui
# Adjust the buffer first:
$newsize = $pswindow.buffersize
$newsize.height = 9999
$newsize.width = 200
$pswindow.buffersize = $newsize
# Adjust the Window size
@rysstad
rysstad / Add-Printer.ps1
Created April 14, 2014 04:51
Add printer connection to Windows with Powershell.
$PrinterPath = "\\printerServer\printerShare"
$PrinterName = "PrinterName"
$wmiNet = new-Object -com WScript.Network
$wmiNet.AddWindowsPrinterConnection($PrinterPath)
# Set as default
(New-Object -ComObject WScript.Network).SetDefaultPrinter($PrinterName)
# List all printers
# (New-Object -ComObject WScript.Network).EnumPrinterConnections()
(Get-Date -Format yyyy-MM-dd_HH-mm).ToString()
@rysstad
rysstad / Get-ChildItemInMb
Created June 3, 2014 07:51
Show files with filesize in Mb
Get-ChildItem | Select-Object Name,LastWriteTime,@{Name="Size Mb"; Expression = {[math]::round($_.Length /1Mb, 2)}}
; Turn on NumLock for ever and always... aahh...
SetNumLockState, AlwaysOn
::dt--::
FormatTime, dateTime2, ,yyyy.MM.dd-HH.mm
SendInput %dateTime2%
return