Saturday, April 21, 2018

Check If Mailbox Exist


Below simple code will check to see if mailbox exist, if not script will stop. It is easy to use same logic to setup similar conditions for similar tasks.

Clear-Host
write-host "---------------------------------------" -f Yellow
$targetmb  = Read-Host "()_Please Provide user name"
write-host "---------------------------------------" -f Yellow


#()_.Vars
$sc = "SilentlyContinue"

write-host $null
Write-Host "(-)_.Checking mailbox:[$targetmb]" -f Yellow
$mb = get-mailbox  $targetmb -ErrorAction $sc

if ($mb -eq $null)
{
 write-host "`tThe target mailbox does NOT exist:" -n; Write-Host "[$targetmb ]" -f Red -b Black
break;
else
{
write-host "`tLocated mailbox:" -n; Write-Host "[$targetmb]" -f Green -b Black
}




Casey DeDeal
Azure Certified Solutions Architect 
Principal Systems Engineer
https://msazure365.blogspot.com/ (blog)
https://simplepowershell.blogspot.com/  (blog)
https://twitter.com/Message_Talk (Twitter)



Friday, April 20, 2018

Simple PS code will wait until the log file exist.
#Wait Until File is created

$logfile = "Log file name"
$TargetLogFile = "Path_To_File"

# example      $logfile             = "Test.CSV"
# example      $TargetLogFile =  \\$ServerName\C$\Temp\$logfile"



#()_.Wait for the log file
write-host "()_.Attempting to locate [$logfile]" -f yellow

do{
  
   Write-host "()_.Please wait..." -f Cyan
   Start-Sleep -Seconds 5
   Write-host "()_.{$logfile] not there" -f Yellow

    $path = Test-Path $TargetLogFile
    if (!($TargetLogFile))  
        {Write-Host "()_.[$logfile]  Not here yet..." -f Yellow
        start-sleep -Seconds 5}      
    }
until($path)
    Write-Host "()_.Located [$logfile]" -f Green
    Write-Host "()_.Will continue" -f Yellow






Connect-Azure-PowerShell if there is no existing Connection.

By Using MsolService to connect to Azure PowerShell, could be annoying time to time if unable to validate existing connection. The simpl...