Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Maciej Michalski spy86

🎯
Focusing
View GitHub Profile
View Get Active Directory user account last logged on time
#Check if the account exists.
If($Results.Count -eq 0)
{
Write-Warning "The SamAccountName '$UserName' cannot find. Please make sure that it exists."
}
Else
{
Foreach($Result in $Results)
{
$DistinguishedName = $Result.Properties.Item("DistinguishedName")
View Script to export the configuration of SQL Server
USE master
GO
PRINT ‘*******************************************************************************************’
PRINT ‘*******************************************************************************************’
PRINT ‘<SQL Server Instance Name>’
SELECT @@SERVERNAME
GO
PRINT ‘*******************************************************************************************’
PRINT ‘*******************************************************************************************’
PRINT ‘<SQL Server Version, Edition and Build>’
@spy86
spy86 / drop database
Created Aug 3, 2017
PS drop database & close connection
View drop database
$dbnamefile1 = Get-ChildItem %RestorePath% | Where Name -Match ("DB-Name")
$dbname1 = "DB-Name"
Restore-SqlDatabase -ServerInstance %SQLSERVER% -Database $dbname1 -BackupFile "%RestorePath%\$dbnamefile1"
$dbnamefile2 = Get-ChildItem %RestorePath% | Where Name -Match ("DB-Name")
$dbname2 = "DB-Name"
Restore-SqlDatabase -ServerInstance %SQLSERVER% -Database $dbname1 -BackupFile "%RestorePath%\$dbnamefile1"
$dbnamefile3 = Get-ChildItem %RestorePath% | Where Name -Match ("DB-Name")
$dbname3 = "DB-Name"
View Samba install & configure
Install Samba
Check for existing samba package if any using the following commands.
rpm -qa | grep samba
yum list installed | grep samba
If samba is installed, remove it using the below command:
yum remove samba*
Now, install samba using the following command.
View export single IIS site
%windir%\system32\inetsrv\appcmd list site "site" /config /xml > c:\mywebsite.xml
View Install MongoDB as a Service on Windows 2012
mongod --dbpath "C:\Program Files\MongoDB\Server\3.4\database" --logpath "C:\Program Files\MongoDB\Server\3.4\logs" --install --serviceName "MongoDB Server"
View MongoDB dump
mongodump -h localhost -c New Collection -o F:\mongodb_backup\Dest_SingleCollBkp
View PS script to MongoDB dump
$date = Get-Date -UFormat %Y-%m-%d;
$backupFolder = $date;
$basePath = "F:\mongodb_backup";
$destinationPath = Join-Path $basePath $backupFolder;
if(!(Test-Path -Path $destinationPath)) {
New-Item -ItemType directory -Path $destinationPath;
(C:\mongodump.exe --out $destinationPath);
}
View PS Transfer files into FTP
#we specify the directory where all files that we want to upload
$Dir="C:/Dir"
#ftp server
$ftp = "ftp://xxx.xxx.xxx/dir/"
$user = "user"
$pass = "Pass"
$webclient = New-Object System.Net.WebClient
View Duplicati CommandLine restore
C:\Program Files\Duplicati 2\Duplicati.CommandLine.exe restore %SftpURL% --auth-username=%SftpUser% --auth-password=%SftpPassword% --passphrase=%SftpPassphrase% --restore-path=%RestorePath%