Skip to content

Instantly share code, notes, and snippets.

View rysstad's full-sized avatar

Tor Arne Rysstad rysstad

View GitHub Profile
(Get-Date -Format yyyy-MM-dd_HH-mm).ToString()
@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()
# 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
Get-WMIObject Win32_LogicalDisk | ForEach-Object {Write-Host $_.DeviceID "Size: " ("{0:N2}" -f ($_.Size / 1GB)) "Gb `t Free:" ("{0:N2}" -f ($_.freespace / 1GB)) "Gb" }
################################################################################
# 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
$hostnameFQDN = [System.Net.Dns]::GetHostByName(($env:computerName)).HostName
$TranscriptFile = $env:TEMP + "\PowershellTranscript-" + (Get-Date -Format yyyy-MM-dd_HH-mm).ToString() + ".log"
Start-Transcript $TranscriptFile -Verbose