Total Pageviews

Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts

Wednesday, September 15, 2021

Azure cmdlets required for day today work


# Force policies to start , will take around 15minutes 

Start-AzPolicyComplianceScan -ResourceGroupName "cloud*"


#Delete az resources

Get-AzResourceGroup -Name 'Ne*' | Remove-AzResourceGroup -Force -AsJob


#Policy Related

Get-AzPolicyDefinition | Where-Object { $_.Properties.DisplayName -eq "Allowed virtual machine size SKUs" }

New-AzPolicyAssignment -Name "VMCheckingRule" -DisplayName "Checking the Rule" -Scope $rg1.Resourceid -PolicyDefinition $def


#Create new resources Group

New-AzResourceGroup -Name "MyNewRG" -Location "East US"

Get-AzResourceGroup -Name "MyNewRG"


#Check PS Version

Get-Host | Select-Object Version


#Conncet local machine to AZ portal

Install-Module -Name Az -AllowClobber -Repository PSGallery -Force

Connect-AzAccount


#new Resource group

New-AzResourceGroup -Name "NewTest" -Location "East US"


#Create Vertual Machine

New-AzVM -ResourceGroupName "NewTest" -Name "MyVM1" -Location "East US" -VirtualNetworkName "VMnet1" -SubnetName "sub1" -SecurityGroupName "NewSG" -PublicIPAddressName "myIpaddress" -OpenPorts "3389"


#Stop the VM

Stop-AzVM -ResourceGroupName "NewTest" -Name "MyVM1"


#Start the VM

Start-AzVM -ResourceGroupName "NewTest" -Name "MyVM1"


#Install Web-Server & display Hellow world

powershell.exe Install-WindowsFeature -name Web-Server -IncludeManagementTools && powershell.exe remove-item 'C:\\inetpub\\wwwroot\\iisstart.htm' && powershell.exe Add-Content -Path 'C:\\inetpub\\wwwroot\\iisstart.htm' -Value $('Hello World from ' + $env:computername


#Crete New Z: disk on VM

New-StoragePool -FriendlyName storagepool1 -StorageSubsystemFriendlyName "Windows Storage*" -PhysicalDisks (Get-PhysicalDisk -CanPool $true)

New-VirtualDisk -StoragePoolFriendlyName storagepool1 -FriendlyName virtualdisk1 -Size 2046GB -ResiliencySettingName Simple -ProvisioningType Fixed

Initialize-Disk -VirtualDisk (Get-VirtualDisk -FriendlyName virtualdisk1)

New-Partition -DiskNumber 4 -UseMaximumSize -DriveLetter Z


#GetVM Public ip adress

(Get-AzPublicIpAddress -ResourceGroupName $rgName -Name $lbpipName).IpAddress


#Create a managed image of a generalized VM in Azure

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/capture-image-resource#code-try-1


#Get azure avaialable image list

az vm image list --output table


#redeploy a VM

Set-AzureRmVm -Redeploy -ResourceGroupName NewTest -Name MyVM1 




Monday, June 3, 2019

[Powershell] Managing O365 with Powershell

1) Installing the O365 online module

  • Download Powershell online module from this link : http://aka.ms/t01i1o
  • Under Microsoft Online Services Sign-In Assistant for IT Professionals RTW, click Download.
  • select the en\msoidcl_64.msi check box, click Next, and then click Save.Wait for the download to finish.When the download finishes, click Run.
  • In the Microsoft Online Services Sign-in Assistant Setup wizard, click I accept the terms in the license Agreement and Privacy Statement, and then click Install.If a User Account Control dialog box appears, click Yes.
  • On the Completed the Microsoft Online Services Sign-in Assistant Setup Wizard page, click Finish.
  • Then Right click on Start and click Windows PowerShell (Admin)
  • At the prompt, type Install-ModuleMSOnline command.
  • If prompted to install the NuGet provider, type Y and press ENTER.
  • If prompted to install the module from PSGallery, type Y and press ENTER
2) Create new users and assign licenses

  • At the Powershell, type the following command to connect
Connect-MsolService
  • In the Enter Credentials dialog box sign in

2.1) Create New User

New-MsolUser -UserPrincipalName Catherine@LODSA904072.onmicrosoft.com -DisplayName "Catherine Richard" -FirstName "Catherine" -LastName"Richard" -Password 'Pa55w.rd' -ForceChangePassword $false -UsageLocation "CH" 

2.2) Checking the un-licensed user

Get-MsolUser -UnlicensedUsersOnly

2.3) View the available licenses

Get-MsolAccountSku

2.4) Add Licenses to a user

Set-MsolUserLicense UserPrincipalName  catherine@LODSA904072.onmicrosoft.com AddLicenses "LODSAxxxxxx:ENTERPRISEPREMIUM"

2.5) Prevent a user from signing in


Set-MsolUser -UserPrincipalNameCatherine@LODSA904072.onmicrosoft.com -BlockCredential $true

2.6) To allow a user to sign in


Set-MsolUser -UserPrincipalNameCatherine@LODSA904072.onmicrosoft.com -BlockCredential $false

2.7) Delete a user

Remove-MsolUser -UserPrincipalNameCatherine@LODSA904072.onmicrosoft.com -Force

2.8) view the Deleted Users 

Get-MsolUser -ReturnDeletedUsers

2.9) Restore a deleted user

Restore-MsolUser -UserPrincipalNameCatherine@LODSA904072.onmicrosoft.com

2.10) view the active users list

Get-MsolUser


3) Modify user accounts

3.1) To bulk import several users from a comma-separated value (CSV) file

Import-Csv -PathC:\labfiles\O365Users.csv | ForEach-Object { New-MsolUser -UserPrincipalName$_."UPN" -FirstName $_."FirstName" -LastName $_."LastName" -DisplayName$_."DisplayName" -BlockCredential $False-ForceChangePassword $False -Password$_."Password" -PasswordNeverExpires$True -Title $_."Title" -Department$_."Department" -Office $_."Office" -PhoneNumber $_."PhoneNumber" -MobilePhone $_."MobilePhone" -StreetAddress $_."StreetAddress" -City$_."City" -State $_."State" -PostalCode$_."PostalCode" -Country $_."Country" }

It is recommended that you use the type/text feature in a Notepad first and from there to copy and then paste this code into your PowerShell session.


4) Configure groups and group membership


4.1) Create a group

New-MsolGroup -DisplayName "Marketing" -Description "Marketing department users"

4.2) Configure a variable for the group add user to the group

$MktGrp = Get-MsolGroup | Where-Object{$_.DisplayName -eq "Marketing"}

$Catherine = Get-MsolUser | Where-Object{$_.DisplayName -eq "Catherine Richard"}

Add-MsolGroupMember -GroupObjectId$MktGrp.ObjectId -GroupMemberType "User"-GroupMemberObjectId $Catherine.ObjectId


4.3) To verify the members of the group



Get-MsolGroupMember -GroupObjectId$MktGrp.ObjectId


5) Configure user passwords

5.1) Set Passwords

Set-MsolUserPassword -UserPrincipalName"Tameka@LODSA904072.onmicrosoft.com" -NewPassword 'Pa55w.rd'

5.2) Set password to never expire

Get-MsolUser | Set-MsolUser -PasswordNeverExpires $false


6) Manage service administration 

6.1) Assigning Roles

Add-MsolRoleMember -RoleName "Service Support Administrator" -RoleMemberEmailAddress"Sallie@LODSA904072.onmicrosoft.com"

Add-MsolRoleMember -RoleName "Company Administrator" -RoleMemberEmailAddress"Amy@LODSA904072.onmicrosoft.com"

6.2) Get the members who has Service Support Administrator role assigned

$role = Get-MsolRole -RoleName "Service Support Administrator"

Get-MsolRoleMember -RoleObjectId$role.ObjectId


Azure Pricing

  Azure offers pay-as-you-go and reserved instances for pricing. Azure Pricing Factors: Resource size and resource type. Different Azure loc...