Any powershell guru's in here

Welcome to our Community
Wanting to join the rest of our members? Feel free to Sign Up today.
Sign up

ThatOneDude

Commander in @Chief, Dick Army
First 100
Jan 14, 2015
35,390
34,272
I'm working on a powershell script that was working but now it isn't, it's no longer storing the variables.
 
Last edited:

ThatOneDude

Commander in @Chief, Dick Army
First 100
Jan 14, 2015
35,390
34,272
in case anyone was watching, got it working, feel free to use it

Code:
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Disable Active Directory User"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
$objForm.Add_KeyDown(
    {
        if ($_.KeyCode -eq "Enter")
        {
            $global:x=$objTextBox.Text;
            $objForm.Close()
        }
    }
)
$objForm.Add_KeyDown(
    {
        if ($_.KeyCode -eq "Escape")
        {
            $objForm.Close()
        }
    }
)

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click(
    {
        $global:x=$objTextBox.Text;
        $objForm.Close()
    }
)
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please enter the user name below:"
$objForm.Controls.Add($objLabel)


$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})

[void] $objForm.ShowDialog()

Disable-ADAccount -Identity $x

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<SERVER>/PowerShell/ -Authentication Kerberos
Import-PSSession $Session

Disable-UMMailbox -Identity $x@domain.com


[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Forward Mailbox To"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
$objForm.Add_KeyDown(
    {
        if ($_.KeyCode -eq "Enter")
        {
            $globabl:y=$objTextBox.Text;
            $objForm.Close()
        }
    }
)
$objForm.Add_KeyDown(
    {
        if ($_.KeyCode -eq "Escape")
        {
            $objForm.Close()
        }
    }
)

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click(
    {
        $global:y=$objTextBox.Text;
        $objForm.Close()
    }
)
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please enter the user name below:"
$objForm.Controls.Add($objLabel)



$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})

[void] $objForm.ShowDialog()

Set-Mailbox -Identity DOMAIN\$x -HiddenFromAddressListsEnabled $true
Set-Mailbox $x@domain.com -ForwardingAddress $y@domain.com -DeliverToMailboxAndForward $false

$cred = Get-Credential “DOMAIN.COM\”
$session = New-PSSession -ConnectionURI “https://<SERVER>/OcsPowershell” -Credential $cred
Import-PsSession $session
Set-CsUser -Identity $x -Enabled $False
 

ThatOneDude

Commander in @Chief, Dick Army
First 100
Jan 14, 2015
35,390
34,272
well maybe those 23 are interested in powershell but couldnt provide any assistance and maybe they will find this useful
 

ThatOneDude

Commander in @Chief, Dick Army
First 100
Jan 14, 2015
35,390
34,272
its a cmd line interface that use's .NET framework and is great for scripting tasks and other things in a windows environment. this script allows for an Admin to disable an AD account, hide the disabled accounts mailbox from the address list, forward all emails to that persons manager or whoever you choose, and also disable their lync account all from 1 place instead of having to go into 3 different programs/servers.
 

La Paix

Fuck this place
First 100
Jan 14, 2015
38,273
64,597
its a cmd line interface that use's .NET framework and is great for scripting tasks and other things in a windows environment. this script allows for an Admin to disable an AD account, hide the disabled accounts mailbox from the address list, forward all emails to that persons manager or whoever you choose, and also disable their lync account all from 1 place instead of having to go into 3 different programs/servers.
I almost guessed that.
 

Splinty

Shake 'em off
Admin
Dec 31, 2014
44,116
91,096
its a cmd line interface that use's .NET framework and is great for scripting tasks and other things in a windows environment. this script allows for an Admin to disable an AD account, hide the disabled accounts mailbox from the address list, forward all emails to that persons manager or whoever you choose, and also disable their lync account all from 1 place instead of having to go into 3 different programs/servers.
God I'm glad I'm not doing admin work anymore :eek: