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
# Confirm system access: | |
"user1","user2" | Get-ADUser -properties * | ft SamAccountName, DisplayName, Enabled | |
# Disable: | |
"user1","user2" | Disable-ADAccount | |
# If processing a change for folks who should be terminated, easier to do this: | |
$userlist = "user1","user2" | |
$userlist | Get-ADUser -properties * | ft SamAccountName, DisplayName, Enabled | |
$userlist | Disable-ADAccount |
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
# Add/Remove Email Access For Another Mailbox: | |
# First get a session to work in, unless you have the tools installed | |
$Session = New-PSSession -ConfigurationName Microsoft.Exchange ` | |
-ConnectionUri http://mailserver/PowerShell/ ` | |
-Authentication Kerberos | |
Import-PSSession $Session | |
# setup users | |
$a = '[email protected]' #who's mailbox is it? |
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 speed of last command: | |
($hi = (Get-History)[-1]) | %{ $hi;$hi.EndExecutionTime - $hi.StartExecutionTime} | |
# check get-history for id-1 to get index if you want a specific task |
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
# Save task as xml (and delete them, or a list of them): | |
$sn="server" | |
$tn="taskname" | |
schtasks /query /s $sn /tn $tn /xml one > "cleanup_job-$tn.xml" | |
schtasks /delete /s $sn /tn $tn |
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-Uptime { | |
Param ( [string] $ComputerName = $env:COMPUTERNAME ) | |
$os = Get-WmiObject win32_operatingsystem -ComputerName $ComputerName -ErrorAction SilentlyContinue | |
if ($os.LastBootUpTime) { | |
$uptime = (Get-Date) - $os.ConvertToDateTime($os.LastBootUpTime) | |
Write-Output ("Last boot: " + $os.ConvertToDateTime($os.LastBootUpTime) ) | |
Write-Output ("Uptime : " + $uptime.Days + " Days " + $uptime.Hours + " Hours " + $uptime.Minutes + " Minutes" ) | |
} | |
else { | |
Write-Warning "Unable to connect to $computername" |
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
# Generate a..z in powershell | |
([char[]]([int][char]'a'..[int][char]'z')) |
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
@' | |
username,fullname | |
user1,"user one" | |
user2,"user two" | |
'@ | ConvertFrom-Csv | foreach { | |
$AD = Get-ADUser -Identity $_.username | |
New-Object PSObject -Property @{ | |
UserName = $_.username | |
FullName = $_.fullname | |
Name = $AD.Name |
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
New-ADUser newdomainadmin -OtherAttributes @{displayname="new domain admin person"} | |
Set-ADAccountPassword newdomainadmin -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "plaintextpassword" -Force ) | |
Get-ADGroup "Domain Admins" | |
Get-ADGroup "Domain Admins" | Add-ADGroupMember -Members (Get-ADUser newdomainadmin ) | |
Get-ADGroup "Domain Admins" |
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
#set the user to fix, this should match the duplicate that was sent from local AD | |
$sam = "user1" | |
$old = "[email protected]" | |
$new = "[email protected]" | |
#show the users | |
Get-MsolUser -UserPrincipalName $old | |
Get-MsolUser -UserPrincipalName $new | |
#remove the old user | |
Remove-MSOLuser -UserPrincipalName $old -Force | |
#remove it from recyclebin |
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
-- temp table variable | |
declare @tbl table ( | |
a varchar(2) | |
) | |
insert @tbl | |
select 'v0' | |
union all select 'v1' | |
union all select 'v2' |