This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Works with PowerShell v2, but only works with very simple JSON | |
function Get-SimpleJSON { | |
param( | |
[Parameter(Mandatory=$true, | |
ValueFromPipeline=$True)] | |
[Alias('Uri')] | |
[string]$JSONUri, | |
[Alias('CamelCase')] | |
[switch]$TitleCase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get-WMIObject: | |
Days : 0 | |
Hours : 0 | |
Minutes : 7 | |
Seconds : 11 | |
Milliseconds : 568 | |
Ticks : 4315681996 | |
TotalDays : 0.00499500231018519 | |
TotalHours : 0.119880055444444 | |
TotalMinutes : 7.19280332666667 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$computers = Get-ADComputer -SearchBase (Get-ADOrganizationalUnit -Filter {Name -eq 'Servers'} ) -Filter * | Select-Object -ExpandProperty Name | |
Measure-Command { | |
Get-WmiObject Win32_ComputerSystem -ComputerName $computers -ErrorAction ignore | |
} | |
Measure-Command { | |
Get-CimInstance Win32_ComputerSystem -ComputerName $computers -ErrorAction ignore | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-PCBUptime { | |
<# | |
.SYNOPSIS | |
A simple tool for checking how long a system on the network has been running since last boot. | |
.DESCRIPTION | |
Get-PCBUptime is a quick WMI-based tool for determinging a remote system's uptime. It is useful for verifying | |
what a user says when asked if they've rebooted their machine recently. | |
Get-PCBUptime is written by and copyright of Christopher R. Lowery, aka The PowerShell Bear (poshcodebear.com; Twitter: @poshcodebear) | |
It is free for all to use, and free to distribute with attribution to the original author. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Server = 'server' | |
$Shares = Get-Content -Path C:\temp\server-shares.txt | |
$output = foreach ($Share in $Shares) { | |
$Path = "\\$Server\$Share" | |
Get-ChildItem -Path $Path -Recurse | ` | |
where attributes -like *directory* | ` | |
Get-Acl | ` | |
Where-Object {$_.AreAccessRulesProtected -eq $True} | ` | |
Select-Object @{Label='Directory';Expression={$_.path.split(':')[-1]}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$BirthDay = Get-Date "8-16-1989 17:55" | |
$BirthDay.AddSeconds(1000000000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Setup = 'HKLM:\SOFTWARE\Microsoft\Internet Explorer\Setup' | |
$Main = 'HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main' | |
$Versions = '9', '10', '11' | |
#Disable upgrading to Versions listed above | |
try { Get-Item -Path $Setup -ErrorAction Stop } | |
catch { New-Item -Path $Setup } | |
foreach ($ver in $Versions) { | |
if ([int]$ver -lt 10) { $dna = $ver + '0' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$NS = Resolve-DnsName -Name domain.tld -Type NS | ` | |
Where {$_.Type -eq 'NS'} | ` | |
Select-Object -ExpandProperty NameHost | |
$output = foreach ($server in $NS) { | |
$forwarders = Get-DNSServer -ComputerName $server | ` | |
Select-Object -ExpandProperty ServerForwarder | ` | |
Select-Object -ExpandProperty IPAddress | ` | |
Select-Object -ExpandProperty IPAddressToString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-ADOrganizationalUnit -Filter * -Properties ProtectedFromAccidentalDeletion | ` | |
where {$_.ProtectedFromAccidentalDeletion -eq $False} | ` | |
Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$vms = Get-VM | |
$output = foreach ($vm in $vms) { | |
foreach ($adapter in $vm.NetworkAdapters) { | |
$props = @{'Name' = $vm.Name; | |
'Type' = $adapter.Type} | |
$obj = New-Object -TypeName PSObject -Property $props | |
Write-Output $obj | |
} |