Skip to content

Instantly share code, notes, and snippets.

View jespernohr's full-sized avatar

Jesper Nøhr jespernohr

View GitHub Profile
## PowerShell: Script To Telnet To Remote Hosts And Run Commands Against Them With Output To A File ##
## Overview: Useful for Telnet connections to Cisco Switches and other devices. Can add additional command strings
## Usage Examples: Add your environment specific details into the parameters below, or include when calling the script:
## In this script it 1. change Ethernet NIC to static IP - 2. connects to Zyxel VMG1312-B10A and configure device- 3.change Ethernet NIC to DHCP
## Contributer "Chrisdee" https://github.com/chrisdee/Scripts/blob/master/PowerShell/Working/telnet/PowerShellTelnetRemoteSession.ps1
## Modified "[email protected]"
param(
[string] $remoteHost = "192.168.1.1",
[int] $port = 23,
@jespernohr
jespernohr / Signing-Scripts.ps1
Last active September 24, 2015 13:29
sign powershell scripts using a code signing ssl certificate.
# use commands to sign powershell scripts using a code signing ssl certificate.
# prerequsits:
# 1. Self-signed, 3rd party or Active Directory Certificate Services codesigning certificate installed.
# 2. client computers or client servers should trust the publisher/auther (user) used signed the script.
# sets Windows execution policy to secure.
Set-ExecutionPolicy AllSigned
# sign the script with the "Code Signing" certificate in Certificate - Current User - Personal - Certificates store.
# First check your kernel version, so you won't delete the in-use kernel image, running:
uname -r
# Now run this command for a list of installed kernels:
sudo dpkg --list 'linux-image*'
# and delete the kernels you don't want/need anymore by running this:
sudo apt-get remove linux-image-VERSION
# Use openSSl to create and managed SSL certificates
# Create privat key (4096 bit):
openssl genrsa -out domain.gl.key 4096
# Create CSR (Certificate Signing Request):
openssl req -new -sha256 -key domain.gl.key -out domain.gl.csr
# Verify CSR:
openssl req -text -noout -verify -in domain.gl.csr
# use theese cmd-lets to create managed service accounts in Active Directory
# these new service accounts can be used on servers that share a specific computer group.
New-ADServiceAccount -name gmsa001 -DNSHostName gmsa001.contoso.com -PrincipalsAllowedToRetrieveManagedPassword "Domain Controllers"
New-ADServiceAccount -name gmsa002 -DNSHostName gmsa002.contoso.com -PrincipalsAllowedToRetrieveManagedPassword "Web Servers"
New-ADServiceAccount -name gmsa003 -DNSHostName gmsa003.contoso.com -PrincipalsAllowedToRetrieveManagedPassword "SQL Servers"
New-ADServiceAccount -name gmsa004 -DNSHostName gmsa004.contoso.com -PrincipalsAllowedToRetrieveManagedPassword "File Servers"
New-ADServiceAccount -name gmsa005 -DNSHostName gmsa005.contoso.com -PrincipalsAllowedToRetrieveManagedPassword "RDS Servers"
# use this cmd-let to enable the "protect from accidental deletion" on your active directory site.
Set-ADReplicationSite -ProtectedFromAccidentalDeletion $true
# set all users in an OU to have password expiration enabled.
# use -limit x if you have more that 100 users in the OU.
dsquery user "OU=Postal Workers,OU=Nuuk,OU=Users,OU=Business Unit,DC=test,DC=contoso,DC=com" -limit 2000 | dsmod user -pwdneverexpires no
# load Azure Active Directory Module
Import-Module MSOnline
#login to Azure Active Directory with <username>@<domain.com>
$msolcred = get-credential
connect-msolservice -credential $msolcred
# get users from office365/Azure Active Directory
Get-MsolUser | select-object -property userprincipalname,displayname,islicensed | export-csv -path c:Office365_users.csv
# Synchronize your Active directory with o365/Azure
# On the computer that is running the Directory Sync tool, start PowerShell, type Import-Module DirSync, and then press ENTER.
Import-Module DirSync
# Start Delta synchronization
Start-OnlineCoexistenceSync
# check if fullsync is enabled
Get-ItemProperty –Path ‘hklm:\Software\Microsoft\MSOLCoexistence’ –Name FullSyncNeeded
# use this script to add the userprincipalname as pimary SMTP to the proxyaddress attribute of a user object.
$users = Get-ADUser -Filter {EmailAddress -like "[email protected]"}
foreach($item in $users)
{
$UPN=$item.UserPrincipalName
write-host $UPN
set-aduser -identity $item -add @{proxyAddresses="SMTP:"+$UPN}
}