Get User’s Desktop Path
$ShellFolders = Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' $ShellFolders.Desktop
Zip All Files in Folder
# Get the files to zip $FilesToZip = Get-ChildItem -Path $FolderPath -File # Load the assembly to get the zip functionality [Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" ) | Out-Null # Set compression level $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal # Set Zip file pathc based on folder $ZipPath = Join-Path $FolderPath "$(Split-Path $FolderPath -Leaf).zip" # initialize the zip file $Archive = [System.IO.Compression.ZipFile]::Open( $ZipPath, "Update" ) #...
Get Folder Path of the Current Script
Function Get-ScriptDirectory{ $Invocation = (Get-Variable MyInvocation -Scope 1).Value; if($Invocation.PSScriptRoot){ $Invocation.PSScriptRoot; } elseif($Invocation.MyCommand.Path){ Split-Path $Invocation.MyCommand.Path } elseif($Invocation.InvocationName.LastIndexOf("\") -gt 0){ $Invocation.InvocationName.Substring(0,$Invocation.InvocationName.LastIndexOf("\")); } else { Get-PSDrive | Where-Object{$_.Provider.Name -eq 'FileSystem'} | Foreach-Object { Join-Path -Path $_.Root -ChildPath $_.CurrentLocation } } }
Grant Permissions to Folder Share
Grant-SmbShareAccess -name $ShareName -AccountName $Account -AccessRight Full -Force
Revoke All Permissions From Folder Share
Get-SmbShareAccess -name $ShareName | Foreach {Revoke-SmbShareAccess -name $ShareName -AccountName $_.AccountName -Force}
Create a Folder Share
$Shares=[WMICLASS]'WIN32_Share' $sd = ([WMIClass] "Win32_SecurityDescriptor").CreateInstance() $shares.create($FolderPath, $ShareName, 0, 100, "Description", "", $sd)
Create Folder If It Doesn’t Exist
If (-not(test-path $FolderPath)){ New-Item -type directory -Path $FolderPath }