POWERSHELL
-
Powershell – Set ACL for each folder with respective share foldels
This is working fine: $csv = Import-Csv -Path “$env:userprofile\desktop\KDrivePath.csv” ForEach ($item In $csv) { $acl = Get-Acl $item.Path $AddPerm = New-Object System.Security.AccessControl.FileSystemAccessRule($item.Name,”FullControl”,”ContainerInherit, ObjectInherit”, “None”,”Allow”) $acl.SetAccessRule($AddPerm) $acl | Set-Acl $item.Path Write-Host -ForegroundColor Green “Group $($item.Name) created!” }
-
PowerShell – Find Name & OS Version of Domain Controllers
Get-ADDomainController -Filter * | select name, operatingsystem
-
Get nested Active Directory group members
function Get-ADNestedGroupMembers { [cmdletbinding()] param ( [String] $GroupName ) import-module activedirectory $Members = Get-ADGroupMember -Identity $GroupName $members | % { if($_.ObjectClass -eq "group"){ Get-ADNestedGroupMembers -GroupName $_.distinguishedName } else { return $_.distinguishedname } } }
-
User password changed time using PowerShell
Get-QADUser pugazh| select PasswordLastSet To know no. of days since the user changed his password, ((get-date) – (Get-QADUser pamarths).PasswordLastSet).days
-
Create multiple test user accounts
Import-Module ActiveDirectory foreach($i in 1..10) { $AccountName = "TestUser{0}" -f $i $Password = Convertto-secureString -string "password" -AsPlainText New-ADUser -Name $AccountName -AccountPassword $Password -Path "OU=testing,DC=pugazh,DC=in" -Enabled:$true }
-
Powershell: Find Services failed to start after server reboot
[cmdletbinding()] Param( [string[]]$ComputerName = $env:ComputerName ) foreach($Computer in $ComputerName) { if(Test-Connection -Computer $Computer -Count 1 -quiet) { try { $services = Get-WMIObject -Class Win32_Service -Filter "State='Stopped'" -ComputerName $Computer -EA stop foreach($service in $services) { if(!(($service.exitcode -eq 0) -or ($service.exitcode -eq 1077))) { $Error = Invoke-Expression "net helpmsg $($service.Exitcode)" $Service | select Name, Startmode, State, Exitcode,@{Label="Message";Expression={$Error[1]}} } } } catch { Write-Verbose "Failed to query service status. $_" } } else { Write-Verbose "$Computer : OFFLINE" } }
-
Force dns registration on remote computers
([WMIClass]"\\Computer-Name\ROOT\CImv2:Win32_Process").Create("cmd.exe /c ipconfig /registerdns") New-CimSession -ComputerName computer-name | Register-DnsClient
-
List all the installed applications on a given machine
Find the below script to get the all installed application in given server. strHost = "." Const HKLM = &H80000002 Set objReg = GetObject("winmgmts://" & strHost & _ "/root/default:StdRegProv") Const strBaseKey = _ "Software\Microsoft\Windows\CurrentVersion\Uninstall\" objReg.EnumKey HKLM, strBaseKey, arrSubKeys For Each strSubKey In arrSubKeys intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _ "DisplayName", strValue) If intRet <> 0 Then intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _ "QuietDisplayName", strValue) End If If (strValue <> "") and (intRet = 0) Then WScript.Echo strValue End If Next For more Link
-
Powershell script to restore the AD User/computer account in AD after the specified timeline.
$ChangeDate = New-Object DateTime(2019, 4, 15, 12, 00, 02) Get-ADObject -filter ‘whenChanged -gt $ChangeDate -and isDeleted -eq $true’ -IncludeDeletedObjects -properties * | Foreach-Object {Restore-ADObject $_.objectguid -NewName $_.SamAccountName -TargetPath $_.LastKnownParent}
-
Windows PowerShell v2 script to update the account password.
If you have just one account to change, use DSA, LDP.exe or ADSIedit to get it done