New-ADUser -Name <Name> -SAMAccountName <Logon Name> - GivenName <First Name> -Surname <Surname> -DisplayName <Display Name> -UserPrincipalName <User Principal Name>- Path <Organizational Unit Path> -ProfilePath <Profile Path> -HomeDrive <Home Drive Letter> -HomeDirectory <Home Directory Path> -AccountPassword (ConvertTo-SecureString -AsPlainText <Password> -Force) -Enabled $True New-ADUser -Name "Simon Ansell" -SAMAccountName SAnsell -GivenName Simon -Surname Ansell -DisplayName "Simon Ansell" -UserPrincipalName "sansell@mainlinesoup.internal"-path "CN=Users,DC=Mainlinesoup,DC=Internal" -ProfilePath "\\MLS-DC-01\Users\Profiles\SAnsell" -HomeDrive "N:" - HomeDirectory "\\MLS-DC-01\Users\Home\sansell" - AccountPassword (ConvertTo-SecureString -AsPlainText "Change_Me" -Force) -Enabled $True Add-ADGroupMember Identity <Group Name> -Member <User Name>
Add-ADGroupMember Identity Students Member SAnsell New-Item <Folder Path and Name> -Type Directory New-Item H:\Users\Work\SAnsell Type Directory $Path = <Folder Path> $ACL = Get-ACL $Path $Permission = "<Domain\User>","FullControl","Allow" $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission $acl.setaccessrule($accessrule) $ACL Set-Acl $Path
$Path = H:\Users\Home\SAnsell $ACL = Get-ACL $Path $Permission = "MLS\SAnsell","FullControl","Allow" $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission $acl.setaccessrule($accessrule) $ACL Set-Acl $Path
Import-Module GroupPolicy Verbose $Date = Get-Date Format dd-mm-yyyy $BackupPath = Join-Path <Backup Folder> ChildPath $Date New-Item Path $BackupPath Type Directory Backup-GPO All Path $BackupPath > <Backup Path>\$Date.txt Import-Module GroupPolicy Verbose $Date = Get-Date Format dd-mm-yyyy $BackupPath = Join-Path D:\GPOBackup ChildPath $Date New-Item Path $BackupPath Type Directory Backup-GPO All Path $BackupPath > D:\GPOBackup\$Date.txt Import-Module GroupPolicy Verbose $GPO = <GPO Name> $BackupPath = <Backup Folder>
Get-GPO Name $GPO Backup-GPO Path $BackupPath Import-Module GroupPolicy Verbose $GPO = Default Domain Policy $BackupPath = D:\GPOBackup\Default Domain Policy Get-GPO Name $GPO Backup-GPO Path $BackupPath Restore-GPO Name <GPO Name> -Path <Backup Path> Restore-GPO Name Default Domain Policy -Path D:\GPOBackup Restore-GPO All -Path <Backup Path> Restore-GPO All -Path D:\GPOBackup
cscript GetReportsForAllGPOs.wsf <Target Folder>
cscript GetReportsForAllGPOs.wsf C:\Policies
Repadmin /Showrepl Example Repadmin /Showrepl <Server Name> Repadmin /Showrepl MLS-DC-01
Repadmin /Showrepl /CSV ><File Path> Repadmin /Showrepl /CSV >D:\Temp\Rep.csv Example Repadmin /Replicate <Destination DC> <Source DC> <Domain> Repadmin /Replicate MLS-DC-02 MLS-DC-01 DC=mainlinesoup, DC=internal The
Get-WMIObject NameSpace Root\MicrosoftDNS List Where- Object {$_.Name NotMatch }
Set q=mx
Server <Server name> Server alien.xtra.co.nz
Server <IP Address> scope <Scope Address> show clients 1 Server 10.0.186.10 scope 10.0.186.0 show clients 1 Server <IP Address> scope <Scope Address> set optionvalue 003 ipaddress <IP Address> Server 10.0.186.10 scope 10.0.186.0 set optionvalue 003 ipaddress 10.0.186.66
$a = (netsh dhcp server <> scope <> show clients 1) $lines = @() #start by looking for lines where there is both IP and MAC present:10 foreach ($i in $a){ if ($i -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"){ If ($i -match "[0-9a-f]{2}[:-][0-9a-f]{2}[:- ][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9af]{2}"){ $lines += $i.trim() } } } $csvfile = @() #Trim the lines for uneeded stuff, leaving only IP, Subnet mask and hostname. foreach ($l in $lines){ $Row = "" select Hostname,IP $l = $l -replace '[0-9a-f]{2}[:-][0-9a-f]{2}[:- ][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9af]{2}', '' $l = $l -replace ' - ',',' $l = $l -replace '\s{4,}','' $l = $l -replace '--','-' $l = $l -replace '-D-','-' $l = $l -replace '[-]{1}\d{2}[/]\d{2}[/]\d{4}','' $l = $l -replace '\d{1,2}[:]\d{2}[:]\d{2}','' $l = $l -replace 'AM','' $l = $l -replace 'PM','' $l = $l -replace '\s{1}','' $l = $l + "`n" $l = $l -replace '[,][-]',','
$Row.IP = ($l.split(","))[0] #Subnet mask not used, but maybe in a later version, so let's leave it in there: #$Row.SubNetMask = ($l.split(","))[1] $Row.Hostname = ($l.split(","))[2] $csvfile += $Row } #let create a csv file, in case we need i later.. $csvfile sort-object Hostname Export-Csv "Out_List.csv" #Create the HTML formating $a = "<style>" $a = $a + "body {margin: 10px; width: 600px; fontfamily:arial; font-size: 12px;}" $a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}" $a = $a + "TH{border-width: 1px;padding: 2px;borderstyle: solid;border-color: black;background-color: rgb(179,179,179);align='left';}" $a = $a + "TD{border-width: 1px;padding: 2px;borderstyle: solid;border-color: black;background-color: white;}" $a = $a + "</style>" #And create HTML file... $csvfile sort-object Hostname ConvertTo-HTML -head $a Out-File -Append "DHCPLeases.html"
Const HARD_DISK = 3 strcomputer = "." Set objwmiservice = GetObject("winmgmts:" _ & "{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2") Set coldisks = objwmiservice.execquery _ ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "") For Each objdisk in coldisks Wscript.Echo "DeviceID: "& vbtab & objdisk.deviceid Wscript.Echo "Free Disk Space: "& vbtab & objdisk.freespace Next Example cscript <Path>\FreeSpace.vbs
cscript D:\Temp\FreeSpace.vbs Get-WmiObject Win32_LogicalDisk -filter "DriveType=3 Select SystemName,DeviceID,VolumeName,@{Name="Size(GB)";Expre ssion={"{0:n1}" - f($_.size/1gb)}},@{name="freespace(gb)";expression={"{ 0:N1}" -f($_.freespace/1gb)}}
Get-WmiObject Win32_LogicalDisk Computer <Computer Name> -filter "DriveType=3 Select SystemName,DeviceID,VolumeName,@{Name="Size(GB)";Expre ssion={"{0:n1}" - f($_.size/1gb)}},@{name="freespace(gb)";expression={"{ 0:N1}" -f($_.freespace/1gb)}}
[reflection.assembly]::loadwithpartialname("micr osoft. UpdateServices.Administration") Out-Null $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]:: getupdateserver() $wsussubscription = $wsus.getsubscription() $objcategories = New-Object Microsoft.UpdateServices.Administration.UpdateCategory Collection foreach ($category in $wsus.getupdatecategories()) { if ($category.title.tolower() -eq "exchange server 2010") {$objcategories.add($category) Out-Null} } $wsussubscription.setupdatecategories($objcategories) $wsussubscription.save() $wsussubscription.startsynchronization() [reflection.assembly]::loadwithpartialname("microsoft. UpdateServices.Administration") Out-Null $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]:: getupdateserver() $wsussubscription = $wsus.getsubscription() $Req = "Exchange 2010" $arrrequired = "exchange",
"developer tools, runtimes, and redistributables", "expression", "office", "silverlight", "virtual server", "windows live" # But we want to exclude these $arrexclude = "windows 2000", "eu browser choice update-for europe only" $objcategories = New-Object Microsoft.UpdateServices.Administration.UpdateCategory Collection foreach ($category in $wsus.getupdatecategories()) { if ($arrrequired -contains $category.title.tolower()) { if ($category.type -eq "ProductFamily") {$objcategories.add($category) Out-Null} } elseif ($category.title -eq "Windows") { foreach ($subcategory in $category.getsubcategories()) { if ($arrexclude -notcontains $subcategory.title) {$objcategories.add($subcategory) Out-Null} } } } $wsussubscription.setupdatecategories($objcategories) $wsussubscription.save() $wsussubscription.startsynchronization()
Import-Module BITSTransfer Get-Command Module BITSTransfer Get-BITSTransfer AllUsers
MSTSC /v <Target Name> /Admin MSTSC /v MLS-DC-02 /Admin
Shutdown /m \\<Computer Name> /r Shutdown /m MLS-DC-01 /r