Next: Powershell

Pages

Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

How to run powershell from TaskActivity of Window

 Use as Program or script: c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe

and as arg use -executionpolicy bypass -file "C:\Temp\example.ps1"

where example.ps1 contain your script

How to retrieve the key license of Windows from UEFI

  1. Open Shell (cmd.exe) as Administrator
  2. run the following powershell command:

    powershell "(Get-WmiObject -query ‘select * from SoftwareLicensingService’). OA3xOriginalProductKey"
     

How to compare two paths of files



My films are stored inside th external HD.

I have a copy of backup of my film also inside the HD of my computer.

Some time I put my new film olny in my computer and I don't copy the film in my external HD.

The problem is that external HD is not aligned with my HD computer.

The following script in Powershell align the two version in fast mode......

Check Internet Connection with PowerShell



$flagConnectionAtive=[Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]‘{DCB00C01-570F-4A9B-8D69-199FDBA5723B}’)).IsConnectedToInternet

if ($flagConnectionAtive -eq "True")
{
 Write-Host "Internet connection is active"
}
else
{
 Write-Host "Internet connection is not active"
}

How to unistal program with Powershell





To obtain the list of the program/Package installed use this command:

Get-WmiObject -Class Win32_Product

To remove the program/package installed use this command:

$packages = @("package1", "package2", "package3")
foreach($package in $packages) {
  $app = Get-WmiObject -Class Win32_Product | Where-Object {
    $_.Name -match "$package"
  }
  $app.Uninstall()
}


where package1, package2 and package3 are the programs to unistall.

Copy files and change name with PowerShell



A friend of mine asked if I could copy files from one folder to another and rename them according to the following format

YYYYMMDDHHMMSS.ext

here  source code:


 cls  
 $source="C:\next72\source"  
 $destination="C:\next72\destination"  
 set-location  $source  
 $files=get-childitem -Recurse    
 foreach ($file in $files)  
 {  
  if (!$file.PsIsContainer)   
  {  
  $newName=$destination+"\"+[string]$file.LastWriteTime.Year +   
               [string]$file.LastWriteTime.Month +   
               [string]$file.LastWriteTime.Month +   
               [string]$file.LastWriteTime.Day +   
               [string]$file.LastWriteTime.Hour +   
               [string]$file.LastWriteTime.Minute +   
               [string]$file.LastWriteTime.Second +   
               [string]$file.Extension  
  Copy-Item $file.FullName $newName  
  }  
 }  

Then change source and destination variable in the script.

How to retrieve windows product key


How to retrieve windows product key

To retrieve the windows product key you can use the following 
script in Powershell: