Found this today.. converting a date into a Large integer.. used in various positions within Active Directory.
(Get-Date "01/01'2015").ToFileTime()
And that's it. Surprisingly easy.
Technology tidbits and things related to small farming including Powershell, AD, Exchange, Security, Chickens, Dogs, General Construction and the like.
Thursday, October 29, 2015
Wednesday, October 28, 2015
Powershell Remote Goodies (RDP Shutdown Query)
I had cause this morning to reboot a remote server that was unresponsive to RDP sessions. The server is running Windows 2003 (yes, yes I know.. ) So new RDP session would hang at Applying settings so I looked to POSH to take care of this.
A couple things I discovered that I'd not heard of before.. Quesry session, and MSG.
First off to see what users had sessions:
Query Session /server:"servername"
It will list all current sessions whether Active or otherwise. Very nice.
Next is MSG.
The MSG command sends a message just like the old NET SEND did. So first thing to notify the few users who had working sessions that the server was going down.
(I didnt even need to use my admin account for this)
MSG /server:"server name" *
Enter message to send; end message by pressing CTRL-Z on a new line, then ENTER.
Easy as cake.. even my RDP session that was still Applying Settings got the notice. So next step to actively tell it to reboot.
First thing I tried was
Shutdown /r /m \\servername /force
Which didn't work because I did not have the right permissions. Next was running POSH as my admin account, when I retried the command it wanted a reason code.
Reasons on this computer:
(E = Expected U = Unexpected P = planned, C = customer defined)
Type Major Minor Title
U 0 0 Other (Unplanned)
E 0 0 Other (Unplanned)
E P 0 0 Other (Planned)
U 0 5 Other Failure: System Unresponsive
E 1 1 Hardware: Maintenance (Unplanned)
E P 1 1 Hardware: Maintenance (Planned)
E 1 2 Hardware: Installation (Unplanned)
E P 1 2 Hardware: Installation (Planned)
P 2 3 Operating System: Upgrade (Planned)
E 2 4 Operating System: Reconfiguration (Unplanned)
E P 2 4 Operating System: Reconfiguration (Planned)
P 2 16 Operating System: Service pack (Planned)
2 17 Operating System: Hot fix (Unplanned)
P 2 17 Operating System: Hot fix (Planned)
2 18 Operating System: Security fix (Unplanned)
P 2 18 Operating System: Security fix (Planned)
E 4 1 Application: Maintenance (Unplanned)
E P 4 1 Application: Maintenance (Planned)
E P 4 2 Application: Installation (Planned)
E 4 5 Application: Unresponsive
E 4 6 Application: Unstable
U 5 15 System Failure: Stop error
E 5 19 Security issue
U 5 19 Security issue
E P 5 19 Security issue
E 5 20 Loss of network connectivity (Unplanned)
U 6 11 Power Failure: Cord Unplugged
U 6 12 Power Failure: Environment
P 7 0 Legacy API shutdown
I re-ran the command but by this time the local staff had powered it off since it was not responding to a shutdown at the console either. :(
But I did learn some new things today.
A couple things I discovered that I'd not heard of before.. Quesry session, and MSG.
First off to see what users had sessions:
Query Session /server:"servername"
It will list all current sessions whether Active or otherwise. Very nice.
Next is MSG.
The MSG command sends a message just like the old NET SEND did. So first thing to notify the few users who had working sessions that the server was going down.
(I didnt even need to use my admin account for this)
MSG /server:"server name" *
Enter message to send; end message by pressing CTRL-Z on a new line, then ENTER.
Easy as cake.. even my RDP session that was still Applying Settings got the notice. So next step to actively tell it to reboot.
First thing I tried was
Shutdown /r /m \\servername /force
Which didn't work because I did not have the right permissions. Next was running POSH as my admin account, when I retried the command it wanted a reason code.
Reasons on this computer:
(E = Expected U = Unexpected P = planned, C = customer defined)
Type Major Minor Title
U 0 0 Other (Unplanned)
E 0 0 Other (Unplanned)
E P 0 0 Other (Planned)
U 0 5 Other Failure: System Unresponsive
E 1 1 Hardware: Maintenance (Unplanned)
E P 1 1 Hardware: Maintenance (Planned)
E 1 2 Hardware: Installation (Unplanned)
E P 1 2 Hardware: Installation (Planned)
P 2 3 Operating System: Upgrade (Planned)
E 2 4 Operating System: Reconfiguration (Unplanned)
E P 2 4 Operating System: Reconfiguration (Planned)
P 2 16 Operating System: Service pack (Planned)
2 17 Operating System: Hot fix (Unplanned)
P 2 17 Operating System: Hot fix (Planned)
2 18 Operating System: Security fix (Unplanned)
P 2 18 Operating System: Security fix (Planned)
E 4 1 Application: Maintenance (Unplanned)
E P 4 1 Application: Maintenance (Planned)
E P 4 2 Application: Installation (Planned)
E 4 5 Application: Unresponsive
E 4 6 Application: Unstable
U 5 15 System Failure: Stop error
E 5 19 Security issue
U 5 19 Security issue
E P 5 19 Security issue
E 5 20 Loss of network connectivity (Unplanned)
U 6 11 Power Failure: Cord Unplugged
U 6 12 Power Failure: Environment
P 7 0 Legacy API shutdown
I re-ran the command but by this time the local staff had powered it off since it was not responding to a shutdown at the console either. :(
But I did learn some new things today.
Friday, October 16, 2015
Friday, October 9, 2015
Powershell Script - Change Contractor Info
Crafted this gem today.. I need to change some AD attributes for contracted personnel, namely adding a 'c-' to the beginning of their email, UPN and SAMAccountName. Adding a '(Contractor)' to the end of the DisplayName field and changing a couple proxyaddresses.
First things, the csv used has the following columns:
name, mail, displayname, samaccountname, proxyaddress_0, proxyaddress_1, proxyaddress_2
Code:
#========================================================================
# Created with: SAPIEN Technologies, Inc., PowerShell Studio 2012 v3.1.26
# Created on: 10/9/2015 1:46 PM
# Created by: Ben Hart
# Organization: UnifiedBrands
# Filename: Change-ContractorInfo.ps1
#========================================================================
Import-module ActiveDirectory
Import-Csv -Path d:\Users\username\Desktop\test.csv | foreach-object {
$email = $_.mail
$Displayname = $_.displayName
$UPN = $_.mail
$sam = $_.samaccountname
$proxy0 = $_.Proxyaddress_0
$proxy1 = $_.Proxyaddress_1
$proxy2 = $_.Proxyaddress_2
set-aduser -identity $sam -emailaddress $email -UserPrincipalName $email -DisplayName $Displayname
Set-ADUser -Identity $sam -Replace @{proxyaddresses=@("SMTP:"+$email)}
Set-ADUser -Identity $sam -Add @{proxyaddresses="$proxy0"}
Set-ADUser -Identity $sam -Add @{proxyaddresses="$proxy1"}
Set-ADUser -Identity $sam -Add @{proxyaddresses="$proxy2"}
Set-ADUser -identity $sam -Replace @{targetaddress="$email"}
}
First things, the csv used has the following columns:
name, mail, displayname, samaccountname, proxyaddress_0, proxyaddress_1, proxyaddress_2
Code:
#========================================================================
# Created with: SAPIEN Technologies, Inc., PowerShell Studio 2012 v3.1.26
# Created on: 10/9/2015 1:46 PM
# Created by: Ben Hart
# Organization: UnifiedBrands
# Filename: Change-ContractorInfo.ps1
#========================================================================
Import-module ActiveDirectory
Import-Csv -Path d:\Users\username\Desktop\test.csv | foreach-object {
$email = $_.mail
$Displayname = $_.displayName
$UPN = $_.mail
$sam = $_.samaccountname
$proxy0 = $_.Proxyaddress_0
$proxy1 = $_.Proxyaddress_1
$proxy2 = $_.Proxyaddress_2
set-aduser -identity $sam -emailaddress $email -UserPrincipalName $email -DisplayName $Displayname
Set-ADUser -Identity $sam -Replace @{proxyaddresses=@("SMTP:"+$email)}
Set-ADUser -Identity $sam -Add @{proxyaddresses="$proxy0"}
Set-ADUser -Identity $sam -Add @{proxyaddresses="$proxy1"}
Set-ADUser -Identity $sam -Add @{proxyaddresses="$proxy2"}
Set-ADUser -identity $sam -Replace @{targetaddress="$email"}
}
Friday, October 2, 2015
CommVault - Simpana iData Agent install on LInux
So push installations from the Simpana console sometimes don't work on *nix hosts, so I resorted to installing interactively. Problem was I was getting an error concerning an incorrect version of KSH.
My resolution was a 'chmod -R 755 .' Running that from within the directory where the cvpkgadd file is. Fixed me right up!
My resolution was a 'chmod -R 755 .' Running that from within the directory where the cvpkgadd file is. Fixed me right up!
PowerShell Script - Backing up ESXi Configuration
Crafted this guy today because I've been forgetting to backup our ESXi hosts configs in quite a while.
I used a small part of the PowerCLI script to load the modules for this..
# Loads additional snapins and their init scripts
function LoadSnapins(){
$snapinList = @( "VMware.VimAutomation.Core", "VMware.VimAutomation.Vds", "VMware.VimAutomation.License", "VMware.DeployAutomation", "VMware.ImageBuilder", "VMware.VimAutomation.Cloud")
$loaded = Get-PSSnapin -Name $snapinList -ErrorAction SilentlyContinue | % {$_.Name}
$registered = Get-PSSnapin -Name $snapinList -Registered -ErrorAction SilentlyContinue | % {$_.Name}
$notLoaded = $registered | ? {$loaded -notcontains $_}
foreach ($snapin in $registered) {
if ($loaded -notcontains $snapin) {
Add-PSSnapin $snapin
}
}
}
LoadSnapins
$cred = Get-Credential
connect-viserver 1.2.3.4 -credential $cred
get-vmhost | get-vmhostfirmware -backupconfiguration -destinationpath "C:\vmware_backups"
pause
I used a small part of the PowerCLI script to load the modules for this..
# Loads additional snapins and their init scripts
function LoadSnapins(){
$snapinList = @( "VMware.VimAutomation.Core", "VMware.VimAutomation.Vds", "VMware.VimAutomation.License", "VMware.DeployAutomation", "VMware.ImageBuilder", "VMware.VimAutomation.Cloud")
$loaded = Get-PSSnapin -Name $snapinList -ErrorAction SilentlyContinue | % {$_.Name}
$registered = Get-PSSnapin -Name $snapinList -Registered -ErrorAction SilentlyContinue | % {$_.Name}
$notLoaded = $registered | ? {$loaded -notcontains $_}
foreach ($snapin in $registered) {
if ($loaded -notcontains $snapin) {
Add-PSSnapin $snapin
}
}
}
LoadSnapins
$cred = Get-Credential
connect-viserver 1.2.3.4 -credential $cred
get-vmhost | get-vmhostfirmware -backupconfiguration -destinationpath "C:\vmware_backups"
pause
Subscribe to:
Posts (Atom)