Password policies are a good thing, however as users aren’t chained to their desks anymore they might not realize that their AD password is expiring. Here’s a script that you can run as a scheduled task that will notify users that their password is expiring.

It was roughly copied from a Reddit thread (link) however it had a few bugs relating to fine-grained password policies and was using .NET methods for a few things instead of Powershell cmdlets.

Hope it comes in useful for someone.

Comment and share

It turns out there’s a lot to getting Powershell to connect to FTP servers. Here’s two functions I’ve written that can list FTP contents and download files. Enjoy.

Comment and share

Set-Permissions

Hee’s a basic script I created recently to set permissions on a file/folder. This can be integrated with other scripts quite nicely.

Enjoy!

Comment and share

A nice little one-liner. This assumes you have already ran Connect-MsolService.

1
Get-MsolUser | select firstname,lastname,userprincipalname,islicensed,@{N="License";E={switch -regex ($_.licenses.accountskuid) { ("ENTERPRISEPACK") { "E3" } ("STANDARDPACK") { "E1" } }}} | ft

You can add more switches for more license types but we only use E3 and E1. Types are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"DESKLESSPACK" = "Office 365 (Plan K1)"
"DESKLESSWOFFPACK" = "Office 365 (Plan K2)"
"LITEPACK" = "Office 365 (Plan P1)"
"EXCHANGESTANDARD" = "Office 365 Exchange Online Only"
"STANDARDPACK" = "Office 365 (Plan E1)"
"STANDARDWOFFPACK" = "Office 365 (Plan E2)"
"ENTERPRISEPACK" = "Office 365 (Plan E3)"
"ENTERPRISEPACKLRG" = "Office 365 (Plan E3)"
"ENTERPRISEWITHSCAL" = "Office 365 (Plan E4)"
"STANDARDPACK_STUDENT" = "Office 365 (Plan A1) for Students"
"STANDARDWOFFPACKPACK_STUDENT" = "Office 365 (Plan A2) for Students"
"ENTERPRISEPACK_STUDENT" = "Office 365 (Plan A3) for Students"
"ENTERPRISEWITHSCAL_STUDENT" = "Office 365 (Plan A4) for Students"
"STANDARDPACK_FACULTY" = "Office 365 (Plan A1) for Faculty"
"STANDARDWOFFPACKPACK_FACULTY" = "Office 365 (Plan A2) for Faculty"
"ENTERPRISEPACK_FACULTY" = "Office 365 (Plan A3) for Faculty"
"ENTERPRISEWITHSCAL_FACULTY" = "Office 365 (Plan A4) for Faculty"
"ENTERPRISEPACK_B_PILOT" = "Office 365 (Enterprise Preview)"
"STANDARD_B_PILOT" = "Office 365 (Small Business Preview)"

Comment and share

Email2SMS

We’ve switched SMS providers at work to Nexmo, however they don’t have a SMTP API. I whipped up a quick EWS script to monitor a mailbox for emails in the correct format and to send SMS’ based off it. Script below.

The script should be run as the user whos mailbox will be monitored (ours is set up as a scheduled task). Next, it should have to subfolders called “Error” and “Processed”. Successful emails get marked as read and send to “Processed”, and unsuccessful emails get kept as unread and moved to “Error”. Because we send from some systems that don’t have SMTP authentication, there is a field called “Secret” that should be defined at the top of the PowerShell script and put in each email.

The format for the email is:

1
2
3
4
From: fromuser
To: number in international format (ie. +61404040404)
Text: any text here
Secret: secret code defined in script

The script is set to run every 20 seconds.

Comment and share

This isn’t really documented anywhere on the VMware website, but it comes in really handy if require certain users to have console access to machines without the complication of the vSphere Web Client.

  • Install VMware Player from the VMware website

  • Get the Managed Object ID of the VM. This can be done through PowerCLI with the following script:

1
2
3
4
5
6
7
8
9
$vcenter = "vcenter.domain.name"
$targetvm = "targetvm"
Add-PSSnapin VMware.VimAutomation.Core
Connect-VIServer -Server $vcenter -Force
$vmid = (Get-VM $targetvm).id -replace "VirtualMachine-",""
Disconnect-VIServer -Server $vcenter -Confirm:$false
Write-Output "VM MOID is $vmid"
  • Give the user access to the VM. The permission “Virtual Machine\Interaction\Console Interation” needs to be given on both the VM and the host. It doesn’t need to inherit to children so deselect “Propagate to children” in the permisisons screen”.

  • Create a shortcut to connect straight to the VM. The following PowerShell script can create the shortcut automatically.

1
2
3
4
5
6
7
8
9
$desktop = [Environment]::GetFolderPath("Desktop")
$vcenter = "vcenter.domain.name"
$targetvm = "targetvm"
$vmid = "vm-moid"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$desktop\$targetvm.lnk")
$Shortcut.TargetPath = "vmrc://$vcenter/?moid=$vmid"
$Shortcut.Save()

Afterwards, double click on the shortcut on the desktop and enter appropriate credentials. You’ll be straight in to the console.

Comment and share

Jacob Ludriks

Nerd


System Administrator


Australia