Skip to content

Instantly share code, notes, and snippets.

@mbrownnycnyc
mbrownnycnyc / getinfo.ps1
Last active August 29, 2015 14:00
quick script to pull some info from a given list of machines
<#
Note:
If you're going to schedule this task to run, use the following action:
Program/script: powershell
add arguments: -command &{[path to find_pc_owner.ps1]}
Start in: [the working directory]
see: http://blogs.technet.com/b/heyscriptingguy/archive/2011/0/12/use-scheduled-tasks-to-run-powershell-commands-on-windows.aspx
#>
@mbrownnycnyc
mbrownnycnyc / set-multitouch.ps1
Last active August 29, 2015 14:02
send a Windows message... will also change multitouch setting
#http://poshcode.org/2049
#http://forums.codeguru.com/showthread.php?491406-RESOLVED-Touch-Enable-Disable-Script&p=1911164#post1911164
if (-not ("win32.nativemethods" -as [type])) {
# import sendmessagetimeout from win32
add-type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
"@
}
@mbrownnycnyc
mbrownnycnyc / Invoke-CommandAgainstOU.ps1
Last active August 29, 2015 14:02
Do something to a bunch of computers by OU.
#ref
## http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/13/use-powershell-invoke-command-for-remoting.aspx
## http://www.powershellmagazine.com/2013/04/10/pstip-wait-for-a-service-to-reach-a-specified-status/
## http://stackoverflow.com/a/3008717/843000
## http://support.microsoft.com/kb/2509997
Invoke-Command -scriptblock {
#is this case, I am cleaning up pending updates due to an issue with a deployed update (error 1638)
$wuausvc = get-service wuauserv
$wuausvc.stop()
@mbrownnycnyc
mbrownnycnyc / Set-ExchCalendarPermissions.ps1
Last active August 29, 2015 14:04
Quick powershell to add Calendar permissions to a user's default calendar in Exchange
Param(
[string]$targetuser,
[string]$granteduser,
[string]$accessright
)
$targetuser=$targetuser+":"
write-host "previous to action permission list:"
<#
http://techibee.com/tips/powershell-script-to-get-ilo-version-and-server-model-remotely/572
Note:
If you're going to schedule this task to run, use the following action:
@mbrownnycnyc
mbrownnycnyc / gist:9075f25350e5e2168899
Last active August 29, 2015 14:05
KB querier and uninstaller (not a real powershell script, just some invocations).
#query for KB on all machines in a given OU (instead of get-adcomputer, try get-content and a file with a list of IPs or hostnames for the same effect)
#note that the get-wmiobject is optimized to only request specific hotfixids, before I would request all records are parse client size (ewww)
$contents = $( get-adcomputer -filter "objectCategory -eq 'computer'" -SearchBase "OU=New York,DC=contoso,DC=corp" | select-object -expand name )
foreach ($computer in $contents)
{
if (fastping $computer)
{
get-wmiobject -computer $computer -query "select * from win32_quickfixengineering where hotfixid like '%2982791%' OR hotfixid like '%2970228%' " | select-object csname, hotfixid, installedOn | export-csv -append -NoTypeInformation -noclobber "c:\users\mbrown\desktop\evilkbsliveshere.csv" -Encoding UTF8
}
}
@mbrownnycnyc
mbrownnycnyc / send-emailswhenoldfilesfound.ps1
Last active August 29, 2015 14:05
this will send an email if some files (in this case ".log") begin to accumulate past a given time span in a given directory.
function append-listofoldfilestoafile {
param(
[int]$fileageinhours,
[string]$filepath
)
#require a filepath
if ( -not ($filepath) ) {
throw "give me a filepath sucker"
@mbrownnycnyc
mbrownnycnyc / enter-appassuremaintenance.ps1
Last active August 29, 2015 14:05
Put a Dell AppAssure core server into "maintenance mode"
#https://support.software.dell.com/kb/119400
Import-Module AppAssurePowerShellModule
Suspend-Snapshot –All
Suspend-Replication -outgoing [hostname of remote core] -all
Suspend-Replication -incoming [hostname of remote core] -all
Suspend-Vmexport –All
if ( $(Get-ActiveJobs –All) -like "%no jobs%" ) {echo "what!"} # "No jobs of the specified type were found on the core." note that you will have to use dotpeek on the dll returned by `Get-Module AppAssurePowerShellModule | fl path` to actually see what the hell is going on here.
Set-Service AppAssureCore -StartupType Disabled
Stop-Service AppAssureCore
@mbrownnycnyc
mbrownnycnyc / exit-appassuremaintenance.ps1
Last active August 29, 2015 14:05
Take a Dell AppAssure core server out of "maintenance mode"
#https://support.software.dell.com/kb/119400
Import-Module AppAssurePowerShellModule
Sc.exe Config AppAssureCore Start= Delayed-Auto
Start-Service AppAssureCore
Resume-Snapshot –All
Resume-Replication -outgoing [hostname of remote core] -all
Resume-Replication -incoming [hostname of remote core] -all
Resume-Vmexport –All
@mbrownnycnyc
mbrownnycnyc / get-adusersid.ps1
Created September 2, 2014 19:45
get a sid for an AD user
function get-adusersid{
#http://community.spiceworks.com/how_to/show/2776-powershell-sid-to-user-and-user-to-sid
param(
[string]$domain,
[string]$user
)
$objUser = New-Object System.Security.Principal.NTAccount("$domain", "$user")
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])