First simple code
#()_.Check if Module installed
$name = 'AzureAD'
if (!(Get-Module $name))
{
write-Host "Cannot locate module ($name)" -f DarkGreen
Write-Host 'Script will stop' -f DarkGray
Start-Sleep -Seconds 5
break;
}
|
Second simple code
#()_.load Module if not loaded
$name = 'AzureAD'
if (!(Get-Module $name))
{
write-Host "()_.Importing AzureAD Module" -ForegroundColor DarkYellow
Import-Module $name
write-Host "()_.Completed" -ForegroundColor DarkYellow
}
|
Third Sample
# Module Exist
$name = 'AzureAD'
if (Get-Module $name)
{
write-Host "located
module ($name)" -f DarkGreen
}else{
write-Host "Cannot locate module ($name)" -f DarkGreen
Write-Host 'Script will stop' -f DarkGray
Start-Sleep -Seconds 5
break;
}
|
And final Example
# Module DOES NOT Exist
$name = 'AzureAD!'
if (Get-Module $name)
{
write-Host "located
module ($name)" -f DarkGreen
}else{
write-Host "Cannot locate module ($name)" -f DarkGreen
Write-Host 'Script will stop' -f DarkGray
Start-Sleep -Seconds 5
break;
}
|
Azure Solutions Architect
AWS Certified Cloud Practitioner
https://simplepowershell.blogspot.com
https://cloudsec365.blogspot.com
https://msazure365.blogspot.com
https://twitter.com/Message_Talk
No comments:
Post a Comment