Category: Windows Server

PS (Unfinished): O365 User Exporter For MaaS360

PS (Unfinished): O365 User Exporter For MaaS360

Image result for its broken meme

#############################################
## Global Varibles
#############################################
$script:SelectedPath = $null
$script:PrimaryDomain = $null
$script:PulledUserData = $null
$Script:date = Get-Date -Format ddmmyyhhmm
#############################################
## Functions
#############################################
Function EnvConfiguration () {
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -ErrorAction Stop
Add-Type -AssemblyName PresentationFramework
Add-Type -assemblyName PresentationCore
Add-Type -assemblyName WindowsBase
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
}
Function WelcomeDialouge () {
# Dialouge Box Params
$ButtonType = [Windows.MessageBoxButton]::OKCancel
$MessageIcon = [Windows.MessageBoxImage]::Information
$MessageTitle = "ASB -- O365 CSV Exported For IBM MaaS360 -- Daisy Stevens"
$MessageBody = "Welcome to the O365 Exporter Tool for`nMass User Importation into MaaS360`n `nScript Developed By: Daisy Olivia Stevens`nhttps://adminscriptbank.wordpress.com`nhttps://www.linkedin.com/in/theheroic"
# Dialouge Call
$Result = [Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
if ($Result -eq 'OK'){ConnectO365}
}
Function ConnectO365 (){
# Obtain Creds from User input and then connect to Office 365
Connect-MsolService #-ErrorAction stop
# Move to the next function
Set-DestinationPath
}
function Set-DestinationPath {
$Message = "Please select a directory for your exported data"
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{SelectedPath = 'C:\'}
$FolderBrowser.Description = $Message
[void]$FolderBrowser.ShowDialog()
$FolderBrowser.SelectedPath
if ($FolderBrowser.SelectedPath -eq $null){
# Dialouge Box Params
$ButtonType = [Windows.MessageBoxButton]::OKCancel
$MessageIcon = [Windows.MessageBoxImage]::Error
$MessageTitle = "ASB -- O365 CSV Exporter For IBM MaaS360 -- Daisy Stevens"
$MessageBody = "No Path Was Selected!`nDo you wish to try again?"
# Dialouge Call
$Result = [Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
if ($Result -eq 'OK'){Set-DestinationPath} else {exit}
}
$script:SelectedPath = $FolderBrowser.SelectedPath
PrimaryDomainSelector
}
Function PrimaryDomainSelector {
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "ASB -- O365 CSV Exported For IBM MaaS360 -- Daisy Stevens"
$objForm.Size = New-Object System.Drawing.Size(800,200)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$x=$objListBox.SelectedItem;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$x=$objListBox.SelectedItem;$objForm.Close();PullUserData;})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please Select Your Primary Domain:"
$objForm.Controls.Add($objLabel)
$objListBox = New-Object System.Windows.Forms.ListBox
$objListBox.Location = New-Object System.Drawing.Size(10,40)
$objListBox.Size = New-Object System.Drawing.Size(755,20)
$objListBox.Height = 80
Get-MsolDomain | Select-Object name | ForEach-Object {$_.Name | Add-Content -Path .\o365Domains.tmp}
ForEach($i in (Get-Content .\o365Domains.tmp))
{[void] $objListBox.Items.Add($i)}
$objForm.Controls.Add($objListBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
$script:PrimaryDomain = $objListBox.SelectedItem
$FileName = ".\o365Domains.tmp"
if (Test-Path $FileName)
{
Remove-Item $FileName
}
}
function PullUserData {
$script:PulledUserData = Get-MsolUser -All | Select-Object *
ComposeCSV
}
function CustomInputBox([string] $title, [string] $message, [string] $defaultText) {
[void] [Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$userForm = New-Object System.Windows.Forms.Form
$userForm.Text = "$title"
$userForm.Size = New-Object System.Drawing.Size(800,200)
$userForm.StartPosition = "CenterScreen"
$userForm.AutoSize = $False
$userForm.MinimizeBox = $False
$userForm.MaximizeBox = $False
$userForm.SizeGripStyle= "Hide"
$userForm.WindowState = "Normal"
$userForm.FormBorderStyle="Fixed3D"
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(115,80)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$value=$objTextBox.Text;$userForm.Close()})
$userForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(195,80)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$userForm.Close()})
$userForm.Controls.Add($CancelButton)
$userLabel = New-Object System.Windows.Forms.Label
$userLabel.Location = New-Object System.Drawing.Size(10,20)
$userLabel.Size = New-Object System.Drawing.Size(280,20)
$userLabel.Text = "$message"
$userForm.Controls.Add($userLabel)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objTextBox.Text="$defaultText"
$userForm.Controls.Add($objTextBox)
$userForm.Topmost = $True
$userForm.Opacity = 1.0
$userForm.ShowIcon = $False
$userForm.Add_Shown({$userForm.Activate()})
[void] $userForm.ShowDialog()
$value=$objTextBox.Text
return $value
}
function ComposeCSV {
$UserInputTitle = "ASB -- O365 CSV Exporter For IBM MaaS360 -- Daisy Stevens"
$userInputText = "Please enter your international country code: "
$UserInputDText = "+44"
$userInput = CustomInputBox $UserInputTitle $userInputText $UserInputDText
if ($userInput -eq $null){
$userInput = CustomInputBox $UserInputTitle $userInputText $UserInputDText
}
$Data = New-Object System.Object
$Data | Add-Member -MemberType Property -Name "Full Name" -Value $script:PulledUserData.DisplayName
$Data | Add-member -MemberType Property -Name "User Name" -Value $script:PulledUserData.Signinname
$Data | Add-Member -MemberType Property -Name "Domain" -Value $Domain
$Data | Add-Member -MemberType Property -Name "Email" -Value $script:PulledUserData.signinname
$Data | Add-Member -MemberType Property -Name "Phone Number Country" -Value $userInput
$Data | Add-Member -MemberType Property -Name "Phone Number" -Value $script:PulledUserData.PhoneNumber
$Data | Add-Member -MemberType Property
-Name "Location" -Value "London"
$Data | add-member -MemberType Property -Name "Auth Type" -Value "Local"
$Data | select * | Export-Csv -Path "$script:SelectedPath\Maas360_Export_$script:date.csv" -NoTypeInformation
CompleteMSG
}
function CompleteMSG {
# Dialouge Box Params
$ButtonType = [Windows.MessageBoxButton]::OK
$MessageIcon = [Windows.MessageBoxImage]::Information
$MessageTitle = "ASB -- O365 CSV Exported For IBM MaaS360 -- Daisy Stevens"
$MessageBody = "The Script has completed successfully"
# Dialouge Call
$Result = [Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
if ($Result -eq 'OK'){exit}
}
#############################################
## Function Calls
#############################################
EnvConfiguration
WelcomeDialouge
Advertisements
PS: User Mailbox SMTP Alias Address Report

PS: User Mailbox SMTP Alias Address Report

Hi Everyone,

Here is a quick and dirty script that will produce a table within your terminal session showing you each user mailbox along with any additional SMTP addresses that are associated to each of the mailbox’s

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
# Collect Data from exchange and store into varible
$box = Get-Mailbox | Where {$_.name -NotLike ‘*DiscoverySearchMailbox*’} | Where-Object -Property RecipientType -eq -Value UserMailbox | select primarysmtpaddress,name,@{Name=”EmailAddresses”;Expression={ ($_.EmailAddresses | Where-Object {$_ -cmatch “s mtp:*”} | ForEach-Object {$_ -replace 'smtp:' }) -join ',' }}
# Perform Count of records in varible
$count = $box | measure
# Count Output
Write-Host "Result Count: " -NoNewline -ForegroundColor Green $count.Count
# Result Table Output
$box | ft -autosize

 


Old Code

$UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session Get-Mailbox | Where {$_.name -NotLike ‘*DiscoverySearchMailbox*’} | Where-Object -Property RecipientType -eq -Value UserMailbox | select primarysmtpaddress,name,@{Name=”EmailAddresses”;Expression={ ($_.EmailAddresses | Where-Object {$_ -cmatch “s mtp:*”} | ForEach-Object {$_ -replace ‘smtp:’ }) -join ‘,’ }} | ft -AutoSize

PS: Windows Update

PS: Windows Update

Needing to run Windows Updates on your machine from PowerShell this is the module for you.

https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc

Download and extract the folder a place it in the following directory

%WINDIR%\System32\WindowsPowerShell\v1.0\Modules

Import the module into your PowerShell session

Import-Module PSWindowsUpdate

To download and install windows updates run the following

Get-WUInstall

Screenshot of Module In action

powershell-windows-update-screenshot

Licensing: Activating Servers that cannot reach the Web

Licensing: Activating Servers that cannot reach the Web

Okay, I have been working through the night to meet some deadlines on a few cloud projects at work. One of the challenges I have come across was activating my VM’s reason being they are behind a very strict firewall, therefore cannot activate in the normal sense.

To resolve this I used the Microsoft ADK it includes VAMT (Volume Activation Managment Tool) Which more importantly allows you to perform activation via proxy. It is worth checking out

You can download this from the following link

https://developer.microsoft.com/en-us/windows/hardware/windows-assessment-deployment-kit

volumeactivationforwindows81-18

PowerCLI: Rename Windows Guest OS Hostname

PowerCLI: Rename Windows Guest OS Hostname

Okay, today I had run a script but I had not taken into account the character limit of the Windows hostname. The Result was I had 14 VM’s that are all running with the same hostname and I was not prepared to go into every single VM and change the hostname manually.

So the solution, I had been fishing around the internet for a quick solution to this problem and the solution was to use PowerCli with the Invoke-VMscript command which turns out to be pretty powerful so below is an example of using Invoke-VMscript to change the Windows Hostname

Invoke-VMScript -VM VM-Windows-01 -ScriptType Powershell -ScriptText 'Rename-Computer -NewName VM-WIN-01 -Restart' -GuestUser Administrator -GuestPassword ChangeMe
Invoke-VMScript -VM VM-Windows-02 -ScriptType Powershell -ScriptText 'Rename-Computer -NewName VM-WIN-02 -Restart' -GuestUser Administrator -GuestPassword ChangeMe
Invoke-VMScript -VM VM-Windows-03 -ScriptType Powershell -ScriptText 'Rename-Computer -NewName VM-WIN-03 -Restart' -GuestUser Administrator -GuestPassword ChangeMe