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
#One liner answer to 'Beginner Task' | |
#relies on the fact that all Latin-1 accented characters have an ASCII value > 192 (https://msdn.microsoft.com/en-us/library/ms537495(v=vs.85).aspx) | |
#Not clear from brief on how this is meant to be run, but works locally: | |
Get-ChildItem c:\temp\FileShare -recurse | Where-Object{[int[]][char[]]$_.name -gt 192} | Format-Table name, @{label="Directory"; Expression={$_.DirectoryName}}, @{label="Creation Date"; Expression={$_.CreationTime}},@{label="Last Modification Date"; Expression={$_.LastWriteTime}}, @{label="File Size"; Expression={$_.length}} | |
#Over UNC | |
Get-ChildItem \\labbox1\share$\FileShare -recurse | Where-Object{[int[]][char[]]$_.name -gt 192} | Format-Table name, @{label="Directory"; Expression={$_.DirectoryName}}, @{label="Creation Date"; Expression={$_.CreationTime}},@{label="Last Modification Date"; Expression={$_.LastWriteTime}}, @{label="File Size"; Expression={$_.length}} | |
#Or via RemotePS: |
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
<# | |
.Synopsis | |
Get files with accented Latin-1 characters in their name | |
.DESCRIPTION | |
Long description | |
.EXAMPLE | |
Get-Diacritic -Path c:\fileshare\ -To Boss@contoso.com | |
Gets all files whose name contains an accented Latin-1 character in the given folders and sends | |
the results as a CSV attachment to the email address supplied | |
.Example |
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
#Assumes the solution ps1 is in the c:\scripts folder | |
Register-ScheduledTask -Action (New-ScheduledTaskAction -execute 'PowerShell.exe' -Argument "c:\scripts\Get-Diacritic.ps1; get-diacritic -Path 'c:\temp\fileshare\' -To stuart.moore@ntu.ac.uk -AsHTML" | |
) -Trigger (New-ScheduledTaskTrigger -weekly -WeeksInterval 2 -DaysOfWeek Saturday -At 11pm) -TaskName 'Find files with diacritic marks' |
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
$testtext = @" | |
test1 | |
test 2 | |
The quick brown fox jumps over the lazy fox | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum | |
test4 |
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
$output = @() | |
$plineblank = $false | |
$tline = '' | |
$reader = [System.IO.File]::OpenText("C:\full\path\to\testfile.txt ") | |
while($null -ne ($line = $reader.ReadLine())) { | |
if ($line -eq '' -and $pline -ne '' ){ | |
$output += $tline | |
$tline = $null |
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
$externals = Get-ChildItem "$ModulePath\functions\" | |
$Rules = (Get-ScriptAnalyzerRule).Where{$_.RuleName -notin ('PSAvoidUsingPlainTextForPassword') } | |
Describe -tags ('ScriptAnalysis')'Script Analyzer Tests' { | |
ForEach ($ScriptFile in $externals) | |
{ | |
Context "Testing $ScriptFile for Standard Processing" { | |
foreach ($rule in $rules) | |
{ | |
$i = $rules.IndexOf($rule) | |
It "$ScriptFile passes the PSScriptAnalyzer Rule number $i - $rule " { |
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
#Written off the top of my head, check before relying on it. | |
import-module "SQLPS" -DisableNameChecking | |
$sqlsvr = New-Object -TypeName Microsoft.SQLServer.Management.Smo.Server("Server1") | |
$restore = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Restore | |
$devicetype = [Microsoft.SqlServer.Management.Smo.DeviceType]::File | |
$files=(Get-ChildItem \\YourServer\Yourshare\FULL\ -Filter *.bak | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-1)}) |
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
function Invoke-DbaDBRestoreSeeding | |
{ | |
<# | |
.SYNOPSIS | |
Syncs 2 databases ready for database mirroring or Availability Group setup | |
.DESCRIPTION | |
Scans the database backup history on the Source SQL Instance, and restores them onto the source Instance | |
If more transanction backups occur before the restores complete, these will then be applied afterwards. | |
The function may also be used to resume an already partially restored databas as long as it's based on the same full database backup chain |
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
use master | |
go | |
if exists (select * from sys.databases where name='RestoreTimeDiffStripe') | |
begin | |
ALTER DATABASE RestoreTimeDiffStripe SET single_USER with rollback immediate | |
drop database RestoreTimeDiffStripe | |
end | |
go |
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
use master | |
go | |
if exists (select * from sys.databases where name='RestoreCopyOnly') | |
begin | |
ALTER DATABASE RestoreCopyOnly SET single_USER with rollback immediate | |
drop database RestoreCopyOnly | |
end | |
go |
OlderNewer