[PS] Checking profile folders with account in AD
Get-childitem c:\Users\ | where {$_.Mode -like "d*"} | ForEach-Object {
$folder = $_
$ad = Get-ADuser $folder -properties samaccountname
if($ad.samaccountname -eq $folder) {
echo "$folder is valid" | out-file -filepath output.txt -append
}
else
{
echo "$folder could not be matched"| out-file -filepath output.txt -append
}
}
[PS] Pre-populating computers in AD
Get-Content computers.txt | ForEach-Object { New-ADComputer -Name $_ -Path "PathToOU" }
[PowerCLI] Simple vSphere setup script
Simple vSphere setup..........Just posted the script will update soon.
Add-PSSnapin "Vmware.VimAutomation.Core" $VMHost = Read-Host "What is the ESX IP Address?" $VMotionIP = Read-Host "VMotion IP?" $VMotionSubnet = Read-Host "VMotion Subnet?" $ServiceIP = Read-Host "Service Console IP?" $ServiceSubnet = Read-Host "Service Console Subnet?" connect-VIServer $VMHost write-host "Creating vSwitch 2" New-VirtualSwitch -VMHost $VMHost -Name “vSwitch2“ -Nic “vmnic0,vmnic1“ New-VMHostNetworkAdapter -PortGroup “VMotion“ -VirtualSwitch “vSwitch2“ -IP $VMotionIP -SubnetMask $VMotionSubnet -VMotionEnabled:$true New-VMHostNetworkAdapter -PortGroup “Service Console“ -VirtualSwitch “vSwitch2“ -IP $ServiceIP -SubnetMask $ServiceSubnet write-host "vSwitch2 created" write-host "Creating vSwitch 3" $vS3 = New-VirtualSwitch -VMHost $VMHost -Name “vSwitch3“ -Nic “vmnic2,vmnic3,vmnic4,vmnic5“ write-host "Creating vLans to vSwitch3" New-VirtualPortGroup -VirtualSwitch $vS3 -Name ‘Servers‘ -VLanId ’1‘ New-VirtualPortGroup -VirtualSwitch $vS3 -Name ‘Heartbeat‘ -VLanId ’2‘ New-VirtualPortGroup -VirtualSwitch $vS3 -Name ‘Management‘ -VLanId ’3‘ write-host "vSwitch3 created" write-host "Enable iSCSI software adapter" Set-VMHostStorage -SoftwareIScsiEnabled $true write-host "iSCSI software activated" write-host "Getting WWN ID for the iSCSI" $ESXHost = get-vmhost $VMHost | Get-View $storageSystem = get-view $ESXHost.ConfigManager.StorageSystem $output = $storageSystem.StorageDeviceInfo.HostbusAdapter | select IScsiName $output | Out-File "iSCSI WWN.txt" write-host "Output file created from script location called 'iSCSI WNN.txt'" write-host "Script Compeleted."
[PS] Clearing extension attributes from Active Directory
i've decided to create this Powershell script which can be used to clean any extension attributes but as you will see below they have been set to 1 & 2. When using this script a parameter needs to be set this can be their login name
param($user) $user = Get-ADuser $user Set-ADObject -identity $user.DistinguishedName -clear extensionAttribute1, extensionAttribute2
[PS] Adding domain group to local group
Powershell script to add a domain group to a local group. The script will look through a list of computers which are specified in the "computers.txt" file and cycle through the list of computers adding the group.
Get-Content c:\Users\$username$\Desktop\computers.txt | ForEach-Object {
[ADSI]$objAdmins = "WinNT://$_/Administrators"
$objAdmins.Add("WinNT://contoso/Server Administrators,group")
}
[PS] Move disabled and log location
This script is mainly to help clean up Active Directory. The script will look through Test 1 and Test 2 OUs for devices disabled in active directory and move them to an Inactive OU. The script also keeps a log of the location where the computer was moved from for easy reference.
#########################################################################
# #
# Script created to move disabled computer into Inactive OU. #
# #
#########################################################################
$list = ("OU=Test 1,DC=contoso,DC=com","OU=Test 2,DC=contoso,DC=com")
foreach($ou in $list)
{
$inactive = "OU=Inactive,DC=contoso,DC=com"
Search-ADAccount -AccountDisabled -ComputersOnly -SearchBase $ou | Select name,DistinguishedName | Out-File Move-Disabled-Output.csv -append
Search-ADAccount -AccountDisabled -ComputersOnly -searchbase $ou | Move-ADobject -TargetPath $inactive
}
[PS] Move and disable inactive devices
This powershell script similar to the "AD clean up". This will look through certain OU and check for the last logged on. If the computer hasn't been logged on for over 90 days the computer will be moved in to the inactive OU while getting disabled. This script will also keep a record of the location and output this to a file.
#########################################################################
# #
# Script created to move inactive computers (90 Days) to the #
# inactive OU and Disable computer account #
# #
#########################################################################
$list = ("OU=TestOU2,DC=contoso,DC=com")
foreach($ou in $list)
{
$inactive = "OU=Inactive,DC=contoso,DC=com"
$date = (Get-Date).adddays(-90)
$lastSetdate = 0
#$lastSetdate = Get-Date $date -format "dd/MM/yy HH:mm:ss"
$result = Get-ADComputer -Filter {lastLogondate -le $lastSetdate} -Properties lastLogondate -ResultSetSize $null -SearchBase $ou
Get-ADComputer -Filter {lastLogondate -le $lastSetdate} -Properties lastLogondate -ResultSetSize $null -SearchBase $ou | Select name,DistinguishedName | Out-File MoveSet-Output.csv -append
Get-ADComputer -Filter {lastLogondate -le $lastSetdate} -Properties lastLogondate -ResultSetSize $null -SearchBase $ou | Set-ADComputer -Enable $False
Get-ADComputer -Filter {lastLogondate -le $lastSetdate} -Properties lastLogondate -ResultSetSize $null -SearchBase $ou | Move-ADobject -TargetPath $inactive
}
[VBs] Reset local admin password
Just an old VBs that would cycle through a list of computers resetting the local administrators account. This was developed in a domain enviroment.
Option Explicit
Dim fso, user, ts, temp, src
Set fSO = CreateObject("Scripting.FileSystemObject")
src = "\\DC01\sysvol\contoso.com\scripts\ictroom.txt"
If Not fso.FileExists(src) Then
WScript.Echo "File: " & src & " cannot be found."
WScript.Quit
End If
Set ts = fso.OpenTextFile(src,1)
Do Until ts.AtEndOfStream
temp = ts.ReadLine
Set user = GetObject("WinNT://" & temp & "/Administrator,user")
user.setpassword "P@ssw0rd"
user.setinfo
Loop
[VBs] Password reset
Option Explicit
Dim objOU, objUser, objRootDSE
Dim strContainer, strSubContainer, strLastUser, strDNSDomain, intCounter, intAccValue
Dim strUSER, strPWD
strUSER = inputbox("Enter the username:")
strPWD = inputbox("Enter the Password:")
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = "OU=Clients ,"
strSubContainer = "OU=Pupils ,"
intAccValue = 544
strContainer = strSubContainer & strContainer & strDNSDomain
set objOU =GetObject("LDAP://" & strContainer )
intCounter = 0
For each objUser in objOU
If objUser.sAMAccountName = (strUSER) then
objUser.SetPassword (strPWD)
objUser.SetInfo
objUser.Put "userAccountControl", intAccValue
objUser.SetInfo
intCounter = intCounter +1
strLastUser = objUser.Get ("name")
End if
next
WScript.Echo intCounter & " Users change pwd next logon. Value " _
& intAccValue
WScript.Quit
[VBs] Adding printers
Just another VBs that will add two printers and sets printer1 as the default on the computer.
' Printers.vbs - Windows Logon Script.
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\server\printer1"
objNetwork.SetDefaultPrinter "\\server\printer1"
objNetwork.AddWindowsPrinterConnection "\\server\printer2"