forked from okieselbach/Intune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
okieselbach
committed
May 10, 2018
1 parent
376af38
commit 2f237dd
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<# | ||
Version: 1.1 | ||
Author: Oliver Kieselbach | ||
Script: HideFileExt.ps1 | ||
Description: | ||
Intune Management Extension - PowerShell script template with logging, | ||
error codes, standard error output handling and x64 PowerShell execution. | ||
Release notes: | ||
Version 1.0: Original published version. | ||
Version 1.1: Added standard error output handling. | ||
The script is provided "AS IS" with no warranties. | ||
#> | ||
|
||
$exitCode = 0 | ||
|
||
if (![System.Environment]::Is64BitProcess) | ||
{ | ||
# start new PowerShell as x64 bit process, wait for it and gather exit code and standard error output | ||
$sysNativePowerShell = "$($PSHOME.ToLower().Replace("syswow64", "sysnative"))\powershell.exe" | ||
|
||
$pinfo = New-Object System.Diagnostics.ProcessStartInfo | ||
$pinfo.FileName = $sysNativePowerShell | ||
$pinfo.Arguments = "-ex bypass -file `"$PSCommandPath`"" | ||
$pinfo.RedirectStandardError = $true | ||
$pinfo.RedirectStandardOutput = $true | ||
$pinfo.CreateNoWindow = $true | ||
$pinfo.UseShellExecute = $false | ||
$p = New-Object System.Diagnostics.Process | ||
$p.StartInfo = $pinfo | ||
$p.Start() | Out-Null | ||
|
||
$exitCode = $p.ExitCode | ||
|
||
$stderr = $p.StandardError.ReadToEnd() | ||
|
||
if ($stderr) { Write-Error -Message $stderr } | ||
} | ||
else | ||
{ | ||
# start logging to TEMP in file "scriptname".log | ||
Start-Transcript -Path "$env:TEMP\$($(Split-Path $PSCommandPath -Leaf).ToLower().Replace(".ps1",".log"))" | Out-Null | ||
|
||
try | ||
{ | ||
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name HideFileExt -Value 0 -ErrorAction Stop | ||
} | ||
catch | ||
{ | ||
Write-Error -Message "Could not write regsitry value" -Category OperationStopped | ||
$exitCode = -1 | ||
} | ||
|
||
Stop-Transcript | Out-Null | ||
} | ||
|
||
exit $exitCode |