6Foot2 Posted January 25, 2018 Posted January 25, 2018 Starting this thread with a script from another thread that I will find useful from time-to time: Not brill, but this powershell script does show the last logon times for computersI run this from one of my Domain Controllers.Get-ADComputer -Filter * -Properties * | Sort LastLogonDate | FT Name, LastLogonDate -Autosize | Out-File C:\ComputerLastLogonDate.txt 1
mdrabble Posted January 25, 2018 Posted January 25, 2018 I have this script for check on-premise mailbox sizes Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn $DateStamp = get-date -uformat "%d-%m-%Y" $filename = 'D:\' + $DateStamp + '_MailBox_Sizes.txt' #change exch-01 to your server name Get-MailboxStatistics -Server exch-01 | where {$_.ObjectClass –eq “Mailbox”} | Sort-Object TotalItemSize –Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}},@{label=”Items”;expression={$_.ItemCount}},@{label=”Storage Limit”;expression={$_.StorageLimitStatus}} -auto >>$filename
mdrabble Posted January 25, 2018 Posted January 25, 2018 I found these somewhere (cannot remember where) and amended to suit. I use the following scripts to randomly set a password on the user for the guest wifi Part 1 - Scheduled at 4pm each day to set a randomly generated password and email details to relevant people such as main office. GuestWifi.ps1 write-host "Importing CreatePassword.ps1" . ".\CreatePassword.ps1" $newPassWord = Create-RandomPassword Set-ADAccountPassword -Identity "CN=Visitor,OU=SOME OU NAME,DC=DOMAIN" -reset -NewPassword (ConvertTo-SecureString -AsPlainText $newPassword -Force) [string]$body = @() $date = (Get-Date).AddDays(1).ToString('dddd d MMMM yyyy') #change this line $smtp = "SMTP_SERVER_DETAILS_HERE" #change thi lin [string[]]$to = "[email protected]","[email protected]" #change this line $from = "NAME " $subject = "Daily Password change for Guest Wifi Account" $body ="" $body += "These details may be printed out and handed to Visitors who may wish to use our Guest Wifi. " #### $body += "Anyone who wishes to use the Guest Wifi will need the following details: " $body += "Joining the Guest_Wifi " $body += "1. On your device, select the Guest_Wifi " $body += "2. When prompted for a username and password, use the following details " $body += "Username: Visitor " $body += "Password: $newPassword " #change this line $body += "3. Accept/Trust the Authentication Certificate from RADIUS SERVER NAME " $body += "4. Read and follow the details on the Guest Wifi Page. " $body += "Once all the necessary certificates are installed you will be able to use the internet (subject to our Acceptable Usage Policy " $body += "These details will become invalid at 4pm on $date " $body += "If you have any questions or concerns, please speark to a member of the IT Support team. " $body += "Many thanks " $body += "IT Support" send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high ########### End of Script################ Part 2 - Script to called to generate password CreatePassword.ps1 function Create-RandomPassword ( [int] $minLength = 8, [int] $maxLength = 8, [bool] $useSymbols = $false, [bool] $asSecureString = $false ) { [system.Security.Cryptography.RNGCryptoServiceProvider] $random = new-object System.Security.Cryptography.RNGCryptoServiceProvider # Get an array of all characters that can be used in the password [string] $choice = Get-CharacterChoice -useSymbols $useSymbols $randomPassword = $null if (($minLength -le $maxLength) -and ($minLength -ge 6)) { # Allocate a byte array of dimension 1 $randomNumber = new-object byte[] 1 if ($minLength -eq $maxLength) { [int] $length = $minLength } else { # Calculate a random length between minLength and maxLength $random.GetBytes($randomNumber) [int] $length = $minLength + $randomNumber[0] % ($maxLength - $minLength + 1) } # Allocate a byte array of dimension $length $randomSequence = new-object byte[] $length $hasUCase = $hasLCase = $hasNum = $false while(!$hasUCase -or !$hasLCase -or !$hasNum) { # Generate random sequence of bytes $random.GetBytes($randomSequence) # Ensure that there is at least one number, uppercase # character and lowercase character in the sequence. $hasUCase = $hasLCase = $hasNum = $false foreach($b in $randomSequence) { [char]$char = $choice[$b % $choice.Length] if ($char -ge 'A' -and $char -le 'Z') { $hasUCase = $true } if ($char -ge 'a' -and $char -le 'z') { $hasLCase = $true } if ($char -ge '0' -and $char -le '9') { $hasNum = $true } } } if ($asSecureString) { $randomPassword = new-object System.Security.SecureString } else { [string] $randomPassword = '' } # Assign the password from the sequence of random bytes foreach($b in $randomSequence) { [char]$char = $choice[$b % $choice.Length] if ($asSecureString) { $randomPassword.AppendChar($char) } else { $randomPassword += $char } } } return $randomPassword } # Outputs an array of all the characters that the generated password # can be made up of. function Get-CharacterChoice ( [bool] $useSymbols = $true ) { if ($useSymbols) { [string] $choice = '!"#$%&''()*+,-./' } else { [string] $choice = '' } $choice += '23456789' if ($useSymbols) { $choice += ':;<=>?@' } $choice += 'ABCDEFGHJKMNPQRSTUVWXYZ' if ($useSymbols) { $choice += '[\]^_`' } $choice += 'abcdefghjkmnpqrstuvwxyz' if ($useSymbols) { $choice += '{|}~' } return $choice }
Bedders Posted January 26, 2018 Posted January 26, 2018 Quick and simple command to find which mailbox an email address is associated with in Exchange Management Shell: Get-Recipient [email protected] 1
6Foot2 Posted January 26, 2018 Author Posted January 26, 2018 Quick and simple command to find which mailbox an email address is associated with in Exchange Management Shell: Get-Recipient [email protected] That's the sort of thing!
Arthur Posted January 29, 2018 Posted January 29, 2018 This script will ping every device in the specified IP range in literally a second or two! $IPs = 1..255 | ForEach-Object { "[color="#FF0000"]192.168.0[/color].$_" } $t = $IPs | ForEach-Object {(New-Object Net.NetworkInformation.Ping).SendPingAsync($_, 250)}; [Threading.Tasks.Task]::WaitAll($t); $t.Result | Select-Object Address, Status, RoundTripTime | ForEach-Object {if ($_.Status -eq "Success") {$_}} Source: https://twitter.com/mrhvid/status/929717169130176512/
bicky Posted January 29, 2018 Posted January 29, 2018 List all the groups the user is member of Get-ADPrincipalGroupMembership -Identity username | select name, groupcategory, groupscope | Out-GridView Count number of users in an OU (Get-ADUser -Filter * -SearchBase "OU=staff,OU=myusers,DC=mydomain,DC=com").count Search DHCP by Mac Address Get-DhcpServerv4Scope | Get-DhcpServerv4Lease -EA SilentlyContinue | Where-Object clientid -match '00-1a-2b-3c-44-5a' Following will list all the devices whose Mac address starts with "00-1a" Get-DhcpServerv4Scope | Get-DhcpServerv4Lease -EA SilentlyContinue | Where-Object clientid -match '00-1a' 2
Bedders Posted May 15, 2018 Posted May 15, 2018 (edited) Get a list of all Distribution Groups that have "Require that all senders are authenticated" ticked, so that external emails cannot be received. (Please note: Exchange 2007, Forest Functional Level 2000 native. No hate, please ) Get-DistributionGroup | Where-Object {$_.RequireSenderAuthenticationEnabled -eq "True"} | Sort-Object -Property Name | Format-Table Name, PrimarySMTPAddress Edited May 15, 2018 by Bedders
Latham Posted May 15, 2018 Posted May 15, 2018 The day I finally managed to get this powershell script to remotely change a name of a network machine, it was the greatest day of my life. For M. Bison it was...Tuesday. Does require a domain admin account and password to send the command. If the machine is logged on it sends a message on screen saying that said user is about to remotely log them off. Would recommend only doing it to machines that are logged off. # Asks user to input old PC name $oldComputerName = Read-Host -Prompt 'Please type in the PC you wish to rename' # Asks user to input desired new name for PCSI $newComputerName = Read-Host -Prompt 'What do you want to name this PC as?' # Requests username $domainUser = Read-Host -Prompt 'Insert Username - please use "domainname\" prefix' # Asks a password for the user $password = Read-Host -assecurestring "Please enter your password" $password = [system.Runtime.InteropServices.Marshal]::PtrToStringAuto([system.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) # Asks a password for the user netdom renamecomputer $oldComputerName /newname:$newComputerName /userD:$domainUser /passwordD:$password /force /reboot
HPlum78 Posted May 16, 2018 Posted May 16, 2018 (edited) Notes rather than a PS command(s) first is the initial post from @DaveP the Get-ADComputer -Filter * -Properties * you should really try not to run any command with a -Filter * and -Properties * it is just bad (ask Don Jones for his thoughts on running that very command). It can be scoped with little effort as all the details are in the command and would look like Get-ADComputer -Filter * -Properties Name, LastLogonDate | Sort LastLogonDate | FT Name, LastLogonDate -Autosize | Out-File C:\ComputerLastLogonDate.txt next is for @Latham Does require a domain admin account and password that scares me and that's all am I going to say on that! Edited May 16, 2018 by HPlum78
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now