cancel
Showing results for 
Search instead for 
Did you mean: 
CS_HelpDesk
GoTo Contributor

Folder Move

To move a folder from one location to another.

---

$source = $null 

$destination = $null 

$overwrite = $false 

If (-Not (Test-Path -Path $destination -PathType Container)) 

{ 

    New-Item -Path $destination -ItemType Container 

} 

Move-Item -Path $source -Destination $destination -Force:$overwrite –Verbose 

CS_HelpDesk
GoTo Contributor

Folder Delete

To delete a folder at a given destination.

---

Delete 

$folderPath = $null 

if (Test-Path -Path $folderPath -PathType Container) 

{ 

  Remove-Item -Path $folderPath -Force -Recurse 

} 

else 

{ 

  Write-error -Message "$folderPath doesn't exist" -Category InvalidArgument 

} 

CS_HelpDesk
GoTo Contributor

Compress to zip

Compress a file or folder to a ZIP archive.

---

$source = $null 

$destination = $null 

$includeRootFolder = $false 

$overwrite = $false 

$parent = Split-Path $destination 

If (-Not (Test-Path -Path $parent -PathType Container)) 

{ 

    New-Item -Path $parent -ItemType Container 

} 

$isFile = Test-Path -Path $source -PathType Leaf 

if (-Not $includeRootFolder -and -Not $isFile) 

{ 

    $source = Join-Path $source "*" 

} 

Compress-Archive -Path $source -DestinationPath $destination -Force:$overwrite 

CS_HelpDesk
GoTo Contributor

Extract from Zip

Extract all files and folders from a compressed ZIP archive to a selected folder.

---

$source = $null 

$destination = $null 

$overwrite = $false 

Expand-Archive -Path $source -DestinationPath $destination -Force:$overwrite 

CS_HelpDesk
GoTo Contributor

Display a message box

$caption = $null 

$text = $null 

Add-Type -AssemblyName PresentationFramework 

[System.Windows.MessageBox]::Show($text, $caption) 

CS_HelpDesk
GoTo Contributor

MSI installation

Upload an .msi file that will be run silently in the background.

---

$customArguments = $null

$msiPath = $resolve_Files[0];

$arguments = @();
$arguments += "/i";
$arguments += '"' + $msiPath + '"';
$arguments += "/quiet";

if ($noRestart)
{
    $arguments += "/norestart";
}

$logFileId = New-Guid;
$logFilePath = "$logFileId.log";
$arguments += "/l*";
$arguments += '"' + $logFilePath + '"';

if ($customArguments)
{
    $arguments += $customArguments;
}

$msiExec = "msiexec.exe";
$process = Start-Process $msiExec -ArgumentList $arguments -Wait -NoNewWindow -PassThru;

if (Test-Path $logFilePath)
{
    Get-Content -Path $logFilePath;
}

Exit $process.ExitCode;
CS_HelpDesk
GoTo Contributor

MSI Uninstall

Upload the .msi file for the app you want to uninstall. It will be run silently in the background.

---

$customArguments = $null

$msiPath = $resolve_Files[0];

$arguments = @();
$arguments += "/uninstall";
$arguments += '"' + $msiPath + '"';
$arguments += "/quiet";

if ($noRestart)
{
    $arguments += "/norestart";
}

$logFileId = New-Guid;
$logFilePath = "$logFileId.log";
$arguments += "/l*";
$arguments += '"' + $logFilePath + '"';

if ($customArguments)
{
    $arguments += $customArguments;
}

$msiExec = "msiexec.exe";
$process = Start-Process $msiExec -ArgumentList $arguments -Wait -NoNewWindow -PassThru;

if (Test-Path $logFilePath)
{
    Get-Content -Path $logFilePath;
}

Exit $process.ExitCode;
CS_HelpDesk
GoTo Contributor

Winget Install

Install application from the web by the application's ID and version.

Without specifying the version, winget installs the latest version of the application.

You can find the ID of the app via the 'winget search' command.

---

$appId = $null
$version = $null

$PlatformString = if([Environment]::Is64BitOperatingSystem){"x64"} else{"x86"}

function IsVistualMachine
{
    try
    {
        if((Get-CimInstance win32_computersystem).model -like "*virtual*"){return $true}
    }
    catch{}
    $false
}

function Get-RegUninstallKey
{
    param (
        [string]$DisplayName
    )

    $ErrorActionPreference = 'Continue'
    $uninstallKeys = @("registry::HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall")
    if($PlatformString -eq "x64"){$uninstallKeys += "registry::HKLM\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"}
    $softwareTable = @()
   
    foreach ($key in $uninstallKeys)
    {
        $softwareTable += Get-Childitem $key | Get-ItemProperty | where displayname | Sort-Object -Property displayname
    }
    if ($DisplayName)
    {
        $softwareTable | where displayname -Like "*$DisplayName*"
    }
    else
    {
        $softwareTable | Sort-Object -Property displayname -Unique
    }
}

function IsVisualCppRedistrubutable2019OrLaterInstalled
{
    $keys = Get-RegUninstallKey -DisplayName "Microsoft Visual C++ * Redistributable ($PlatformString)"
    foreach ($key in $keys){
        if([System.Version]$key.BundleVersion -ge [System.Version]"14.29.0.0"){return $true} # version 2015-2019
    }
    $false
}

function Install-VisualC {
    $url = "https://aka.ms/vs/17/release/vc_redist.$PlatformString.exe"
    $WebClient = New-Object System.Net.WebClient
    $WebClient.DownloadFile($url, "$env:Temp\vc_redist.exe")
    $WebClient.Dispose()
    start-process "$env:temp\vc_redist.exe" -argumentlist "/q /norestart" -Wait
}


# If Visual C++ Redist. not installed, install it
if ((IsVistualMachine) -and -not (IsVisualCppRedistrubutable2019OrLaterInstalled))
{
    Write-Host -message "Suitable version of Visual C++ not found. Attempting to install"
    try {
        Install-VisualC
    }
    Catch [System.InvalidOperationException]{
        Write-Host -message "Error installing Visual C++ redistributable. Attempting install once more"
        Start-Sleep -Seconds 5
        Install-VisualC
    }
    Catch {
        Write-Host -message "Failed to install Visual C++ redistributable!"
        Write-Host -message $_
        exit 1
    }
    if (-not (IsVisualCppRedistrubutable2019OrLaterInstalled)){Write-Host -message "Suitable version of Visual C++ Redistributable not found!" ; exit 1}
    else {Write-Host -message "Successfully installed Microsoft Visual C++ Redistributable ($PlatformString)"}
}

function GetWingetPath
{
    $WingetPath = (Get-ChildItem "$env:programfiles\WindowsApps" -Recurse -File
        | where { $_.name -like "AppInstallerCLI.exe" -or $_.name -like "Winget.exe" }
        | select -ExpandProperty fullname
        | Sort-Object -Property @{Expression={[Version][RegEx]::Match($_, "_(\d+.\d+.\d+.\d+)_").Groups[1].Value}; Descending=$true})
    if ($WingetPath.count -gt 1) { $WingetPath = $WingetPath[0] }
    $WingetPath
}

$winget = GetWingetPath

if($null -eq $winget){
    Write-Host "Winget not found!"
    exit 1
}

if($version)
{
    &$winget install --id $appId -v $version --accept-package-agreements --accept-source-agreements --silent
}
else
{
    &$winget install --id $appId --accept-package-agreements --accept-source-agreements --silent
}
CS_HelpDesk
GoTo Contributor

Microsoft Defender- Quick Scan

Run Microsoft Defender quick scan on the file system.

---

& "$env:ProgramFiles\Windows Defender\MpCmdRun.exe" -Scan -ScanType 1
CS_HelpDesk
GoTo Contributor

Microsoft Defender - Full Scan

Run Microsoft Defender full scan on the file system.
---
& "$env:ProgramFiles\Windows Defender\MpCmdRun.exe" -Scan -ScanType 2