$ADgroup = "testgroup"
Get-ADGroupMember $ADgroup | ForEach-Object {Remove-ADGroupMember $ADgroup $_ -Confirm:$false}
Remove all members from AD group
Reply
$ADgroup = "testgroup"
Get-ADGroupMember $ADgroup | ForEach-Object {Remove-ADGroupMember $ADgroup $_ -Confirm:$false}
param ($servername)
$ignorelist = "MapsBroker","RemoteRegistry","sppsvc","WbioSrvc","BITS","ShellHWDetection","TrustedInstaller"
if ($servername.length -lt 2) { $Servername = Read-Host -Prompt 'Input the servername' }
# Check for name is IP
$checkIP = [bool]($servername -as [ipaddress])
# Check DNS resolve
if (!($checkIP)) {
$DNScheck = Resolve-DnsName $servername -ErrorAction SilentlyContinue
if ($DNScheck.length -lt 1) {
Write-host "Unable to resolve DNS name" -ForegroundColor Red
Exit 1}
}
Invoke-Command -ComputerName $servername -ArgumentList $ignorelist -ScriptBlock { $NotRunningServices = Get-Service | Where-Object { $_.Starttype -like "Automatic*" -and $_.status -notlike "Running" }
foreach ($NotRunningService in $NotRunningServices) {
if (!($args.Contains($NotRunningService.name))) {
Start-service $NotRunningService.name -ErrorAction SilentlyContinue
sleep -Milliseconds 500
if ((Get-service -Name $NotRunningService.name).status.value__ -ne 4 ) { Write-host "Failed to start" $NotRunningService.name -ForegroundColor Red }
else { Write-host "Succeded starting" $NotRunningService.name -ForegroundColor Green }
}
} }
while (!(Get-ADgroup -Filter { Name -like "the_AD_object"}))
{
write-host wait
start-sleep -m 1000
}
#Allow remote powershell
Enable-PSRemoting -Force
Enable-WSManCredSSP -Role Server -Force
Get-Service winrm | Start-Service
Enable-WSManCredSSP -Role Client -DelegateComputer * -Force
Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\Credssp\PolicyDefaults\AllowFreshCredentials -Name WSMan -Value WSMAN/*
Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\Credssp\PolicyDefaults\AllowFreshCredentialsDomain -Name WSMan -Value WSMAN/*
#Test from an other machine:
Invoke-Command -ComputerName Remote-Server -ScriptBlock {Get-host}
#Allow crossdomain:
#On remote server do the above and:
New-Itemproperty -name LocalAccountTokenFilterPolicy -path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -propertyType DWord -value 1
#On remote and local machine run:
Set-item wsman:localhost\client\trustedhosts -value 'server1,server2,server3'
#Test from an other machine:
$credential = Get-Credential
Invoke-Command -ComputerName RM-SERVER -ScriptBlock {Get-Process} -Credential $credential
Event Viewer
Filter System log for event id: 1074
Username: nsroot
Password: nsroot
For($i = 1; $i -le 100; $i++)
{
Write-Progress -Activity "Progress bar" -status "Done $i" -percentComplete ($i)
write-host $i
Start-Sleep -s 2
}
$sn = "CZC12068T4"
$country = "DK"
$body = "rows%5B0%5D.item.serialNumber=" + $sn + "&rows%5B0%5D.item.countryCode=" + $country + "&rows%5B1%5D.item.serialNumber=&rows%5B1%5D.item.countryCode=US&rows%5B2%5D.item.serialNumber=&rows%5B2%5D.item.countryCode=US&rows%5B3%5D.item.serialNumber=&rows%5B3%5D.item.countryCode=US&rows%5B4%5D.item.serialNumber=&rows%5B4%5D.item.countryCode=US&rows%5B5%5D.item.serialNumber=&rows%5B5%5D.item.countryCode=US&rows%5B6%5D.item.serialNumber=&rows%5B6%5D.item.countryCode=US&rows%5B7%5D.item.serialNumber=&rows%5B7%5D.item.countryCode=US&rows%5B8%5D.item.serialNumber=&rows%5B8%5D.item.countryCode=US&rows%5B9%5D.item.serialNumber=&rows%5B9%5D.item.countryCode=US&submitButton=Submit"
$r=Invoke-WebRequest -Uri ("http://h20564.www2.hp.com/hpsc/wc/public/find") -Method POST -Body $body
$ss = $r.RawContent.IndexOf("Wty: HP Support for Initial Setup")
# Extra run, in case of not found.
if($ss -lt 100) {
$r=Invoke-WebRequest -Uri ("http://h20564.www2.hp.com/hpsc/wc/public/find") -Method POST -Body $body
$ss = $r.RawContent.IndexOf("Wty: HP Support for Initial Setup")
}
if($ss -gt 100) {
$result = $r.rawcontent.substring($ss+42,20)
$end = $result.IndexOf("</")
$result = $result.Substring(0,$end)
get-date -Date $result -UFormat "%Y/%m/%d"
}
else {
$result = "not found"
$result
}