Pages

Monday, 15 August 2022

looping

$count = 0

$success = $null

# 1. This is to make sure the script is running. We can add this in network log file since the machine is not connected to network.

 $logfile_Temp = "C:\temp\CheckRunning.log"

 Add-Content $logfile_Temp -Value "This is to check the Gpupdate_DSRRedCmd.Ps1 is runnung or not"

 Do{
  try{

  # 1. Checking the VPN is connected to CISCO Anyconnect Mobility client.

 $NIC = Get-NetIPConfiguration | ? {$_.NetAdapter.status -eq "UP"} | Select-Object InterfaceDescription

if ($NIC -match "Cisco AnyConnect Secure Mobility Client Virtual Miniport Adapter for Windows")

 {

  Start-Sleep -Seconds 60

 $location = "\\housccm309\incoming$\Windows 10 Enterprise"

$comname = $env:computername

$logfile = "$location\$comname.log"

  Add-Content $logfile -Value "Machine is connected to Cisco AnyConnect Secure Mobility client "

 $success = $true

  Add-Content $logfile -Value "Executing Gpupdate /force wating time is 3 minutes"

  gpupdate /force

  Start-Sleep -Seconds 180

 Add-Content $logfile -Value "Gpupdate is executed successfully"

$oseditionwin10 = (Get-WmiObject -class Win32_OperatingSystem).Caption

Add-Content $logfile -Value "Machine is changed to $oseditionwin10"

 }

 ElseIF ($NIC -like "*Pulse*")

 {

 Start-Sleep -Seconds 60

 $location = "\\housccm309\incoming$\Windows 10 Enterprise"

$comname = $env:computername

$logfile = "$location\$comname.log"

Add-Content $logfile -Value "Machine is Connect to Pulse VPN"

  $success = $true

  Add-Content $logfile -Value "Executing Upupdate /force wating time is 3 minutes"

  gpupdate /force

  Start-Sleep -Seconds 180

 Add-Content $logfile -Value "Gpupdate is executed successfully"

 $oseditionwin10 = (Get-WmiObject -class Win32_OperatingSystem).Caption

Add-Content $logfile -Value "Machine is changed to $oseditionwin10"

    }

 Else

 {Add-Content $logfile_Temp -Value "Machine is waiting to join network"

}

 }

  catch {

    $location = "\\housccm309\incoming$\Windows 10 Enterprise"

$comname = $env:computername

$logfile = "$location\$comname.log"

Add-Content $logfile -Value "Error"

    }

  $count++

 }until($success)

Monday, 23 May 2022

MSIX Certificate

$expirationDate = {Get-Date}.Invoke().AddYears(5)

$pass = ConvertTo-SecureString -String "12345" -Force -AsPlainText

$thumbprint = (New-SelfSignedCertificate -notafter $expirationDate -Type CodeSigningCert -Subject "CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" -FriendlyName "PowerToys Test Certificate" -KeyDescription "PowerToys Test Certificate" -KeyFriendlyName "PowerToys Test Key" -KeyUsage "DigitalSignature" -CertStoreLocation Cert:\LocalMachine\My).Thumbprint

Export-PfxCertificate -Cert cert:\LocalMachine\My\$thumbprint -FilePath PowerToys_TemporaryKey.pfx -Password $pass

Import-PfxCertificate -CertStoreLocation Cert:\LocalMachine\Root -FilePath PowerToys_TemporaryKey.pfx -Password $pass


Wednesday, 16 March 2022

Powershell script to to check te application version through app name

$driverversion = "7.5.7"

$version = (Get-WmiObject -Class Win32_Product | where Name -like "Sentinel System Driver Installer*" | select Version).version

If ($version -ge $driverversion){
Write-host "Already same or higher version of driver already installed in the machine"
}

Else {
Write-host "Application not found"
}

Thursday, 24 February 2022

VB Script to set a registry under HKCU through system context

 strComputer = "."

strRegPathSuffix = "\Desktop\Pavan"

strRegValueName = "EnableADAL"

intRegValueDec = "1"

strRegPathSuffix1 = "\Desktop\Pavan"

strRegValueName1 = "EnableADAL2"

intRegValueDec1 = "2"

Const HKEY_USERS = &H80000003

Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = ""

oReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys

    'wscript.echo subkey

    'We only want to do something if the subkey does not contain any of the following: .DEFAULT or S-1-5-18 or S-1-5-19 or S-1-5-20 or _Classes

    If NOT ((InStr(1,subkey,".DEFAULT",1) > 0) OR (InStr(1,subkey,"S-1-5-18",1) > 0) OR (InStr(1,subkey,"S-1-5-19",1) > 0) OR (InStr(1,subkey,"S-1-5-20",1) > 0) OR (InStr(1,subkey,"_Classes",1) > 0)) Then

    'Create desired registry key/value

    strKeyPath = subkey & strRegPathSuffix

    'wscript.echo strKeyPath

    oReg.CreateKey HKEY_USERS, strKeyPath

    oReg.SetStringValue HKEY_USERS, strKeyPath, strRegValueName, intRegValueDec

      oReg.SetDWORDValue HKEY_USERS, strKeyPath, strRegValueName1, intRegValueDec1

    End If

Next

Wednesday, 16 February 2022

Set user environmental variable through system contest

 # get the domain and username for the currently logged on user

 $domain, $userName = (Get-WmiObject -Class Win32_ComputerSystem).UserName -split '\\', 2

 # next, get the SID for that current user
 
 $user = [System.Security.Principal.NTAccount]::new($domain, $userName)
 
 $sid  = $user.Translate([System.Security.Principal.SecurityIdentifier]).Value
 
 # set the registry value for this user.
 Set-ItemProperty -Path "Registry::HKEY_USERS\$sid\Environment" -Name 'NAME2' -Value 'Value2' -Type String
 

Thursday, 10 February 2022

read and write permission through powershell

$folder_to_change = "C:\Temp\Aspen"
$acl = Get-Acl "$folder_to_change"
$ar = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Users", @("Read", "write"), "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($ar)
Set-Acl "$folder_to_change" $acl

Thursday, 20 January 2022

Installed application is higher than current version

$currentversion = "97.0.4692.90"

function Get-ApplicationVersion {
    $applicationName = "Google Chrome"
    $my_check = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, InstallDate | Where -Property DisplayName -Match $applicationName
    $versionNumber = $my_check.DisplayVersion
    if ($my_check) {
        $versionNumber
    }
    else {
        write-warning "Application not found"
    }
}
$version = Get-ApplicationVersion
If ($version -gt $currentversion) {
Write-host "Alredy higher version installed in the machine"
}
Else {
Write-host "Installing the current version"
}

Thursday, 6 January 2022

Copy File to user profile while installing through system contest

 For /F "tokens=2* delims= " %%u IN ('Reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /V ProfilesDirectory') DO Set ProfilesDir=%%v

Set ProfilesDir=%profilesDir:%%SystemDrive%%=%\%ProfilesDir:~14,100%

For /F "tokens=*" %%d IN ('Dir /ad /b "%ProfilesDir%"') DO (

If /I NOT "%%d" == "ALL USERS" (

xcopy "%~dp0FIlezilla" "%ProfilesDir%\%%d\appdata\Roaming\FileZIlla" /y /e))

User based detection

function getloggedindetails () {     ##Find logged in username     $user = Get-WmiObject Win32_Process - Filter "Name='explorer...

Search This Blog