Powershell script monitor with encrypted password

I have created a powershell script based monitor in my management pack and everything is ok but I can't get my credentials work inside the script. I want to open pssession to another computer with my credentials. I have triple checked that my pssession is
working because I can access it from powershell console.
This works perfectly at local server from PSconsole:
$EncryptedPassword ="01000000d08c9ddf0115d1118c7a00c04fc297eb01000000534b2....etc...etc..."
$pw = convertto-securestring -String $EncryptedPassword
$cred = new-object System.Management.Automation.PSCredential -argumentlist "MyDOMAIN\MyACCOUNT",$pw
$s = New-PSSession -ComputerName "MyServer" -Port MyPort -Credential $cred
But when I run the same lines inside my management pack the convertto-securestring
does nothing, it just wont convert the encrypted password to secure string!
I have tried this plain text method and it works
inside my management pack, but I don't want to use it because you can see the password in plain text:
ConvertTo-SecureString -String "myPlainTextPassword" -AsPlainText -Force
This is the $error variable, so it's basically says that I don't have anything in the password secure string variable because the convertion did not work for some reason:
The argument is null. Provide a valid value for the argument, and then try running the command again. Cannot process argument transformation on parameter 'Credential'. PromptForCredential Exception calling ".ctor" with "2" argument(s):
"Cannot process argument because the value of argument "password" is null. Change the value of argument "password" to a non-null value." The system cannot find the file specified. Exception calling "SecureStringToBSTR"
with "1" argument(s): "Value cannot be null. Parameter name: s" The system cannot find the file specified. Exception calling "SecureStringToBSTR" with "1" argument(s): "Value cannot be null. Parameter name: s"
The system cannot find the file specified. 
So is there some known issue with SCOM Agent / management pack when you are dealing with convertto-securestring
function with encrypted passwords?
I used these methods to encrypt the password: Technet article about encryption

I got it to work!
  <TypeDefinitions>
    <EntityTypes>
      <ClassTypes>
        <ClassType ID="MyClass" Accessibility="Public" Abstract="false" Base="Windows!Microsoft.Windows.LocalApplication" Hosted="true" Singleton="false" Extension="false"
/>
      </ClassTypes>
    </EntityTypes>
    <SecureReferences>
      <SecureReference ID="MyRunAsAccountProfile" Accessibility="Public" Context="System!System.Entity" />
    </SecureReferences>
<ScriptBody>param (
  [string]$Username,
  [string]$Password
$API = new-object -comObject "MOM.ScriptAPI" 
$PropertyBag = $API.CreatePropertyBag()
$cred = New-Object System.Management.Automation.PSCredential -Argumentlist @($Username,(ConvertTo-SecureString -String $Password -AsPlainText -Force))
$s = New-PSSession -ComputerName "myserver" -Credential $cred
Invoke-Command -Session $s -ScriptBlock { $service = Get-Service -Name Spooler}
$invcom = Invoke-Command -Session $s -ScriptBlock { $service.status}
Remove-PSSession -Id $s.Id
if ($invcom.Value -ne "Running") {
$PropertyBag.AddValue("State","ERROR") 
$outputLongLine = "Spooler Service is not running on target server!" 
$PropertyBag.AddValue("Description", $outputLongLine)
else {
$PropertyBag.AddValue("State","OK") 
$outputLongLine = "Spooler is Running on target server."
$PropertyBag.AddValue("Description", $outputLongLine) 
$PropertyBag</ScriptBody>
<Parameters>
<Parameter>
<Name>Username</Name>
 <Value>$RunAs[Name="MyRunAsAccountProfile"]/Domain$\$RunAs[Name="MyRunAsAccountProfile"]/UserName$</Value>
</Parameter>
<Parameter>
<Name>Password</Name>
<Value>$RunAs[Name="MyRunAsAccountProfile"]/Password$</Value>
</Parameter>

Similar Messages

  • The PowerShell script failed with below exception

    I'm receiving the following errors on all SQL Express Servers (every machine that has SQL Express inside).
    it seems that the discovery has found SQL Express but could not connect to the instance.
    details on the alerts:
    Date and Time:
    10/22/2013 12:04:22 PM
    Log Name:
    Operations Manager
    Source:
    Health Service Modules
    Generating Rule:
    Collect Power Shell Module Events
    Event Number:
    22406
    Level:
     Error
    Logging Computer:
    SQLEXPRESS.DOMAIN.COM
    User:
    N/A
    Description:
    The PowerShell script failed with below exception
    System.Management.Automation.RuntimeException: Exception calling "Fill" with "1" argument(s): "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not
    accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
    At line:44 char:19
    + $SqlAdapter.Fill <<<< ($DataSet)|out-null
    at System.Management.Automation.FlowControlNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
    at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
    at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
    Script Name: StolenServerMemory2008.ps1
    One or more workflows were affected by this.
    Workflow name: Microsoft.SQLServer.2008.DBEngine.StolenServerMemoryMonitor
    Instance name: SQLEXPRESS
    Instance ID: {9705795C-4F3B-C2EF-AA7D-C736B40FD6A4}
    Management group: SCOMGROUP 

    Some additional inf.
    http://stackoverflow.com/questions/6466974/unable-to-connect-to-sql-express-error-26-error-locating-server-instance-speci?rq=1
    anyway you can disable this rule/monitor as no control from monitoring solution in that case. Or try to rewrite the same monitor...
    The problem in your case is when function tries to get Max Server Memory MB by connecting to master DB, but you can replace it with performance counter like Target Server Memory (KB)...
    just see the function main in StolenServerMemory2008.ps1 and what you need to replace
    $api = New-Object -comObject "MOM.ScriptAPI"
    $bag = $api.CreatePropertyBag()
    $msg = [Environment]::NewLine
    $err = [Environment]::NewLine
    #try {
    $maxMemoryMB = GetMaxServerMemoryMB $ComputerName $InstanceName
    $stolenPages = (Get-Counter ("\" + $PerformanceCounterObject + ":Buffer Manager\Stolen Pages")).CounterSamples[0].CookedValue
    $pakeSizeKB = 8
    [double]$stolenMemoryMB = $stolenPages * $pakeSizeKB / 1024                                      
    [double]$stolenMemoryPercent = 0
    if($maxMemoryMB -gt 0){
    [double]$stolenMemoryPercent= 100.0 * $stolenMemoryMB / $maxMemoryMB
    $bag.AddValue("StolenMemoryMB", $stolenMemoryMB)
    $bag.AddValue("StolenMemoryPercent", $stolenMemoryPercent)                                  
    $msg += "StolenMemoryMB=$stolenMemoryMB StolenMemoryPercent=$stolenMemoryPercent"
    $msg += [Environment]::NewLine                          
    #debug $api.LogScriptEvent("SQL 2008 Stolen Server Memory data source", $SCRIPT_EVENT_ID, $INFORMATION_EVENT_TYPE, $msg + $err)                     
    #catch {
    #             $header = "Managegement Group: $Target/ManagementGroup/Name$. Script: {0}" -f ($MyInvocation.MyCommand).Name.ToString()
    #             $msg += "Error occured during SQL 2008 Stolen Server Memory data source executing.{0}Computer:{1} {0}Reason: {2}" -f [Environment]::NewLine, $env:COMPUTERNAME, $_.Exception.Message
    #             $api.LogScriptEvent($header, $SCRIPT_EVENT_ID, $ERROR_EVENT_TYPE, $msg + $err)                           
    $bag

  • I have an external seagate 2tb drive with 3 partitions each with encrypted passwords. What must I do if one of the drives won't recognize it's password?

    I have an external seagate 2tb drive with 3 partitions each with encrypted passwords. What must I do if one of the drives won't recognize it's password?

    I would have to say the LCD display or possibly the inverter as the graphics adapter can properly output to an external monitor. This would be repaired under warranty.
    \\ I do not respond to PM regarding individual tech support. Keep discussions in the forum for the benefit of others //

  • Login with encrypted password doesn't work

    Hi, simple problem:
    in login settings with encrypted password option on
    The login doesn't work => Error:"AFTER.Trigger_Login_CheckLogin*"
    (tested with a user that has an encrypted password)
    without encrypted password
    The login works
    (tested with a user that has a clean password)
    Where I wrong?
    Thanks
    Gabriele

    Hi Gabriele,
    how many varchars did you define for the column that´s holding the encrypted passwords ? It has to be at least 32 chars due to the MD5 encryption, if it´s lesser than that, the passwords will get truncated.
    Cheers,
    Günter Schenk
    Adobe Community Expert, Dreamweaver

  • After creating a Powershell script monitor - how to import in Operation Manager 2012 ?

    Hello!
    I just completed all the steps in this article:
    http://social.technet.microsoft.com/wiki/contents/articles/16752.management-pack-composition-exercise-2-creating-a-monitor-based-on-a-windows-powershell-script.aspx?CommentPosted=true#commentmessage 
    So now I guess that the just created Management Pack should be imported in Operation Manager 2012, and then also folders and views should be created in order to have it showing green/red based on the values returned by the script.
    In the article there's no pointer to that procedure, so can you please provide a good link where the steps are explained?
    thanks!

    Have a look at the following video, it steps through how to create rules and monitors using PowerShell scripts
    https://technet.microsoft.com/en-us/video/how-do-i-create-a-rule-and-monitor-using-a-windows-powershell-script-in-a-system-center-operations-manager-management-pack.aspx
    Cheers,
    Martin
    Blog:
    http://sustaslog.wordpress.com 
    LinkedIn:
    Note: Posts are provided “AS IS” without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

  • Doubts regarding db connection with encrypted password usage in sandbox

    Hi All,
    We have setup the db connection using configuration file. The configuration file contains db connection information including the encrypted password.
    Below are my doubts:
    1. If we are going to import the ETL project in zip file directly into the sandbox can we run the graphs directly or we need to check how the password which is encrypted in configuration file will be decoded.
    2. Can we directly modify the configuration file for db connection like db connection,user name and password. Suppose I want the graphs to run in some other database which is not specified in configuartion fiel .Can I directly update that?
    3.Is it possible to change the encrypted password in the configuration file in the sandbox. Is it that we need to create the project in Integrator Designer, change the password using the Integrator Designer, and then copy the encrypted password into the configuration file in sandbox, or the Endeca provides a functionality to allow user to directly change the password in the sandbox on the Integrator server.
    Can someone please let me know their comments on above.
    Thanks in Advance.
    Regards,
    Amrit

    can someone please help me on this issue

  • PowerShell Script to enable encryption

    Hi All,
    I am hoping I can get some assistance.   I am looking to create a script that will do following:
    1. Enable Encryption 
    2. Backup Encryption Key and/or TPM Data to specific location and specific file name: ex: Computer Name or FQDN
    Is this possible?

    There's the Bitlocker cmdlets, like Enable-Bitlocker. See
    https://technet.microsoft.com/en-us/library/jj649829.aspx
    This appears to encrypt drive when not encrypted already (or resume encryption when currently paused, as it states there).
    About writing key protector to a text file:
    http://blogs.technet.com/b/leoponti/archive/2013/08/17/powertip-use-powershell-to-write-bitlocker-recovery-key-to-text-file.aspx
    Have not tried this myself though.

  • Powershell script run with TaskScheduler not stopping VM's

    I have a script that stops and starts the VM's, and copies files and it works ok when I run it with powershell, but when I run it with TaskScheduler, it's not stopping/starting the VM's (but does copy files).  We have server 2008 R2.  I updated
    powershell to version 3 and downloaded and installed the Hypver-V powershell module from Microsoft.
    Also, when I run the script through powershell, I needed to run as administrator.  When I run it with the powershell prompt this is what it looks like:
    C:\windows\system32> powershell -NoProfile -noninteractive -ExecutionPolicy bypass -Command "& c:\Scripts\BackupVhdShell_2_param.ps1 -single_backup_file_to_loc 'E:\' -single_backup_file_from_loc 'S:\SQL-bak.vhd'"
    So that works from powreshell to start/stop vm's and copy files.
    In Task Scheduler, this is how I have it set up:
    Run with highest priviledges is checked. I have my login credentials saved so it can wake up the server when I'm not here or if it's not up.  
    In The Program/script field: %SystemRoot%\SysWow64\WindowsPowerShell\v1.0\powershell.exe
    In the Add Arguments field: -NoProfile -noninteractive -ExecutionPolicy bypass -Command "& c:\Scripts\BackupVhdShell_2_param.ps1 -single_backup_file_to_loc 'E:\' -single_backup_file_from_loc 'S:\SQL-bak.vhd'"
    Any thoughts?  I'm not sure if TaskManager isn't finding HyperV module?
    This is what the majority of the script looks like:
    param($single_backup_file_to_loc, $single_backup_file_from_loc)
    function StopVMsInOrder ([array][String]$vmNames){ 
    #this function will stop VM's in list, sequentially 
       Write-Host "Processing virtual machines in order"
       foreach ($name in $vmNames) {
           Write-Host "Analyzing $name"
           Try {
                 #Write-Host "...Saving $name"
                 #Save-VM -VM $name -wait -Force
                 Write-Host "..shutdown $name" #name)"
                 Invoke-VMShutdown -VM $name -Force #$vm.name
           } #try
           Catch {
              Write-Host "Failed to get virtual machine $name"
           } #catch
       }#foreach
    } #function StopVMsInOrder
    function StartVMsInOrder ([array][String]$vmNames){ 
    #this function will start VM's in list, sequentially as opposed to all at once
       Write-Host "Processing virtual machines in order"
       foreach ($name in $vmNames) {
           Write-Host "Analyzing $name"
           Try {
                 Write-Host "..Starting $name"
                 Start-VM -VM $name -wait
           } #try
           Catch {
              Write-Host "Failed to get virtual machine $name"
           } #catch
       }#foreach
    } #function StartVMsInOrder
    function CopyFileToFolder ([string]$Source,[string]$destination){  
       # get filename  
    #################start of script##############
    import-module Hyperv
    #get list of running vm's
    [array]$vmNames = @(Get-VM -Running | %{$_.elementname})  
    Write-Host "To: $single_backup_file_to_loc"
    Write-Host "From: $single_backup_file_from_loc"
    #call function to stop vm's
    StopVMsInOrder $vmNames      
    if($single_backup_file_to_loc -ne " ")
       #someone passed in a parameter for one-off use of script
       [array]$destFileArray = @($single_backup_file_to_loc)
       [array]$sourceFileArray = @($single_backup_file_from_loc)
    }else
       Write-Host "To Loc not Defined as param"
       #get set up for what need to backup vhd's
       #where back it up to
    $i=0
    for ($i = $sourceFileArray.GetLowerBound(0); $i -le $sourceFileArray.GetUpperBound(0); $i++) { 
            $tempSource =  $sourceFileArray[$i]
            $tempDest = $destFileArray[$i]
            CopyFileToFolder $tempSource $tempDest
            Write-Host "i: $i"
    Write-Host "Done with vhd backup"
    #call function to start vm's
    StartVMsInOrder $vmNames  
    Write-Host "Done with vm start"
    Michele Cleary

    I finally figured it out!  I changed it so I was using the 32 bit version of powershell in TaskScheduler:  %SystemRoot%\system32\....  Now it's finding the VM's!
    Michele Cleary
    Just FYI - system32 is x64. SysWOW64 is x86.
    Don't retire TechNet! -
    (Don't give up yet - 12,700+ strong and growing)

  • What is best way to start up to secure processes with encrypted passwords

    Please redirect me if this should be in another Java forum ...
    I want to have 2 Java applications running on a secure server. Both contain a password in memory that needs to be kept highly secure. Also, I want each application to be able to restart the application if one fails (I already am doing this with other appications). Finally, I want assurances when an app is restarted, the source is identical to when processes were first brought up manually.
    Essentially, here is what I'm thinking about, but there's probably a better way:
    Items Required:
    App1 Code
    App1 Password
    App1 Code Hash
    App2 Code
    App2 Password
    App2 Code Hash
    When a server is initially brought up, App1 Code is started manually by Admin. App1 will prompt for App1 Password, and App2 Password (Admin will enter these manually). App1 will also display App1 Code Hash and App2 Code Hash. Admin will verify the Hashes match the expected value. App1 will automatically start App2. Upon initially being started, App2 will begin listening on SSLServerSocket. App1 will connect to this socket, and pass App2 both App1 and App2 Passwords, as well as App1 and App2 Code Hashes. At this point, both Apps are running, and both will have both Passwords and Code Hashes in memory. If either App fails, the other App will catch it (through a periodic process check). Before restarting, the Hash of the Code will be rechecked (of the App being restarted), and the Passwords/Hashes will be repassed to the restarted App through SSL session.
    Any holes here?
    Any better ways of implementing?
    Thanks!

    First, you should have to Apple IDs
    Second, you must have a Wi-Fi connection.
    Facetime Calls
    To add them go to address book and put in the Apple ID username under email.
    Go to facetime, click the contacts button on the bottom. Click the name they gave them. Click the email you used for their Apple ID. It should start a call with the device hooked up with that Apple ID.
    Set-Up Facetime
    Go to settings. Click facetime. Sign-in with the Apple ID you are using. When someone calls that address it should give you a notification.
    Texting
    If you are getting a new iPod you will be getting with iOS 5 wich includes iMessage to other iOS 5 devices. Just click iMessage at the home screen and type in the name of the person with the Apple ID you want to text OR type in the Apple ID you want to text. You should start a convorsation with the iDevice hooked up to that Apple ID.
    Set-Up iMessage (a.k.a. Texting)
    Go to settings. Click iMessage. Sign-in with the Apple ID you are using. When someone texts that address it will notify you.
    Hope I helped!

  • Help Disk Drive Locked With Encryption Password

    Hi,
    I reciently encryptyed my SSD on my Mac-Air and have now forgeten the password. Is there a way to fix it with out taking it to apple and getting a new drive?

    You can't do it in Disk Utility; you'll have to use the shell. It will be a lot easier if you have a bootable backup. That way you can copy and paste the shell commands, instead of having to type them.
    The basic idea is in this thread:
    Hard disk bricked after using file...: Apple Support Communities
    First, you determine the UUID of the logical volume group corresponding to the boot volume. Then you delete that logical volume group.
    Then you should be able to format the partition in Disk Utility, install OS X, and transfer your data from Time Machine in Setup Assistant.

  • Using Echo Command in PowerShell Script for Configuration Item

    Hello All,
    Before you tell me to post my PowerShell question to the PowerShell Forum, please know that the PowerShell portion of my task works just fine. It is the SCCM portion of my task that keeps failing, so that is why I am here. To give some background...
    There are two servers in our SCCM test environment. Both the SCCM server and SQL DB server are 2012, patched and updated.
    Test servers in my Device Collection being used for running Baselines and Reports against are 2008R2 and 2012, patched and updated.
    I have created a Configuration Item that checks to see if the FTP Server Role Feature has been installed on a 2008 or 2012 server. To do the check, I am using the following PowerShell script:
    (get-windowsfeature -Name Web-Ftp-Server).Installed
    When I log into my 2008R2 and 2012 test servers, and run this command directly on the server, it will return a "True" if the FTP Server Role Feature is installed on either server, and a "False" if it is not installed. Basically,
    it works as advertised.
    When I setup my Configuration Item and then deploy my Baseline, or run a report against my device collection of test servers, SCCM will return a correct response (True or False) for the 2012 test server, but throws the following error for the 2008R2
    server:
    0x87df00329 application requirement evaluation or detection failed
    Google searches for this have not been very helpful.
    Now, when I created the Configuration Item and referenced PowerShell, the configuration screen has the following note:
    "Specify the script to find and return the value to be assessed for compliance on client devices. Use the echo command to return the script value to Configuration Manager."
    Since I did not include an echo command in my PowerShell script above, I figured that was my problem, so I did the following:
    Logging onto both of my test servers (2008R2 & 2012) I was able to successfully run the following PowerShell commands and get the expected responses of True or False:
    (get-windowsfeature -Name Web-Ftp-Server).Installed | echo
    (get-windowsfeature -Name Web-Ftp-Server).Installed | write-output (http://technet.microsoft.com/en-us/library/hh849921.aspx)
    (get-windowsfeature -Name Web-Ftp-Server).Installed | write-host (http://technet.microsoft.com/en-us/library/ee177031.aspx)
    However, when I use any of these PowerShell commands in my Configuration Item, NEITHER of my test servers returns a response to the SCCM server.
    When I check the report, both servers show as "Unknown" and when I click on the number 2 (as in 2 servers unknown), the following report page (List of unknown assets for a configuration baseline) has absolutely no data/information at all.
    So...I am at a loss.
    SCCM tells me to use an echo command to return a script value to Configuration Manager. The PowerShell scripts above, with the various echo related commands, work just fine on the servers themselves, but they return no information when run via SCCM.
    What am I missing?
    Any help will be appreciated.
    Thanks in advance for your time.

    Sorry for my ignorance, but I don't understand. (I forgot to mention that I am new at both PowerShell and SCCM.)
    After I change the PowerShell script to add the echo/write-output/write-host cmdlet, I open the ConFig Item and "Clear" the PowerShell script and then re-add it. When I do that, it correctly shows the change in the ConFig Item.
    Next I open the Baseline, then open the ConFig Item within the Baseline to make sure the change is reflected there as well, which it is.
    I then deploy the Baseline to my Device Collection. After that, I run a report against the Baseline and Device Collection and it returns the "Unknown" result.
    If I open the PowerShell script and remove the echo/write-output/write-host cmdlet, then go through the rest of the process of updating and reporting, the result it returns changes, showing one server in compliance and the other server out of compliance,
    which leads me to think that all changes have taken correctly.
    Does that sound right? If I manually deploy the Baseline, is that the same as the client retrieving policies from the management point?
    Sorry to be so thick but I'm learning as I go.
    Thanks again for your help.

  • Is it possible to monitor State change of a .CSV file using powershell scripting ?

    Hi All,
    I just would like to know Is it possible to monitor State change of a .CSV file using powershell scripting ? We have SCOM tool which has that capability but there are some drawbacks in that for which we are not able to utilise that. So i would like
    to know is this possible using powershell.
    So if there is any number above 303 in the .CSV file then i need a email alert / notification for the same.
    Gautam.75801

    Hi Jrv,
    Thank you very much. I modified the above and it worked.
    Import-Csv C:\SCOM_Tasks\GCC2010Capacitymanagement\CapacityMgntData.csv | ?{$_.Mailboxes -gt 303} | Export-csv -path C:\SCOM_Tasks\Mbx_Above303.csv;
    Send-MailMessage -Attachments "C:\SCOM_Tasks\Mbx_Above303.csv" -To “[email protected]" -From “abc@xyz" -SMTPServer [email protected] -Subject “Mailboxex are above 303 in Exchange databases” -Body “Mailboxex are above 303 in Exchange databases" 
    Mailboxex - is the line which i want to monitor if the values there are above 303. And it will extract the lines with all above 303 to another CSV file and 2nd is a mail script to email me the same with the attachment of the 2nd extract.
    Gautam.75801

  • Open An Encrypted, Password Protected Saprsebundle Disk Image With iPhone?

    Is it possible to open an encrypted, password protected sparsebundle disk image using an iPhone/iPad/iPod Touch that is stored on a NAS drive connected to an AirPort Extreme Base Station?
    If so, how do I do it?
    If not, would you be able to explain why not?
    Thanks, Alex

    Hi Robert,
    > Once you through a sudo in there, you lose the option
    to have a regular user
       That's not really true. Sudo is one of the most flexible commands around and not only can a regular user use it but they can use it without a password. Mind you I'm not suggesting that you make all users admins; you can specify both of these privileges for this command only. All you have to do is to put a line like the following in your /etc/sudoers file. (with sudo visudo of course)
    ALL ALL = NOPASSWD: /usr/bin/hdiutil create -encryption -certificate*-stdinpass -type SPARSE -fs "HFS+" -volname-size
    I've included wildcards so that the cert file, volume name, size and image are arbitrary but the others must be in the user's command to qualify. I realize that you'll want different options to use FileVault certs but I don't know how to do that so I used your original example as my example.
       Of course it wouldn't be that easy for your lusers to get all of those options correct so the next thing you do is to wrap the command, with it's sudo preface, in a shell script that parses the cert file, volume name, size and image from the options the user passes to the script and puts those into the command with the right syntax. If you want to get really fancy, the script could prompt the user for any arguments that were omitted. Your lusers will think that you created this really cool command and never know that sudo was involved.
    Gary
    ~~~~
       If you give a man enough rope, he'll claim he's tied up
       at the office.

  • PowerShell - scripting - skip Encrypted\CLR Stored Procedures

    Hi all,
    Forgot where I got the code below from but, how would I skip Encrypted\CLR procedures because, I get error below...
    Message
    Executed as user: Loginname A job step received an error at line 81 in a PowerShell script. The corresponding line is '
    $MyScripter.Script($proc)|out-null'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Exception calling "Script" with "1" argument(s): "The StoredProcedure '[dbo].[myrpocname]'
    cannot be scripted as its data is not accessible."  '.  Process Exit Code -1.  The step failed.
    #STORED PROCEDURES
    if($procs -ne $null)
    foreach ($proc in $procs)
    #Assuming that all non-system stored procs have proper naming convention and don''t use prefixes like "sp_"
    if ( $proc.Name.IndexOf("sp_") -eq -1 -and $proc.Name.IndexOf("xp_") -eq -1 -and $proc.Name.IndexOf("dt_") -eq -1)
    $fileName = $proc.name
    "Scripting SP $fileName"
    $scriptfile = "$rootDrive\DatabaseScripts\$sqlDatabaseName\$strDate\StoredProcedures\$filename.sql"
    New-Item $rootDrive\DatabaseScripts -type directory -force | out-null
    New-Item $rootDrive\DatabaseScripts\$sqlDatabaseName -type directory -force | out-null
    New-Item $rootDrive\DatabaseScripts\$sqlDatabaseName\$strDate -type directory -force | out-null
    New-Item $rootDrive\DatabaseScripts\$sqlDatabaseName\$strDate\StoredProcedures -type directory -force | out-null
    # SetScriptOptions
    $MyScripter.Options.FileName = $scriptfile
    #AppendTofile has to be ''true'' in order that all the procs'' scripts will be appended at the end
    $MyScripter.Options.AppendToFile = "true"
    $MyScripter.Script($proc)|out-null
    Thanks
    gv
    Sword

    You can exclude encrypted stored procedure using $_.IsEncrypted member.
    $storedProcs = $db.StoredProcedures | Where-object { $_.schema -eq $schema -and -not $_.IsSystemObject -and  -not $_.IsEncrypted}
    $server = "localhost"
    $database = "PowerSQL"
    $output_path = "F:\PowerSQL\"
    $schema = "dbo"
    $storedProcs_path = "$output_path\StoredProcedure\"
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
    $srv = New-Object "Microsoft.SqlServer.Management.SMO.Server" $server
    $db = New-Object ("Microsoft.SqlServer.Management.SMO.Database")
    $tbl = New-Object ("Microsoft.SqlServer.Management.SMO.Table")
    $scripter = New-Object ("Microsoft.SqlServer.Management.SMO.Scripter") ($server)
    # Get the database and table objects
    $db = $srv.Databases[$database]
    $storedProcs = $db.StoredProcedures | Where-object { $_.schema -eq $schema -and -not $_.IsSystemObject -and -not $_.IsEncrypted}
    # Set scripter options to ensure only data is scripted
    $scripter.Options.ScriptSchema = $true;
    $scripter.Options.ScriptData = $false;
    #Exclude GOs after every line
    $scripter.Options.NoCommandTerminator = $false;
    $scripter.Options.ToFileOnly = $true
    $scripter.Options.AllowSystemObjects = $false
    $scripter.Options.Permissions = $true
    $scripter.Options.DriAllConstraints = $true
    $scripter.Options.SchemaQualify = $true
    $scripter.Options.AnsiFile = $true
    $scripter.Options.EnforceScriptingOptions = $true
    function CopyObjectsToFiles($objects, $outDir) {
    if (-not (Test-Path $outDir)) {
    [System.IO.Directory]::CreateDirectory($outDir)
    foreach ($o in $objects) {
    if ($o -ne $null) {
    $schemaPrefix = ""
    if ($o.Schema -ne $null -and $o.Schema -ne "") {
    $schemaPrefix = $o.Schema + "."
    $scripter.Options.FileName = $outDir + $schemaPrefix + $o.Name + ".sql"
    Write-Host "Writing " $scripter.Options.FileName -ErrorAction silentlycontinue
    $scripter.EnumScript($o)
    # Output the scripts
    CopyObjectsToFiles $storedProcs $storedProcs_path
    Write-Host "Finished at" (Get-Date)
    -Prashanth

  • LDIF Importing a user with a non-encrypted password fails, anywork arounds?

    I was able to import a group without issue:
    dn: cn=Authenticated,cn=Groups,dc=oraclelinux,dc=com
    description: test group
    objectClass: top
    objectClass: groupOfUniqueNames
    uniqueMember: cn=orcladmin,cn=People,dc=oraclelinux,dc=com
    cn: Authenticated
    But when I try to import a standard user:
    dn: cn=testuser2,cn=Users, dc=oraclelinux, dc=com
    userpassword:: password1
    description: test user
    objectClass: top
    objectClass: person
    sn: testuser2
    cn: testuser2
    It fails if I remove the password field then I can import the user without issue, but I need to include the password field as it is part of what was exported from the old LDAP Server.
    If I create a user in an ldif import it then add a password using oracle's Directory Manager upon exporting it the entry loks like:
    dn: cn=testuser, cn=Users, dc=oraclelinux, dc=com
    authpassword;orclcommonpwd: {MD5}fGoYCzaJagqMAnh+6vsOTA==
    authpassword;orclcommonpwd: {X- ORCLLMV}E52CAC67419A9A2238F10713B629B565
    authpassword;orclcommonpwd: {X- ORCLNTV}5835048CE94AD0564E29A924A03510EF
    authpassword;oid: {SASL/MD5}tUquh+Duowh2aWSEwONtcQ==
    authpassword;oid: {SASL/MD5-DN}lcQ7Z5O5vcwzXMeaZ65fYw==
    authpassword;oid: {SASL/MD5-U}AAWzkmDDCJLbs9mxoWBTiw==
    userpassword:: e1NIQX00NHJTRkpROXF0SFdUQkF2cnNLZDVLL3AyajA9
    description: test user
    objectclass: top
    objectclass: person
    sn: testuser
    cn: testuser
    Changing my imported ldif to look like the following WORKS:
    dn: cn=testuser2,cn=Users, dc=oraclelinux, dc=com
    userpassword:: e1NIQX00NHJTRkpROXF0SFdUQkF2cnNLZDVLL3AyajA9
    description: test user
    objectClass: top
    objectClass: person
    sn: testuser2
    cn: testuser2
    So the password must be encrypted then?, if so how to I generate a password hash on the command-line and through JAVA?
    Can an import be forced with a plain text password (Tivoli, SUN both support this functionality).
    Can I change the constraint that the password must contain a numeric char? (Found in document: http://download-uk.oracle.com/docs/cd/B28196_01/idmanage.1014/b15991/pwdpolicies.htm#g1051713)
    After fixing the constaints I can import a non-encrypted password from an ldif, but it can not be verified and only the authpassword;oid entries are created not the authpassword;orclcommonpwd entries.
    Thanks for your assistance,
    ERIC GANDT

    Eric, my first guess would be that the OID password policy prevents loading of the password i.e. the password doesn't match the existing password policy.
    What version is your "old" OID and what is the version of the current OID you're using?
    What is the error msg you get?
    regards,
    --Olaf                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • In  BDC how you handled header data and item data

    In  BDC how you handled header data and item data

  • Delete query not working ?

    hi all, this delete query is not working for me. Could you please help me and tell me ho to resolve this ? The error i get when executing this query is "ORA-00903: invalid table name". The table name is correct I fail to understand why does it show i

  • LR4 metadata changes are not read in Bridge CS5

    I am saving the metadata in LR4 (as I normally do with LR3) and not all the adjustments are registering in Bridge CS5 or Adobe Camera RAW.  The develop panels (i.e. tone, presence) in LR4 have obviously changed and don't exactly match the current Ado

  • The shares are no longer visible

    Hi Hope this mail finds you well. i have an issue in my WD EX4, can you please provide a reason why the shares that contains the data are no longer visible on the dashboard or via windows explorer and finder. This is the second time it happened. Than

  • I want to download adobe encore CS6 for DVD durning

    i want to download adobe encore CS6 for DVD burning , i am already using premiere pre CC 2014 !