Post your Fav Powershell Scripts


Recommended Posts

So i have been pushing myself to get into more powershell. Anyone here got some good powershell scripts for everyday use. Maybe we can get a nice collection to pin here in NeoWin.

Link to comment
Share on other sites

I tend to use this a lot:

start-process "http://technet.microsoft.com/library"

/joke

 

A great tool that I use a lot for application deployments though SCCM or simple network shares is the PowerShell App Deployment Toolkit on CodePlex. Highly recommend it if you are doing application deployments or just about any PowerShell script that needs a simple UI for end-users.

  • Like 1
Link to comment
Share on other sites

function sudo ([string]$file, [string]$arguments) {
$psi = new-object System.Diagnostics.ProcessStartInfo $file;
$psi.Arguments = $arguments;
$psi.Verb = "runas";
$psi.WorkingDirectory = get-location;
[System.Diagnostics.Process]::Start($psi);
}

Usage: sudo app.exe

 

My prompt function:

$global:wmilocalcomputer = get-WMIObject -class Win32_OperatingSystem -computer "."
$global:lastboottime=[System.Management.ManagementDateTimeconverter]::ToDateTime($wmilocalcomputer.lastbootuptime)
$global:originaltitle = [console]::title
 
function global:prompt 
{
$up=$(get-date)-$lastboottime
 
$upstr="$([datetime]::now.toshorttimestring()) $([datetime]::now.toshortdatestring()) up $($up.days) days, $($up.hours) hours, $($up.minutes) minutes"
 
$dir = $pwd.path
 
$homedir = $env:userprofile
 
if ($homedir -ne "" -and $dir.toupper().startswith($homedir.toupper()))
{
$dir=$dir.remove(0,$homedir.length).insert(0,'~')
}
 
if ([console]::title.length -ne 0) {
[console]::title = "$global:originaltitle ? $env:username@$($env:computername.tolower())?$dir ? $upstr" }
 
write-host "$env:username" -nonewline 
write-host "@" -nonewline
write-host "$($env:computername.tolower())" -nonewline
write-host "?" -nonewline
write-host "$dir" -nonewline
write-host "?" -nonewline
return " `b"
}

Puts the up-time in the powershell window title and makes my prompt look like: jgentile@v8?~\Documents\WindowsPowerShell?

Both work best when put in "C:\Users\[username]\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"

http://poshcode.org also has many great scripts.

Link to comment
Share on other sites

Replace "this pc" with computername.domain.local
 

$objIPProperties = [system.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
if ($objIPProperties.DomainName -eq $null) {
$SystemName = ?{0}? -f $objIPProperties.HostName
}
else {
$SystemName = ?{0}.{1}? -f $objIPProperties.HostName, $objIPProperties.DomainName
}
Set-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}" -Value $SystemName -Type string

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.