Skip to content

Instantly share code, notes, and snippets.

View alexinnes's full-sized avatar

Alex Innes alexinnes

  • Glasgow
View GitHub Profile
@alexinnes
alexinnes / ConstantPingToServer.ps1
Last active August 29, 2015 14:21
Pings server constantly and logs results.
#
# ConstantPingToArc.ps1
#
##This script purpose is to ping Arc console to monitor for network dropouts.
#Location for the log file
$testPath = Test-Path "C:\ping logs\"
#Manual on/off switch, if $onOff = $true means the loop is on, $false = its off.
$onOff = $true
@alexinnes
alexinnes / Mailbox list.ps1
Last active August 29, 2015 14:21
Gets Mailboxes from specified server, lists: Name, last login time, size and which server its located on.
#Database name you want to get all mailboxes from
#Add * on the end for a wildcard
$database = "PER*"
#Output File name
$Filename = "Export.csv"
#Where you want to export the file
$Path = "C:\"
@alexinnes
alexinnes / RebootTime.ps1
Created May 20, 2015 11:20
Quick script to check when the computer has been rebooted.
#
# RebootTime.ps1
#
Set-ExecutionPolicy -ExecutionPolicy Bypass
Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
@alexinnes
alexinnes / Funtion-GetUsersFromGroup.ps1
Created May 20, 2015 11:22
Function to get all users from a specified group.
<#
.Synopsis
Gets all users associated within a AD Group
.DESCRIPTION
Gets all users associated within a AD Group
.EXAMPLE
get-ADUserfromGroup [adgroupname]
.EXAMPLE
Another example of how to use this cmdlet
#>
@alexinnes
alexinnes / finds empty folders.ps1
Created May 20, 2015 11:25
Finds empty folders and removes them.
#Enter top level location here
$filelocation = ""
#Remove the -whatif at the end if you want it to actually remove the folders
(gci $filelocation -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | Remove-Item -verbose -whatif
@alexinnes
alexinnes / hidedisabledaccountsfromGAL.ps1
Last active August 29, 2015 14:21
Hides all disabled accounts from global address list.
#which exchange server
$server = ""
Get-Mailbox -Filter{(HiddenFromAddressListsEnabled -eq $false) -AND (UserAccountControl -eq "AccountDisabled, NormalAccount")}
| where {$_.servername -like "$server"} | set-mailbox -HiddenFromAddressListsEnabled $True
##Must run in exchange console##
@alexinnes
alexinnes / CreatePagesFromList.ps1
Last active August 29, 2015 14:22
Create pages from CSV
#specify the content here
$content = gc "content path here"
#Have a list of what the files will be called specified here
$port = import-csv "list path here"
#loops through the list, creating pages and adding the content
foreach($i in $port){
Add-Content "C:\eco\export\$($i.Title)" $content -force
}
@alexinnes
alexinnes / ComputersinAD.ps1
Created June 9, 2015 08:48
Get Computers in Active Directory in Certain OUs
#Where do you want the file to be exported to
$Export = "C:\"
#What OU Do you want to target
$OU=@("OU=PS,DC=ps,DC=internal","OU=TCASP,DC=ps,DC=internal")
#loop through the array of OUs and find all the computers. Selects the: Name, Operatingsystem, lastlogondate, modified, Created and Canonicalname and exports to CSV
$OU | foreach { get-adcomputer -Filter * -SearchBase $_ -Properties *
| select -Property Name, Operatingsystem, lastlogondate, modified, Created, Canonicalname} | export-csv $Export
@alexinnes
alexinnes / removeUserfromGroups.ps1
Created July 22, 2015 15:19
Gets all users from a OU and removes them from their groups
$users = get-aduser -filter * -SearchBase "OU=ToBeArchived,OU=Users,OU=PS,DC=ps,DC=internal" | select -Property samaccountname
$groups = get-aduser -filter * -SearchBase "OU=ToBeArchived,OU=Users,OU=PS,DC=ps,DC=internal" -Properties memberof | select -Property memberof -ExpandProperty memberof
foreach($user in $users){foreach($group in $groups){Remove-ADGroupMember $group -Members $user.samaccountname -whatif; $user}}
@alexinnes
alexinnes / 0365 Getting Users from all Groups.ps1
Last active September 29, 2015 11:04
O365 Getting users from all groups
#Run this first - It will ask you to login (microsoft account)
Connect-MsolService
#This gets the domain
$domain = Get-MsolPartnerContract -DomainName #change me to the domain name e.g. someone.onmicrosoft.com
#this gets the users in the group
$groups = @(Get-MsolGroup -TenantId $domain.TenantId)
#This goes through the groups and lists the users.
foreach($element in $groups){$element.DisplayName; Get-MsolGroupMember -TenantId $domain.TenantId -GroupObjectId $element.ObjectID}