Friday, March 12, 2021

PowerShell for Scale Up and Scale down service plan on Azure - Runbook

 If as azure admin you want to scale up and scale down your azure service plan environment during the weekend for saving a cost so this power shell can help you to create runbook


Main Command


Set-AzureRMAppServicePlan -Tier Standard -Name "serviceplanname" -ResourceGroupName "nameoftheresource"

Specifically:

-Tier identifies the type of Tier that we want to set: free, shared, basic, standard or premium

-Name allows us to specify the type of Tier we need, for example if the Tier is Standard, the Name could be S1, S2 or S3

Tier parameter

Free  - F1

Shared - D1

Basic = B1

Standard = S

Premium  = P

You can use below Script in runbook. Change the value for $resourceGroupName  and $appServiceName and pass the -Tier Free\Shared\Basic

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

$resourceGroupName = "XXXXXXXX"
$appServiceName = "XXXXXX"
 
filter timestamp {"[$(Get-Date -Format G)]: $_"}
Write-Output "Script started." | timestamp
 
#Authenticate with Azure Automation Run As account (service principal)  
$runAsConnectionProfile = Get-AutomationConnection `
-Name "AzureRunAsConnection"
Add-AzureRmAccount -ServicePrincipal `
-TenantId $runAsConnectionProfile.TenantId `
-ApplicationId $runAsConnectionProfile.ApplicationId `
-CertificateThumbprint ` $runAsConnectionProfile.CertificateThumbprint | Out-Null
Write-Output "Authenticated with Automation Run As Account."
 
#Modifying size of AppService Plan
Set-AzureRMAppServicePlan -Tier Free -Name "HendtestAppSerplan" -ResourceGroupName "RG-Dormakaba"
# Get the App Service object and show its new state
$appService = Get-AzureRmAppServicePlan -ResourceGroupName $resourceGroupName -Name $appServiceName
Write-Output "App Service Plan name: $($appService.Name)" | timestamp

Write-Output "Current App Service Plan status: $($appService.Status), tier: $($appService.Sku.Name)" | timestamp

 

 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Reference Link : https://techoosolutions.wordpress.com/2017/02/02/change-azure-appserviceplan/ 


Saturday, June 20, 2020

How to delete mount drive in windows 10 and server from Power Shell



Run below command in power-shell

1. Check the Mount folder permission and if don't have full access then give full access to user.




2.  Redirect the power-shell console to mount folder and close open mount folder.
        
    Ex -   CD C:\Setup\Mount

3.  Run Command:  Dism /cleanup-wim



4.   Now you see mount folder is empty and you can easily shift and delete the mount folder.

5.   Some case you need to reboot the machine.

Thursday, June 11, 2020

My Review on "Hydration Kit For Windows Server 2016 and ConfigMgr Current" is 5 ***** 😊

 
Johan Arwidmark has created Hydration Kit for creating a SCCM LAB.This automation magic tool kit completely reduce your manual effort and gives you standard lab environment in minimum 3 hours.If you are SCCM admin and want to create a lab so i will suggest use below link.
 
Link is:


What some conman mistake we do when we follow the the lab instructions and it lead to stupid errors.I am just discussing some mistakes i did .Which can be help some one..

1.    Create WIM file carefully use latest patch with 3.5 .net frame work.

2.    In case you get below error prompt after running DC01 and CM01 task sequence so please refer below Johan Arwidmark blog  for resolution.
 
Error : Failed to save environment to (80070057)




3.  Error on CM01 "extadsch.exe mfc120.dll missing".(May be Redistributable not installed or got corrupt ) 

          


You need to install Visual C++ Redistributable for Visual Studio 2015 x64 and x86 both in task sequence before config manager prerequisites or this you can download and install during the task sequence is running.

4.  While creatinga deployment share  if you get WARNING: MDT 8456 not installed, aborting...
in power shell script and you already installed MDT but still you are facing the issue .It means version miss match.You can comment this line or match the exact version you have install.
 
5.  Keep running DC01 once you are creating CM01 task sequence .





Wednesday, June 3, 2020

IMP - WMI & Powershell Commands


Remote session using Psexec 

PSEXEC \\hostname -s -h -d powershell.exe "enable-psremoting" -force

For enabling the PS session for remote machine

Enter-PSSession -ComputerName RDP-xxxxxx-VSB
Enable-PSRemoting -Force
winrm quickconfig    #### Enable remote service

Wmi Query : Run Command on power shell console for system info

Get-WmiObject -List
wmic CSProduct list
wmic CSproduct get model
wmic CSproduct get version
Wmic os list brief

Get-WmiObject -Class Win32_OperatingSystem
WMIC COMPUTERSYSTEM GET /?
Install-Module PSWindowsUpdate -force
Get-wmiobject win32_computersystem -computer $_ | select-object systemtype
(Get-WmiObject Win32_OperatingSystem).OSArchitecture

Nomad client:

C:\Program Files\1E>nomadbranch.exe>  /relicense=XXX-XXXX-XXXX-XXXX
CacheCleaner.exe -deletepkg=cp100372 -pkgver=19    
Get-Service -Name NomadBranch -ComputerName CHE-DAA0218-01 | Restart-Service
C:\Program Files\1E\NomadBranch>CacheCleaner.exe -MaxcacheAge=30 
Pending reboot machine

SCCM Client And Sys Registry:

Get-WmiObject -Namespace root\ccm -Class * -List
Get-WmiObject -namespace root\ccm -class sms_client -computername RDP-cxy0801-vsb
Get-WmiObject -Namespace root\ccm -Class SMS_Client
Get-WmiObject -Query "SELECT * from Win32_bios"
Get-WmiObject -List
GET install product 
Get-WmiObject -Class Win32_Product -ComputerName RDP-   XXXX-vsb
Get-WmiObject -Class Win32_product -ComputerName RDP-CXY0801-VSB | Where {$_.Name -match 'SQL' }
Get-WmiObject win32_product | where {$_.Name -match 'office'} | select name, version
Get-WmiObject win32_product -ComputerName RDP-CXY0801-VSB | where {$_.Name -match 'office'} | select name, version

Invoke-command -computer BLR-P-CMSS01 {Get-ItemProperty HKLM:\Software\1E\NomadBranch\ | select SpecialNetShare,SigsFolder}

Invoke-WMIMethod -ComputerName RDP-CXY0801-V76 -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000108}"

Get-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select DisplayName,version
 
Delete Reg:

Invoke-Command -ComputerName xxx-xxx-xxx -ScriptBlock {Remove-Item -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{083988D7-BDA9-4244-983B-409A634BBC09}' -Confirm:$false}

WindowsVersion:

Invoke-command -computer BLA-BXK0815-1 {(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ReleaseId).ReleaseId}  

System Info:

wmic computersystem get model,name,manufacturer,systemtype

GET OU detail:

Get-ADComputer -Filter "Name -like 'BLR-CXY0801*'"
Invoke-CimMethod -Namespace root/ccm/ClientSDK -ClassName CCM_ClientUtilities -MethodName DetermineIfRebootPending

Get WMI classes:

Get-CimClass
Get-CimClass -ClassName win32*
Get-CimClass -ClassName win32* | where CimClassMethods -ne $null  | select CimClassName,CimClassMethods

Get-WmiObject -Query 'Select * From Meta_Class WHERE __Class LIKE "win32%"' | Where-Object { $_.PSBase.Methods } | Select-Object Name, Methods

Get-WmiObject -List | Where { $_.name -match 'User'}
gwmi win32_product -Filter "Name like 'google%'"  | ft name, version, ident*,vendor,caption

Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.DisplayName -match 'amazon'} | Select-Object -Property DisplayName,DisplayVersion,UninstallString,Publisher | FT

Invoke Command:

Get-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select DisplayName,version

Set-ItemProperty -Path hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Ext\CLSID -Name '{B3A6DA95-9243-48E9-AF2E-52F4FF155B9D}' -Value 1 -Type STRING

Invoke-Command -cn wfe0,wfe1 -ScriptBlock {Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName, Publisher, InstallDate

Tuesday, May 26, 2020

Power-Shell imp links and command

Power-Shell Web Access:


Powers shell basic command:

Get-Command
Get-Help
Get-Member
Find-Module 

Power shell Installed Module prerequisites:
 
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

PowerShell to install Hyper-V Role in server:

Enable-WindowsOptionalFeature -Online -FeatureName:Microsoft-Hyper-V -All

Remove Hyper-v Role:

DISM /Online /Disable-Feature:Microsoft-Hyper-V
  

CMD DISM command:Remove Hyper-v Role:

DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V
Install-WindowsFeature -Name Hyper-V -ComputerName -IncludeManagementTools -Restart  


Power shell command to install Google chrome in server and windows 10:

$LocalTempDir = $env:TEMP; $ChromeInstaller = "ChromeInstaller.exe"; (new-object    System.Net.WebClient).DownloadFile('http://dl.google.com/chrome/install/375.126/chrome_installer.exe', "$LocalTempDir\$ChromeInstaller"); & "$LocalTempDir\$ChromeInstaller" /silent /install; $Process2Monitor =  "ChromeInstaller"; Do { $ProcessesFound = Get-Process | ?{$Process2Monitor -contains $_.Name} | Select-Object -ExpandProperty Name; If ($ProcessesFound) { "Still running: $($ProcessesFound -join ', ')" | Write-Host; Start-Sleep -Seconds 2 } else { rm "$LocalTempDir\$ChromeInstaller" -ErrorAction SilentlyContinue -Verbose } } Until (!$ProcessesFound)

Thursday, June 13, 2019

Microsoft Teams Deployment and auto-start disable configuration


I am working on MS Teams packages. I need to put some points in front of you guys before you design team deployment in your organization because if we want to change something  in package after deployment. It’s not going to be easy because
Teams application installing file under ALLUSERSPROFILES and cleanup of MS teams not going to easy from users profile.

Microsoft teams has provided EXE and MSI installer. Here MS has given 32 bit and 64 bit MSI file for deployment and i opt  MSI installer for creating package.

Prerequisite

Target computer requirements must be
  • .NET framework 4.5 or later
  • Windows 7 or later
  • 3 GB of disk space for each user profile (recommended)

Microsoft says here “The architecture (32-bit vs. 64-bit) of Microsoft Teams is agnostic to the architecture of Windows and Office that is installed.”
It means teams software is not dependent of Office version architecture installed on machine weather it installed 32 bit or 64 bit. You can install 32 bit or 64 bit teams as per your organization convenience.
I have done some research on this options and found for safer side we should install 32 bit teams on 32 office and 64 bit teams on 64 bit office suite because we have some plugin’s and it may be affect if we will install 64 bit teams over 32 bit office suite. Example like Avaya, SmartView, AFO.

MS forum discussion for 32 bit and 64 bit


Here We have written a logic in wrapper master script.
We are installing Teams MSI file as per the office architecture is installed on the local machines. If 32 bit office has installed then it will be install 32 bit teams and if office is 64 bit then it will install 64 bit teams.
For office 365 deduction in local machine. I are checking “HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configurationplatform value .All the office 365 suite has this registry value in the system. In case this key is not available because of XYZ reason so master wrapper script will by default install 32 bit team MSI on the machines. After installation machine need to reboot or log off for launching  the teams .it starts automatically once user login in to the machine.

Auto update

Clients are currently updated automatically by the Microsoft Teams service with no IT administrator intervention required.
If an update is available, the client will automatically download the update and when the app has idled for a period of time, the update process will begin.

Desktop shortcut

Team is putting shortcut on desktop after rebooting or log-off the machine and it’s on user profile desktop so we cannot delete it from VBS. May be one more desktop shortcuts on SBD machines.

VDI Environment 

    MS recommend the 64-bit version for a VDI VM on 64-bit operating system.

Here we have to install 64 bit teams on 32 bit office suite. I have created different master script for VDI machine which will deduct OS version and install the teams msi as per the architecture of the machine.
   More info here on VDI machine.

One more this we are getting two Add and Remove program Entry after installation Team from MSI file..

Deployment link from MS

How to Disable AutoStart permanently while every time user login


Here is my comments for Teams auto launch. Microsoft has provided the property to disable Teams auto launch only for first time login.
Once users has launch Teams manually from desktop then after every login it will launch automatically like skype because it made change on users level after first launch.




There is two way to disable the AutoStart.

1.  User can disable there self from general settings after first launch.




2.  We can create new VB Script\powersehll and second different deployment. As we know this is users related         setting once users launch the Teams from his profile so it will make two change in system on users level.One is HKCU(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)  registry. That’s why it launch every time. This registry need to deleted from script.


Second entry create in %AppData%\Roaming\Microsoft\Teams profile in JASON file. We need to change Jason file below vale false.


This VBS\powershell we can deploy from SCCM once USER is login because you have to apply on user level.

Power shell to change team jason file value form Justin.

We wrote a powershell script to edit the json file directly:
$path = “$env:appdata\Microsoft\Teams\desktop-config.json”
$configarray = Get-Content $path | ConvertFrom-Json
$configarray.appPreferenceSettings.openAtLogin = ‘false’
Set-Content $path ($configarray | ConvertTo-Json)

You can refer a very good link also for detail discussion on auto-start.

https://www.lync.se/2018/04/stop-microsoft-teams-auto-start/ 

Tuesday, May 7, 2019

How to share\Copy ISO,EXE,Software files in VM Hyper-v machine from local host machine

If you are working on Hyper-V Lab machines or you have created your own lab for any infra related work and development purpose. Some of the scenario you face issue to copy data from host to Hyper-v machines.
you want to copy ISO file, Office packages, SAP Application and any other data from host machine to  Hyper-V machine .Here is the step you can  follow .I hope it will work.

  1. Open Run ( Win+r )  or type the command  Diskmgmt.msc
  

2.   Now go to Action tab and Create VHD 


3. Now browses the path in your machine where you want to keep VSD EX C:\Dir1
4. You can assign the space like 20 GB or 50GB as per your availability .It support up 2040 GB .
5. Check virtual hard disk size format VHD and click OK Button



Now create simple volume to mount  VHD

  1. Now open Diskmgmt.msc and  you can see new disk.
  2. The Initialize Disk window will automatically appears, select a partition style for the disk and click Ok.
  3. Select MBR Partition 
    4.   Right Click on the disk and choose New Simple Volume, when the volume wizard opened just                click Next to continue and put the value and  select the default option and click on finish.


       If disk is offline just right click and make it on line

      Now you can see the volume is creates in your host machine.




Just copy your data into disk what ever you want to transfer into VM and you can attached the VHD disk into the VM hyper-v machine.



How to connect to VHD disk into Hyper v machine

  • Open Hyper-v Manager in your host machine
  • Select the Virtual Machine that you would like to attach a virtual disk(VHD)
  • Click in Settings from the right side.


  • Click in SCSI Controller from the left side
  • Select Hard drive and click Add



  • Click Browse (VHD)and find the virtual disk that you would like to attach
  • Click OK



Now you see the new drive in your VM machines.


More info you can see below link.


Monday, April 29, 2019

Power shell and .vbs to get machine OU details from AD



You can get the machine name OU Details from using below command and VB script

Power-Shell

([adsisearcher]"(&(name=$env:computername)(objectClass=computer))").findall().path





VB Script (save below command in.vbs Fotomat)

########################################################################

On Error Resume Next

Set WshNetwork = CreateObject("WScript.Network")
ComputerName = WshNetwork.ComputerName

Set objADSysInfo = CreateObject("ADSystemInfo")
strComputerName = objADSysInfo.ComputerName

Set objComputer = GetObject("LDAP://" & strComputerName)
strOUName = objComputer.DistinguishedName
strOUs = Split(strOUName, ",")
MsgBox strOUs(2)
MsgBox strOUs(1)
strOU = Split(strOUs(2), "=")

#######################################################################


Get computer name from hard disk or Slave Drive

Suppose you have  situation where you have detach hard drive and you want to know the computer name without inserting in computer .Here is the steps you can follow.or you have old hard drive into the new PC and want to know the PC name so you can rejoin the domain.
Please follow  the steps here.


connect your hard disk by cable in your test machine or you already inserted disk in PC.Both the conditions please below steps.

1. Open Regedit on the lab system from RUN window and Go to file option in menu and click on load hive.
2. Please enter the name like Mymachine
3. Navigate to below path
    SystemDrive:\Windows\System32\config\  and browse the System file.
4. Now navigate the hive  HKLM

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ComputerName


 Hope this info will help some one...

  

Friday, April 19, 2019

Set up A Hyper-v virtual switch using a NAT network from power shell

This blog totally  inspire from https://www.thomasmaurer.ch/

You can find more info here.

https://www.thomasmaurer.ch/2016/05/set-up-a-hyper-v-virtual-switch-using-a-nat-network/

I am not good to understand the IP address world so just making a simple note for my self and other guys like me.

Please follow the below steps to get the internet access in your VM machine

1. Create a new Hyper-V Virtual Switch

      New-VMSwitch –SwitchName "ViaMonstraNAT" –SwitchType Internal

2.  Configure the NAT Gateway IP Address

     New-NetIPAddress –IPAddress 172.21.21.1 -PrefixLength 24 -InterfaceAlias "vEthernet (ViaMonstraNAT)"

3. Now you can configure the NAT rule

     New-NetNat –Name ViaMonstraNATNetwork –InternalIPInterfaceAddressPrefix 172.21.21.0/24

     Use IP Address in VM host namchine from 172.21.21.2-172.21.21.254.

Here is IP address configuration we apply in VM host machine

    Host Machine, running Windows 10 1703 build
    IP Address – 172.21.21.1
    Subnet Mask – 255.255.255.0

Host VM, running Windows Server 2012 R2



   IP Address – 172.21.21.2
   Subnet Mask – 255.255.255.0
   Default Gateway – 172.21.21.1
   Preferred DNS Server – 8.8.8.8



Prefer IP Address Example:




MSIX Packaging


Thursday, April 18, 2019

Format-Table function in Power -Shell ..

Very impotent function of power shell is Format-Table.You can get the data in table format.Here is some example is  .

1.  Get-Process | Format-Table


2.  Get-Process | Format-Table -AutoSize

     The AutoSize parameter adjusts the column widths to minimize spacing.



3.  Get-Process | Sort-Object -Property basepriority | Format-Table -GroupBy basepriority -Wrap

The GroupBy parameter arranges the data about the processes into groups based on the value of their BasePriority property



4.  Get-Process -Name powershell | Format-List -Property ProcessName,FileVersion

The Format-List cmdlet displays an object in the form of a listing, with each property labeled and displayed on a separate line:



5.  Get-pssnapin | format-table -wrap



6.  You can export Format-Table in Format-Table.txt.

    $Proc = Get-Process | Format-Table -AutoSize

    $Proc | Format-Table Name | Out-File c:\temp\ Format-Table.txt