Friday, December 20, 2013

Set ACL on a folder

"Set ACL"
One of my Runbooks I create a home drive based on the location of the user and their name. I also set the ACL so they are the only ones with rights.

Screen shot of Runbook:




The DriveMap-Var build the drive mapping based on the location of the user. The VAR is taken from in Initialize Data. In my case
$locNLK ="\\nlkvflesvr04\NLK-Home"
$locBDU ="\\nlkvflesvr02\BDU-Home"
If ($location -eq "NLK"){
$loc = $locNLK
}


Once that is defined, I build the share name:

$homeDrive = "\`d.T.~Ed/{30B8BA77-3261-41F6-8EC5-F84511D45983}.loc\`d.T.~Ed/"
$username = "\`d.T.~Ed/{70D59E59-DB18-4D99-B7FE-FF591376E64C}.{F857D2AB-8976-40C1-B25A-6965985B8541}\`d.T.~Ed/"
$ShareName = "$homeDrive\$username"

I use the built in Create Folder in Orchestrator to create the users folder based on the $sharename.

Next I Set-ACL and the user is all set with a Home Drive.

Script: Set-ACL
$acl = get-acl "\`d.T.~Ed/{0FFE6E93-2182-4081-B0B3-7C9DD2B1F871}.Folder\`d.T.~Ed/"
$UserACL = "SCHOLLE\\`d.T.~Ed/{70D59E59-DB18-4D99-B7FE-FF591376E64C}.{F857D2AB-8976-40C1-B25A-6965985B8541}\`d.T.~Ed/"
$arguments = "$UserACL","Modify", "3", "None", "Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $arguments
$acl.SetAccessRule($accessRule)
$acl | Set-Acl "\`d.T.~Ed/{0FFE6E93-2182-4081-B0B3-7C9DD2B1F871}.Folder\`d.T.~Ed/"

Thursday, December 19, 2013

On Battery Powershell Script


I have a laptop in a remote site that loses AC Power from time to time, I wrote the following script and added it to a schedule task to run every hour.

Main line of code is very simple:


Rest of the code is here, this is version 1, I plan on adding other monitoring.

$strComputer = "." 
$colItems = get-wmiobject -class "Win32_Battery" -namespace "root\CIMV2" -computername $strComputer 
$word1 = "Availability: "
$word2 = "Battery Recharge Time: "
$word3 = "Battery Status: "
$word4 = "Description: "
$word5 = "Estimated Charge Remaining: "
$word6 = "Estimated Run Time: "
$word7 = "Last Error Code: " 
$word8 = "Maximum Recharge Time: "
$word9 = "Status: " 
$word10 = "Time On Battery: " 
$word11 = "Time To Full Charge: " 
$br = "
" if ($colItems.Availability -eq "3") { foreach ($objItem in $colItems) { $Bat1 = $objItem.Availability $Bat2 = $objItem.BatteryRechargeTime $Bat3 = $objItem.BatteryStatus $Bat4 = $objItem.Description $Bat5 = $objItem.EstimatedChargeRemaining $Bat6 = $objItem.EstimatedRunTime $Bat7 = $objItem.LastErrorCode $Bat8 = $objItem.MaxRechargeTime $Bat9 = $objItem.Status $Bat10 = $objItem.TimeOnBattery $Bat11 = $objItem.TimeToFullCharge }} else {write-host "NO"} $word1 + $Bat1 + $br | out-file c:\temp\battery.txt $word2 + $Bat2 + $br | out-file c:\temp\battery.txt -Append $word3 + $Bat3 + $br | out-file c:\temp\battery.txt -Append $word4 + $Bat4 + $br | out-file c:\temp\battery.txt -Append $word5 + $Bat5 + $br | out-file c:\temp\battery.txt -Append $word6 + $Bat6 + $br | out-file c:\temp\battery.txt -Append $word7 + $Bat7 + $br | out-file c:\temp\battery.txt -Append $word8 + $Bat8 + $br | out-file c:\temp\battery.txt -Append $word9 + $Bat9 + $br | out-file c:\temp\battery.txt -Append $word10 + $Bat10 + $br | out-file c:\temp\battery.txt -Append $word11 + $Bat11 + $br | out-file c:\temp\battery.txt -Append Del c:\temp\battery.htm Rename-Item C:\temp\battery.txt battery.htm $EmailBody1= get-content "c:\temp\battery.htm" $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "MBX01" $mailmessage.IsBodyHTML = $true $mailmessage.from = ("stein@olle.com") $mailmessage.To.add("stein@olle.com") $mailmessage.Subject = "Test HTML" $mailmessage.Body = $EmailBody1 $mailmessage.Headers.Add("message-id", "<3BD50098E401463AA228377848493927-1>") $smtpclient.Send($mailmessage)



Tuesday, December 17, 2013

System Center Orchestrator

Below is a layout for Notifying people based on location.



Check out the Powershell code here
                                https://github.com/stein97/Orchestrator/blob/master/notify.ps1