Generate Random Names
Function Get-RandomNames{ [CmdletBinding()] [OutputType([Object])] param( [Parameter(Mandatory=$false)] [int] $count=10 ) $Webfemale = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-female-first.txt" $Webmale = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-male-first.txt" $WebSurname = Invoke-WebRequest "https://raw.githubusercontent.com/mdowst/RandomDataLookups/master/People/popular-surnames.txt" $female = @() $female = $Webfemale.Content.Split("`n").Trim() | ?{$_.length -gt 2} $male = @() $male = $Webmale.Content.Split("`n").Trim() | ?{$_.length -gt 2} $Surname = @() $Surname = $WebSurname.Content.Split("`n").Trim() | ?{$_.length -gt 2} $names = @() for($i=0; $i -ne $count; $i++) {...
Find Guid in String
$guidPattern = "(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}" [Regex]::Matches($string, $guidPattern).Value
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 } } }
Get File Name and Extension from Path
# Return just the file name [System.IO.Path]::GetFileName($FilePath) # Returns file name without the extension [System.IO.Path]::GetFileNameWithoutExtension($FilePath) # Returns the file extension only [System.IO.Path]::GetExtension($FilePath)
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 }